-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from jefft0/feat/RequestBuilder-body-NativeRe…
…ader Feat/RequestBuilder with body NativeReader
- Loading branch information
Showing
6 changed files
with
152 additions
and
24 deletions.
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
26 changes: 18 additions & 8 deletions
26
android/bridge/src/main/java/ipfs/gomobile/android/InputStreamToGo.java
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,22 +1,32 @@ | ||
package ipfs.gomobile.android; | ||
|
||
import java.io.InputStream; | ||
import java.util.Arrays; | ||
|
||
final class InputStreamToGo implements core.Reader { | ||
final class InputStreamToGo implements core.NativeReader { | ||
private final InputStream inputStream; | ||
|
||
InputStreamToGo(InputStream inputStream) { | ||
this.inputStream = inputStream; | ||
} | ||
|
||
public long read(byte[] p) throws Exception { | ||
long r = inputStream.read(p); | ||
public byte[] nativeRead(long size) throws Exception { | ||
byte[] b = new byte[(int)size]; | ||
while (true) { | ||
int n = inputStream.read(b); | ||
if (n == -1) { | ||
inputStream.close(); // Auto-close inputStream when EOF is reached | ||
// The Swift/Go interface converts this to nil. | ||
return new byte[0]; | ||
} | ||
if (n > 0) { | ||
if (n == b.length) | ||
return b; | ||
else | ||
return Arrays.copyOf(b, n); | ||
} | ||
|
||
if (r == -1) { | ||
inputStream.close(); // Auto-close inputStream when EOF is reached | ||
throw new Exception("EOF"); | ||
// Iterate to read more than zero bytes. | ||
} | ||
|
||
return r; | ||
} | ||
} |
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
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