/** * Copies all bytes from the given input stream to the given output stream. * Caller is responsible for closing the streams. * * @throws IOException if there is any IO exception during read or write. */ public static long copy(InputStream in, OutputStream out) throws IOException { return copy(in, out, Long.MAX_VALUE); }
/** * Execute the external process to retrieve credentials. */ private String executeCommand() throws IOException, InterruptedException { ProcessBuilder processBuilder = new ProcessBuilder(command); ByteArrayOutputStream commandOutput = new ByteArrayOutputStream(); Process process = processBuilder.start(); try { IOUtils.copy(process.getInputStream(), commandOutput, processOutputLimit); process.waitFor(); if (process.exitValue() != 0) { throw new IllegalStateException("Command returned non-zero exit value: " + process.exitValue()); } return new String(commandOutput.toByteArray(), StringUtils.UTF8); } finally { process.destroy(); } }
copy(resultInputStream, out); res = out.toString().trim(); } catch (Throwable e) {
/** * It's important to override writeTo. Some versions of Apache HTTP * client use writeTo for {@link org.apache.http.entity.BufferedHttpEntity} * and the default implementation just delegates to the wrapped entity * which completely bypasses our CRC32 calculating input stream. The * {@link org.apache.http.entity.BufferedHttpEntity} is used for the * request timeout and client execution timeout features. * * @see <a href="https://github.com/aws/aws-sdk-java/issues/526">Issue #526</a> * * @param outstream OutputStream to write contents to */ @Override public void writeTo(OutputStream outstream) throws IOException { try { IOUtils.copy(this.getContent(), outstream); } finally { this.getContent().close(); } } };
long count = IOUtils.copy(payload, bufferedOutputStream); bufferedOutputStream.flush(); logger.debug("Uploaded {} bytes to uri: {}", count, uri);
/** * Used for performance testing purposes only. */ private void putLocalObject(final UploadObjectRequest reqIn, OutputStream os) throws IOException { UploadObjectRequest req = reqIn.clone(); final File fileOrig = req.getFile(); final InputStream isOrig = req.getInputStream(); if (isOrig == null) { if (fileOrig == null) throw new IllegalArgumentException("Either a file lor input stream must be specified"); req.setInputStream(new FileInputStream(fileOrig)); req.setFile(null); } try { IOUtils.copy(req.getInputStream(), os); } finally { cleanupDataSource(req, fileOrig, isOrig, req.getInputStream(), log); IOUtils.closeQuietly(os, log); } return; }
@Override public final void putLocalObjectSecurely(final UploadObjectRequest reqIn, String uploadId, OutputStream os) throws IOException { UploadObjectRequest req = reqIn.clone(); final File fileOrig = req.getFile(); final InputStream isOrig = req.getInputStream(); final T uploadContext = multipartUploadContexts.get(uploadId); ContentCryptoMaterial cekMaterial = uploadContext.getContentCryptoMaterial(); req = wrapWithCipher(req, cekMaterial); try { IOUtils.copy(req.getInputStream(), os); // so it won't crap out with a false negative at the end; (Not // really relevant here) uploadContext.setHasFinalPartBeenSeen(true); } finally { cleanupDataSource(req, fileOrig, isOrig, req.getInputStream(), log); IOUtils.closeQuietly(os, log); } return; }
/** * Copies all bytes from the given input stream to the given output stream. * Caller is responsible for closing the streams. * * @throws IOException if there is any IO exception during read or write. */ public static long copy(InputStream in, OutputStream out) throws IOException { return copy(in, out, Long.MAX_VALUE); }
connection.setRequestProperty("x-amz-server-side-encryption", "AES256"); OutputStream outputStream = connection.getOutputStream(); IOUtils.copy(stream, outputStream); connection.getResponseCode(); } catch (MalformedURLException e) {
/** * Execute the external process to retrieve credentials. */ private String executeCommand() throws IOException, InterruptedException { ProcessBuilder processBuilder = new ProcessBuilder(command); ByteArrayOutputStream commandOutput = new ByteArrayOutputStream(); Process process = processBuilder.start(); try { IOUtils.copy(process.getInputStream(), commandOutput, processOutputLimit); process.waitFor(); if (process.exitValue() != 0) { throw new IllegalStateException("Command returned non-zero exit value: " + process.exitValue()); } return new String(commandOutput.toByteArray(), StringUtils.UTF8); } finally { process.destroy(); } }
/** * It's important to override writeTo. Some versions of Apache HTTP * client use writeTo for {@link org.apache.http.entity.BufferedHttpEntity} * and the default implementation just delegates to the wrapped entity * which completely bypasses our CRC32 calculating input stream. The * {@link org.apache.http.entity.BufferedHttpEntity} is used for the * request timeout and client execution timeout features. * * @see <a href="https://github.com/aws/aws-sdk-java/issues/526">Issue #526</a> * * @param outstream OutputStream to write contents to */ @Override public void writeTo(OutputStream outstream) throws IOException { try { IOUtils.copy(this.getContent(), outstream); } finally { this.getContent().close(); } } };
@Override public final void putLocalObjectSecurely(final UploadObjectRequest reqIn, String uploadId, OutputStream os) throws IOException { UploadObjectRequest req = reqIn.clone(); final File fileOrig = req.getFile(); final InputStream isOrig = req.getInputStream(); final T uploadContext = multipartUploadContexts.get(uploadId); final ContentCryptoMaterial cekMaterial = uploadContext.getContentCryptoMaterial(); req = wrapWithCipher(req, cekMaterial); try { IOUtils.copy(req.getInputStream(), os); // so it won't crap out with a false negative at the end; (Not // really relevant here) uploadContext.setHasFinalPartBeenSeen(true); } finally { cleanupDataSource(req, fileOrig, isOrig, req.getInputStream(), log); IOUtils.closeQuietly(os, log); } return; }
/** * It's important to override writeTo. Some versions of Apache HTTP * client use writeTo for {@link org.apache.http.entity.BufferedHttpEntity} * and the default implementation just delegates to the wrapped entity * which completely bypasses our CRC32 calculating input stream. The * {@link org.apache.http.entity.BufferedHttpEntity} is used for the * request timeout and client execution timeout features. * * @see <a href="https://github.com/aws/aws-sdk-java/issues/526">Issue #526</a> * * @param outstream OutputStream to write contents to */ @Override public void writeTo(OutputStream outstream) throws IOException { try { IOUtils.copy(this.getContent(), outstream); } finally { this.getContent().close(); } } };
long count = IOUtils.copy(payload, bufferedOutputStream); bufferedOutputStream.flush(); logger.debug("Uploaded {} bytes to uri: {}", count, uri);
protected Path downloadArtifactToTmpFile(BakeManifestEnvironment env, Artifact artifact) throws IOException { Path path = Paths.get(env.getStagingPath().toString(), nameFromReference(artifact.getReference())); OutputStream outputStream = new FileOutputStream(path.toString()); Response response = retrySupport.retry(() -> clouddriverService.fetchArtifact(artifact), 5, 1000, true); InputStream inputStream = response.getBody().in(); IOUtils.copy(inputStream, outputStream); inputStream.close(); outputStream.close(); return path; }
@Override public File getAsFile( FileDescriptor descriptor ) { assertValidDescriptor( descriptor ); try { File localFile = fileManager.createTempFile(); FileUtils.forceMkdir( localFile.getParentFile() ); IOUtils.copy( getInputStream( descriptor ), new FileOutputStream( localFile ) ); return localFile; } catch ( IOException e ) { throw new FileStorageException( e ); } catch ( AmazonServiceException e ) { LOG.error( "Unable to get file {} on Amazon", descriptor, e ); throw new FileStorageException( e ); } }
/** * Used for performance testing purposes only. */ private void putLocalObject(final UploadObjectRequest reqIn, OutputStream os) throws IOException { UploadObjectRequest req = reqIn.clone(); final File fileOrig = req.getFile(); final InputStream isOrig = req.getInputStream(); if (isOrig == null) { if (fileOrig == null) throw new IllegalArgumentException("Either a file lor input stream must be specified"); req.setInputStream(new FileInputStream(fileOrig)); req.setFile(null); } try { IOUtils.copy(req.getInputStream(), os); } finally { cleanupDataSource(req, fileOrig, isOrig, req.getInputStream(), log); IOUtils.closeQuietly(os, log); } return; }
@Override public final void putLocalObjectSecurely(final UploadObjectRequest reqIn, String uploadId, OutputStream os) throws IOException { UploadObjectRequest req = reqIn.clone(); final File fileOrig = req.getFile(); final InputStream isOrig = req.getInputStream(); final T uploadContext = multipartUploadContexts.get(uploadId); ContentCryptoMaterial cekMaterial = uploadContext.getContentCryptoMaterial(); req = wrapWithCipher(req, cekMaterial); try { IOUtils.copy(req.getInputStream(), os); // so it won't crap out with a false negative at the end; (Not // really relevant here) uploadContext.setHasFinalPartBeenSeen(true); } finally { cleanupDataSource(req, fileOrig, isOrig, req.getInputStream(), log); IOUtils.closeQuietly(os, log); } return; }
@Override public final void putLocalObjectSecurely(final UploadObjectRequest reqIn, String uploadId, OutputStream os) throws IOException { UploadObjectRequest req = reqIn.clone(); final File fileOrig = req.getFile(); final InputStream isOrig = req.getInputStream(); final T uploadContext = multipartUploadContexts.get(uploadId); final ContentCryptoMaterial cekMaterial = uploadContext.getContentCryptoMaterial(); req = wrapWithCipher(req, cekMaterial); try { IOUtils.copy(req.getInputStream(), os); // so it won't crap out with a false negative at the end; (Not // really relevant here) uploadContext.setHasFinalPartBeenSeen(true); } finally { cleanupDataSource(req, fileOrig, isOrig, req.getInputStream(), log); IOUtils.closeQuietly(os, log); } return; }