Skip to content

Commit 32b7105

Browse files
authored
Fix length of byte array in upload (#38)
When uploading a chunk of data, truncate unnecessary null bytes from the end.
1 parent ff32304 commit 32b7105

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/main/java/ai/nightfall/scan/NightfallClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.InputStream;
3030
import java.time.Duration;
3131
import java.time.Instant;
32+
import java.util.Arrays;
3233
import java.util.UUID;
3334
import java.util.concurrent.ExecutorService;
3435
import java.util.concurrent.Executors;
@@ -218,6 +219,8 @@ private boolean doChunkedUpload(
218219
if (bytesRead < data.length && notLastChunk) {
219220
semaphore.release();
220221
throw new NightfallClientException("failed to read data from input stream");
222+
} else if (bytesRead < data.length) {
223+
data = Arrays.copyOfRange(data, 0, bytesRead);
221224
}
222225
} catch (IOException e) {
223226
semaphore.release();

0 commit comments

Comments
 (0)