List of usage examples for org.apache.commons.net.io Util DEFAULT_COPY_BUFFER_SIZE
int DEFAULT_COPY_BUFFER_SIZE
To view the source code for org.apache.commons.net.io Util DEFAULT_COPY_BUFFER_SIZE.
Click Source Link
From source file:io.dockstore.common.FileProvisioning.java
/** * Copy from stream to stream while displaying progress * * @param inputStream source//from w w w.j a v a2 s. c o m * @param inputSize total size * @param outputSteam destination * @throws IOException */ private static void copyFromInputStreamToOutputStream(InputStream inputStream, long inputSize, OutputStream outputSteam) throws IOException { CopyStreamListener listener = new CopyStreamListener() { ProgressPrinter printer = new ProgressPrinter(); @Override public void bytesTransferred(CopyStreamEvent event) { /** do nothing */ } @Override public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize) { printer.handleProgress(totalBytesTransferred, streamSize); } }; try (OutputStream outputStream = outputSteam) { Util.copyStream(inputStream, outputStream, Util.DEFAULT_COPY_BUFFER_SIZE, inputSize, listener); } catch (IOException e) { throw new RuntimeException("Could not provision input files", e); } finally { IOUtils.closeQuietly(inputStream); System.out.println(); } }
From source file:com.vimeo.VimeoUploadClient.java
/** * upload file (streaming)// ww w . j a v a 2 s . c o m * * @param endpoint */ private void doPut(String endpoint) { URL endpointUrl; HttpURLConnection connection; try { endpointUrl = new URL(endpoint); connection = (HttpURLConnection) endpointUrl.openConnection(); connection.setRequestMethod("PUT"); connection.setRequestProperty("Content-Length", videoFile.length() + ""); connection.setRequestProperty("Content-Type", new MimetypesFileTypeMap().getContentType(videoFile)); connection.setFixedLengthStreamingMode((int) videoFile.length()); connection.setDoOutput(true); CopyStreamListener listener = new CopyStreamListener() { public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize) { // TODO: get the values to visualize it: currentStreamSize, // currentBytesTransferred currentStreamSize = streamSize; currentBytesTransferred = totalBytesTransferred; /* * System.out.printf("\r%-30S: %d / %d (%d %%)", "Sent", * totalBytesTransferred, streamSize, totalBytesTransferred * * 100 / streamSize); */ } public void bytesTransferred(CopyStreamEvent event) { } }; InputStream in = new FileInputStream(videoFile); OutputStream out = connection.getOutputStream(); System.out.println("Uploading \"" + videoFile.getAbsolutePath() + "\"... "); long c = Util.copyStream(in, out, Util.DEFAULT_COPY_BUFFER_SIZE, videoFile.length(), listener); System.out.printf("\n%-30S: %d\n", "Bytes sent", c); in.close(); out.close(); // return code System.out.printf("\n%-30S: %d\n", "Response code", connection.getResponseCode()); // TODO: Response code, if everything OK the code is 200 } catch (Exception e) { e.printStackTrace(); } }