public InputStream openStream(long start) throws IOException { payload = (payload == null) ? objectApi.get(path, start).getPayload() : payload; try { return payload.openStream(); } catch (IOException e) { if (CloudFilesUtils.CLOUDFILESRETRY.apply(e)) { throw new IOException("Recoverable exception", e); } throw Throwables.propagate(e); } } }
tempFile.deleteOnExit(); fop = new FileOutputStream(tempFile); InputStream is = blob.getPayload().openStream(); IOUtils.copyLarge(is, fop); return tempFile;
try (InputStream is = blob.getPayload().openStream(); OutputStream os = response.getOutputStream()) { ByteStreams.copy(is, os);
@Override @Nullable public Blob getBlob(String container, String name, GetOptions options) { Blob blob = super.getBlob(container, name, options); if (blob == null) { return null; } byte[] array; try (InputStream is = blob.getPayload().openStream()) { array = ByteStreams.toByteArray(is); } catch (IOException ioe) { throw new RuntimeException(ioe); } long length = Longs.fromByteArray(array); ByteSourcePayload payload = new ByteSourcePayload( new NullByteSource().slice(0, length)); payload.setContentMetadata(blob.getPayload().getContentMetadata()); payload.getContentMetadata().setContentLength(length); payload.getContentMetadata().setContentMD5((HashCode) null); blob.setPayload(payload); return blob; }
@Override public String putBlob(String containerName, Blob blob, PutOptions options) { long length; try (InputStream is = blob.getPayload().openStream()) { length = ByteStreams.copy(is, ByteStreams.nullOutputStream()); } catch (IOException ioe) { throw new RuntimeException(ioe); } byte[] array = Longs.toByteArray(length); ByteSourcePayload payload = new ByteSourcePayload( ByteSource.wrap(array)); payload.setContentMetadata(blob.getPayload().getContentMetadata()); payload.getContentMetadata().setContentLength((long) array.length); payload.getContentMetadata().setContentMD5((HashCode) null); blob.setPayload(payload); return super.putBlob(containerName, blob, options); }
/** * {@inheritDoc} */ @Override public InputStream openStream() throws IOException { return delegate.openStream(); }
/** * {@inheritDoc} */ @Override public InputStream openStream() throws IOException { return delegate.openStream(); }
/** * {@inheritDoc} */ @Override public InputStream openStream() throws IOException { return delegate.openStream(); }
@Override public MultipartPart uploadMultipartPart(MultipartUpload mpu, int partNumber, Payload payload) { long length; try (InputStream is = payload.openStream()) { length = ByteStreams.copy(is, ByteStreams.nullOutputStream()); } catch (IOException ioe) { throw new RuntimeException(ioe); } byte[] array = Longs.toByteArray(length); ByteSourcePayload newPayload = new ByteSourcePayload( ByteSource.wrap(array)); newPayload.setContentMetadata(payload.getContentMetadata()); newPayload.getContentMetadata().setContentLength((long) array.length); newPayload.getContentMetadata().setContentMD5((HashCode) null); MultipartPart part = super.uploadMultipartPart(mpu, partNumber, newPayload); return MultipartPart.create(part.partNumber(), length, part.partETag(), part.lastModified()); }
@Override public byte[] decrypt(InputStream input) throws IOException { @SuppressWarnings("resource") Payload payload = new RSADecryptingPayload(crypto, Payloads.newPayload(input), privateKey.get()); return ByteStreams2.toByteArrayAndClose(payload.openStream()); }
@Override public byte[] encrypt(InputStream input) throws IOException { @SuppressWarnings("resource") Payload payload = new RSAEncryptingPayload(crypto, Payloads.newPayload(input), privateKey.get()); return ByteStreams2.toByteArrayAndClose(payload.openStream()); }
public String parseMessage(HttpResponse response) { if (response.getPayload() == null) return null; try { return Strings2.toStringAndClose(response.getPayload().openStream()); } catch (IOException e) { throw Throwables.propagate(e); } } }
public String parseMessage(HttpResponse response) { if (response.getPayload() == null) return null; try { return Strings2.toStringAndClose(response.getPayload().openStream()); } catch (IOException e) { throw Throwables.propagate(e); } } }
public String parseMessage(final HttpResponse response) { if (response.getPayload() == null) { return null; } try { return Strings2.toStringAndClose(response.getPayload().openStream()); } catch (IOException e) { throw new RuntimeException(e); } } }
public String parseMessage(HttpResponse response) { if (response.getPayload() == null) return null; try { return toStringAndClose(response.getPayload().openStream()); } catch (IOException e) { throw new RuntimeException(e); } finally { releasePayload(response); } } }
public String parseMessage(HttpResponse response) { if (response.getPayload() == null) return null; try { return toStringAndClose(response.getPayload().openStream()); } catch (IOException e) { throw new RuntimeException(e); } finally { releasePayload(response); } } }
public void handleError(HttpCommand command, HttpResponse from) { String content; try { content = from.getPayload() != null ? Strings2.toStringAndClose(from.getPayload().openStream()) : null; command.setException(new HttpResponseException(command, from, content)); } catch (IOException e) { command.setException(new HttpResponseException(command, from)); } finally { releasePayload(from); } } }
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) { if (response.getPayload() != null) { try { return Strings2.toStringAndClose(response.getPayload().openStream()); } catch (IOException e) { logger.warn(e, "exception reading error from response", response); } } return null; } }
@Test void aesCodecShouldEncryptPayloadContentWhenWriting() throws Exception { Payload payload = codec().write(expected()); byte[] bytes = IOUtils.toByteArray(payload.openStream()); // authenticated encryption uses a random salt for the authentication // header all we can say for sure is that the output is not the same as // the input. assertThat(bytes).isNotEqualTo(SOME_BYTES); }
@Test void defaultCodecShouldNotChangePayloadContentWhenWriting() throws Exception { Payload payload = codec().write(expected()); assertThat(payload.openStream()).hasSameContentAs(expected()); }