public InputStream copy(final String header, InputStream instream) { int limit = 256 * 1024; FileBackedOutputStream out = null; try { out = new FileBackedOutputStream(limit); long bytesRead = ByteStreams.copy(instream, out); if (bytesRead >= limit) logger.debug("over limit %d/%d: wrote temp file", bytesRead, limit); wire(header, out.getSupplier().getInput()); return out.getSupplier().getInput(); } catch (IOException e) { throw new RuntimeException("Error tapping line", e); } finally { closeQuietly(out); closeQuietly(instream); } }
public InputStream copy(final String header, InputStream instream) { int limit = 256 * 1024; final FileBackedOutputStream out = new FileBackedOutputStream(limit); try { long bytesRead = ByteStreams.copy(instream, out); if (bytesRead >= limit) logger.debug("over limit %d/%d: wrote temp file", bytesRead, limit); wire(header, out.getSupplier().getInput()); // we must call FileBackedOutputStream.reset to remove temporary file return new FilterInputStream(out.getSupplier().getInput()) { @Override public void close() throws IOException { super.close(); out.reset(); } }; } catch (IOException e) { throw new RuntimeException("Error tapping line", e); } finally { closeQuietly(out); closeQuietly(instream); } }
FileBackedOutputStream fbout = new FileBackedOutputStream(MAX_MEMORY_FILE_SIZE, true); updatedSize = ByteStreams.copy(compressedInputStream, fbout); in1 = fbout.getSupplier().getInput(); compressed = true; } else {
@Override public BlobURI write(final UUID messageId, final Mailbox mailbox, final String profileName, final InputStream in, final Long size) throws IOException, GeneralSecurityException { // get blob name String blobName = new BlobNameBuilder().setMailbox(mailbox) .setMessageId(messageId).setMessageSize(size).build(); InputStream in1; Long updatedSize = size; // prepare URI BlobURI blobUri = new BlobURI() .setProfile(profileName) .setName(blobName); // encrypt stream if (encryptionHandler != null) { byte[] iv = getCipherIVFromBlobName(blobName); InputStream encryptedInputStream = this.encryptionHandler.encrypt(in, Configurator.getBlobStoreDefaultEncryptionKey(), iv); FileBackedOutputStream fbout = new FileBackedOutputStream(MAX_MEMORY_FILE_SIZE, true); updatedSize = ByteStreams.copy(encryptedInputStream, fbout); in1 = fbout.getSupplier().getInput(); blobUri.setEncryptionKey(Configurator.getBlobStoreDefaultEncryptionKeyAlias()); } else { in1 = in; } CloudStoreProxy.write(blobName, profileName, in1, updatedSize); return blobUri; }