public static InputStreamPayload newInputStreamPayload(InputStream data) { return new InputStreamPayload(checkNotNull(data, "data")); }
public static InputStreamPayload newInputStreamPayload(InputStream data) { return new InputStreamPayload(checkNotNull(data, "data")); }
public static InputStreamPayload newInputStreamPayload(InputStream data) { return new InputStreamPayload(checkNotNull(data, "data")); }
public static InputStreamPayload newInputStreamPayload(InputStream data) { return new InputStreamPayload(checkNotNull(data, "data")); }
public static InputStreamPayload newInputStreamPayload(InputStream data) { return new InputStreamPayload(checkNotNull(data, "data")); }
public static InputStreamPayload newInputStreamPayload(InputStream data) { return new InputStreamPayload(checkNotNull(data, "data")); }
@Override public InputStream put(String key, InputStream value) { return putInternal(key, new InputStreamPayload(value)); }
byte[] input = data.getBytes("UTF-8"); InputStream is = new ByteArrayInputStream(input); Payload payload = new InputStreamPayload(is); payload.getContentMetadata().setContentLength(input.length);
@Override public InputStream put(String key, InputStream value) { return putInternal(key, new InputStreamPayload(value)); }
protected Payload doSlice(InputStream content, long offset, long length) { try { ByteStreams.skipFully(content, offset); } catch (IOException ioe) { throw Throwables.propagate(ioe); } return new InputStreamPayload(ByteStreams.limit(content, length)); }
protected Payload doSlice(InputStream content, long offset, long length) { try { ByteStreams.skipFully(content, offset); } catch (IOException ioe) { throw Throwables.propagate(ioe); } return new InputStreamPayload(ByteStreams.limit(content, length)); }
@Converter public static Payload toPayload(final InputStream is, Exchange exchange) throws IOException { InputStreamPayload payload = new InputStreamPayload(is); // only set the contentlength if possible if (is.markSupported()) { long contentLength = ByteStreams.toByteArray(is).length; is.reset(); payload.getContentMetadata().setContentLength(contentLength); } return payload; }
protected Payload doSlice(InputStream content, long offset, long length) { try { ByteStreams.skipFully(content, offset); } catch (IOException ioe) { throw Throwables.propagate(ioe); } return new InputStreamPayload(ByteStreams.limit(content, length)); }
@Test public void testIterableSliceExpectedSingle() throws IOException { PayloadSlicer slicer = new BasePayloadSlicer(); String contents = "aaaaaaaaaabbbbbbbbbbccccc"; Payload payload = new InputStreamPayload(new ByteArrayInputStream(contents.getBytes(Charsets.US_ASCII))); Iterator<Payload> iter = slicer.slice(payload, 25).iterator(); assertTrue(iter.hasNext(), "Not enough results"); assertEquals(Strings2.toStringAndClose(iter.next().openStream()), contents); assertFalse(iter.hasNext()); }
@Test public void testIterableSliceExpectedMulti() throws IOException { PayloadSlicer slicer = new BasePayloadSlicer(); Payload payload = new InputStreamPayload(new ByteArrayInputStream("aaaaaaaaaabbbbbbbbbbccccc".getBytes(Charsets.US_ASCII))); Iterator<Payload> iter = slicer.slice(payload, 10).iterator(); assertTrue(iter.hasNext(), "Not enough results"); assertEquals(Strings2.toStringAndClose(iter.next().getInput()), "aaaaaaaaaa"); assertTrue(iter.hasNext(), "Not enough results"); assertEquals(Strings2.toStringAndClose(iter.next().getInput()), "bbbbbbbbbb"); assertTrue(iter.hasNext(), "Not enough results"); assertEquals(Strings2.toStringAndClose(iter.next().getInput()), "ccccc"); assertFalse(iter.hasNext()); }
@Converter public static Payload toPayload(final StreamSourceCache cache, Exchange exchange) throws IOException { long contentLength = ByteStreams.toByteArray(cache.getInputStream()).length; cache.reset(); InputStreamPayload payload = new InputStreamPayload(cache.getInputStream()); payload.getContentMetadata().setContentLength(contentLength); setContentMetadata(payload, exchange); return payload; }
@Test(groups = { "integration", "live" }) public void testPutZeroLengthInputStream() throws Exception { long length = 0; // do not use ByteSource.empty() since it is backed by a // ByteArrayInputStream which supports reset ByteSource byteSource = TestUtils.randomByteSource().slice(0, length); Payload payload = new InputStreamPayload(byteSource.openStream()); testPut(payload, null, payload, length, new PutOptions()); }
public void testWritePayloadOnFileInputStream() throws IOException { String blobKey = TestUtils.createRandomBlobKey("writePayload-", ".img"); File sourceFile = TestUtils.getImageForBlobPayload(); InputStreamPayload fileInputStreamPayload = new InputStreamPayload( new FileInputStream(sourceFile)); Blob blob = storageStrategy.newBlob(blobKey); blob.setPayload(fileInputStreamPayload); // write files storageStrategy.putBlob(CONTAINER_NAME, blob); // verify that the files is equal File blobFullPath = new File(TARGET_CONTAINER_NAME, blobKey); ByteSource expectedInput = Files.asByteSource(sourceFile); ByteSource actualInput = Files.asByteSource(blobFullPath); assertTrue(expectedInput.contentEquals(actualInput), "Files are not equal"); }
@Test(groups = { "integration", "live" }) public void testPutInputStream() throws Exception { long length = 42; ByteSource byteSource = TestUtils.randomByteSource().slice(0, length); Payload payload = new InputStreamPayload(byteSource.openStream()); testPut(payload, null, new ByteSourcePayload(byteSource), length, new PutOptions()); }
@Test(groups = { "integration", "live" }) public void testPutMultipartInputStream() throws Exception { long length = Math.max(getMinimumMultipartBlobSize(), MultipartUploadSlicingAlgorithm.DEFAULT_PART_SIZE + 1); BlobStore blobStore = view.getBlobStore(); MultipartUploadSlicingAlgorithm algorithm = new MultipartUploadSlicingAlgorithm( blobStore.getMinimumMultipartPartSize(), blobStore.getMaximumMultipartPartSize(), blobStore.getMaximumNumberOfParts()); // make sure that we are creating multiple parts assertThat(algorithm.calculateChunkSize(length)).isLessThan(length); ByteSource byteSource = TestUtils.randomByteSource().slice(0, length); Payload payload = new InputStreamPayload(byteSource.openStream()); testPut(payload, null, new ByteSourcePayload(byteSource), length, new PutOptions().multipart(true)); }