Skip to content

Commit 1386b57

Browse files
committed
Use nullity inferred CoolSocket base and bump version to 0.1.0-ALPHA30
1 parent a614563 commit 1386b57

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
<groupId>org.monora.uprotocol</groupId>
2424
<artifactId>core</artifactId>
25-
<version>0.1.0-ALPHA29</version>
25+
<version>0.1.0-ALPHA30</version>
2626
<name>UProtocol</name>
2727
<description>Java implementation of uprotocol, an open specification for p2p content exchange</description>
2828
<licenses>
@@ -142,7 +142,7 @@
142142
<dependency>
143143
<groupId>org.monora.coolsocket</groupId>
144144
<artifactId>core</artifactId>
145-
<version>2.0-rc13</version>
145+
<version>2.0-rc15</version>
146146
</dependency>
147147
<dependency>
148148
<groupId>org.junit.vintage</groupId>
@@ -161,6 +161,7 @@
161161
<groupId>org.jetbrains</groupId>
162162
<artifactId>annotations</artifactId>
163163
<version>16.0.2</version>
164+
<scope>compile</scope>
164165
</dependency>
165166
<dependency>
166167
<!--Some Android 4~ doesn't have Base64 built-in-->

src/main/java/org/monora/uprotocol/core/transfer/Transfers.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.jetbrains.annotations.NotNull;
44
import org.json.JSONException;
55
import org.json.JSONObject;
6-
import org.monora.coolsocket.core.response.SizeOverflowException;
76
import org.monora.coolsocket.core.session.ActiveConnection;
87
import org.monora.coolsocket.core.session.CancelledException;
98
import org.monora.uprotocol.core.CommunicationBridge;
@@ -165,7 +164,7 @@ public static void receive(@NotNull CommunicationBridge bridge, @NotNull Transfe
165164
/**
166165
* Handle the sending process. You can invoke this method via {@link TransportSeat#beginFileTransfer} method when
167166
* the type is {@link TransferItem.Type#Outgoing}.
168-
*
167+
* <p>
169168
* This can also be invoked when using {@link CommunicationBridge#requestFileTransferStart}.
170169
*
171170
* @param bridge The bridge that speaks on behalf of you when making requests. A connection wrapper.
@@ -218,20 +217,32 @@ public static void send(@NotNull CommunicationBridge bridge, @NotNull TransferOp
218217
byte[] bytes = new byte[8096];
219218
int len;
220219

221-
try {
222-
while ((len = inputStream.read(bytes)) != -1) {
223-
operation.publishProgress();
220+
// For avoiding Android MediaStore bug where the reported size is different than actual
221+
// data size.
222+
boolean exceedingClose = false;
223+
long available;
224224

225-
if (len > 0) {
226-
operation.setBytesOngoing(operation.getBytesOngoing() + len, len);
227-
activeConnection.write(description, bytes, 0, len);
225+
while ((len = inputStream.read(bytes)) != -1) {
226+
operation.publishProgress();
227+
228+
if (len > 0) {
229+
available = description.available();
230+
if (len > available) {
231+
len = (int) available;
232+
exceedingClose = true;
228233
}
229-
}
230234

231-
activeConnection.writeEnd(description);
232-
} catch (SizeOverflowException ignored) {
235+
operation.setBytesOngoing(operation.getBytesOngoing() + len, len);
236+
activeConnection.write(description, bytes, 0, len);
237+
238+
if (exceedingClose) {
239+
break;
240+
}
241+
}
233242
}
234243

244+
activeConnection.writeEnd(description);
245+
235246
operation.setBytesTotal(operation.getBytesTotal() + operation.getBytesOngoing());
236247
operation.setCount(operation.getCount() + 1);
237248
operation.clearBytesOngoing();

0 commit comments

Comments
 (0)