-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[java_http] send request body #995
Merged
HosseinYousefi
merged 10 commits into
dart-lang:master
from
alex-james-dev:java-http-request-body
Jul 31, 2023
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
36a8eb8
Generate bindings for java.io.OutputStream
alex-james-dev b19c7c0
Get the request body
alex-james-dev 04241b3
Send request body
alex-james-dev 1c8867c
Test request body
alex-james-dev fc12626
Pass failing request body tests
alex-james-dev fa243dc
Add testIsolate to java_http's tests
alex-james-dev 788d8c1
Write the byte array to the OutputStream
alex-james-dev 140f638
Add extension method to Uint8List
alex-james-dev 5335c75
Revert "Add extension method to Uint8List"
alex-james-dev 0e921cf
Add private extension method to Uint8List
alex-james-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
pkgs/java_http/lib/src/third_party/java/io/OutputStream.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Autogenerated by jnigen. DO NOT EDIT! | ||
|
||
// ignore_for_file: annotate_overrides | ||
// ignore_for_file: camel_case_extensions | ||
// ignore_for_file: camel_case_types | ||
// ignore_for_file: constant_identifier_names | ||
// ignore_for_file: file_names | ||
// ignore_for_file: no_leading_underscores_for_local_identifiers | ||
// ignore_for_file: non_constant_identifier_names | ||
// ignore_for_file: overridden_fields | ||
// ignore_for_file: unnecessary_cast | ||
// ignore_for_file: unused_element | ||
// ignore_for_file: unused_field | ||
// ignore_for_file: unused_import | ||
// ignore_for_file: unused_shown_name | ||
|
||
import "dart:isolate" show ReceivePort; | ||
import "dart:ffi" as ffi; | ||
import "package:jni/internal_helpers_for_jnigen.dart"; | ||
import "package:jni/jni.dart" as jni; | ||
|
||
/// from: java.io.OutputStream | ||
class OutputStream extends jni.JObject { | ||
@override | ||
late final jni.JObjType<OutputStream> $type = type; | ||
|
||
OutputStream.fromRef( | ||
jni.JObjectPtr ref, | ||
) : super.fromRef(ref); | ||
|
||
static final _class = jni.Jni.findJClass(r"java/io/OutputStream"); | ||
|
||
/// The type which includes information such as the signature of this class. | ||
static const type = $OutputStreamType(); | ||
static final _id_ctor = | ||
jni.Jni.accessors.getMethodIDOf(_class.reference, r"<init>", r"()V"); | ||
|
||
/// from: public void <init>() | ||
/// The returned object must be deleted after use, by calling the `delete` method. | ||
factory OutputStream() { | ||
return OutputStream.fromRef(jni.Jni.accessors | ||
.newObjectWithArgs(_class.reference, _id_ctor, []).object); | ||
} | ||
|
||
static final _id_nullOutputStream = jni.Jni.accessors.getStaticMethodIDOf( | ||
_class.reference, r"nullOutputStream", r"()Ljava/io/OutputStream;"); | ||
|
||
/// from: static public java.io.OutputStream nullOutputStream() | ||
/// The returned object must be deleted after use, by calling the `delete` method. | ||
static OutputStream nullOutputStream() { | ||
return const $OutputStreamType().fromRef(jni.Jni.accessors | ||
.callStaticMethodWithArgs(_class.reference, _id_nullOutputStream, | ||
jni.JniCallType.objectType, []).object); | ||
} | ||
|
||
static final _id_write = | ||
jni.Jni.accessors.getMethodIDOf(_class.reference, r"write", r"(I)V"); | ||
|
||
/// from: public abstract void write(int i) | ||
void write( | ||
int i, | ||
) { | ||
return jni.Jni.accessors.callMethodWithArgs(reference, _id_write, | ||
jni.JniCallType.voidType, [jni.JValueInt(i)]).check(); | ||
} | ||
|
||
static final _id_write1 = | ||
jni.Jni.accessors.getMethodIDOf(_class.reference, r"write", r"([B)V"); | ||
|
||
/// from: public void write(byte[] bs) | ||
void write1( | ||
jni.JArray<jni.jbyte> bs, | ||
) { | ||
return jni.Jni.accessors.callMethodWithArgs(reference, _id_write1, | ||
jni.JniCallType.voidType, [bs.reference]).check(); | ||
} | ||
|
||
static final _id_write2 = | ||
jni.Jni.accessors.getMethodIDOf(_class.reference, r"write", r"([BII)V"); | ||
|
||
/// from: public void write(byte[] bs, int i, int i1) | ||
void write2( | ||
jni.JArray<jni.jbyte> bs, | ||
int i, | ||
int i1, | ||
) { | ||
return jni.Jni.accessors.callMethodWithArgs( | ||
reference, | ||
_id_write2, | ||
jni.JniCallType.voidType, | ||
[bs.reference, jni.JValueInt(i), jni.JValueInt(i1)]).check(); | ||
} | ||
|
||
static final _id_flush = | ||
jni.Jni.accessors.getMethodIDOf(_class.reference, r"flush", r"()V"); | ||
|
||
/// from: public void flush() | ||
void flush() { | ||
return jni.Jni.accessors.callMethodWithArgs( | ||
reference, _id_flush, jni.JniCallType.voidType, []).check(); | ||
} | ||
|
||
static final _id_close = | ||
jni.Jni.accessors.getMethodIDOf(_class.reference, r"close", r"()V"); | ||
|
||
/// from: public void close() | ||
void close() { | ||
return jni.Jni.accessors.callMethodWithArgs( | ||
reference, _id_close, jni.JniCallType.voidType, []).check(); | ||
} | ||
} | ||
|
||
class $OutputStreamType extends jni.JObjType<OutputStream> { | ||
const $OutputStreamType(); | ||
|
||
@override | ||
String get signature => r"Ljava/io/OutputStream;"; | ||
|
||
@override | ||
OutputStream fromRef(jni.JObjectPtr ref) => OutputStream.fromRef(ref); | ||
|
||
@override | ||
jni.JObjType get superType => const jni.JObjectType(); | ||
|
||
@override | ||
final superCount = 1; | ||
|
||
@override | ||
int get hashCode => ($OutputStreamType).hashCode; | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
return other.runtimeType == ($OutputStreamType) && | ||
other is $OutputStreamType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export "InputStream.dart"; | ||
export "OutputStream.dart"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[optional] Is there any value in minimizing the uses of
callMethodWithArgs
and avoiding interop calls in a loop?(untested suggestion)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good idea to me!
I've pushed a commit with the suggestions and the tests were all passing locally.
Thank you 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been learning about extension methods recently, could we add an extension method to
Uint8List
?Then, the code would go from:
to:
My intuition is that adding an extension method to
Uint8List
is unnecessary at the moment. But if it becomes a common occurence to convertUint8List
toJArray<jbyte>
injava_http
then it would be a nice idea to add an extension method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This extension method does look like a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Let's go for the extension method
toJArray()
onUint8List
.