public static InputStreamPayload newInputStreamPayload(InputStream data) { return new InputStreamPayload(checkNotNull(data, "data")); }
@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; }
public static InputStreamPayload newInputStreamPayload(InputStream data) { return new InputStreamPayload(checkNotNull(data, "data")); }
@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; }
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)); }
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()); }
private String emulateCopyBlob(BlobStore blobStore, Response resp, BlobMetadata meta, String destContainer, String destObject, CopyOptions options) { Response.StatusType statusInfo = resp.getStatusInfo(); if (statusInfo.equals(Response.Status.OK)) { ContentMetadata contentMetadata = meta.getContentMetadata(); Map<String, String> newMetadata = new HashMap<>(); newMetadata.putAll(meta.getUserMetadata()); newMetadata.putAll(options.userMetadata()); RESERVED_METADATA.forEach(s -> newMetadata.remove(s)); Blob blob = blobStore.blobBuilder(destObject) .userMetadata(newMetadata) .payload(new InputStreamPayload((InputStream) resp.getEntity())) .contentLength(resp.getLength()) .contentDisposition(contentMetadata.getContentDisposition()) .contentEncoding(contentMetadata.getContentEncoding()) .contentType(contentMetadata.getContentType()) .contentLanguage(contentMetadata.getContentLanguage()) .build(); return blobStore.putBlob(destContainer, blob); } else { throw new ClientErrorException(statusInfo.getReasonPhrase(), statusInfo.getStatusCode()); } }
@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()); }