openConnection(); int bytesToRead = Math.min(getChunkSize(), bytesRemainingForRequest);
@Test public void testTusUploader() throws IOException, ProtocolException { byte[] content = "hello world".getBytes(); mockServer.when(new HttpRequest() .withPath("/files/foo") .withHeader("Tus-Resumable", TusClient.TUS_VERSION) .withHeader("Upload-Offset", "3") .withHeader("Content-Type", "application/offset+octet-stream") .withHeader(isOpenJDK6 ? "": "Expect: 100-continue") .withBody(Arrays.copyOfRange(content, 3, 11))) .respond(new HttpResponse() .withStatusCode(204) .withHeader("Tus-Resumable", TusClient.TUS_VERSION) .withHeader("Upload-Offset", "11")); TusClient client = new TusClient(); URL uploadUrl = new URL(mockServerURL + "/foo"); TusInputStream input = new TusInputStream(new ByteArrayInputStream(content)); long offset = 3; TusUploader uploader = new TusUploader(client, uploadUrl, input, offset); uploader.setChunkSize(5); assertEquals(uploader.getChunkSize(), 5); assertEquals(5, uploader.uploadChunk()); assertEquals(3, uploader.uploadChunk(5)); assertEquals(-1, uploader.uploadChunk()); assertEquals(-1, uploader.uploadChunk(5)); assertEquals(11, uploader.getOffset()); uploader.finish(); }