List of usage examples for org.apache.commons.httpclient ChunkedOutputStream write
public void write(byte[] paramArrayOfByte) throws IOException
From source file:com.eucalyptus.blockstorage.PutMethodWithProgress.java
@Override protected boolean writeRequestBody(HttpState state, HttpConnection conn) throws IOException { InputStream inputStream;/*from w ww . j ava 2 s. c o m*/ if (outFile != null) { inputStream = new FileInputStream(outFile); ChunkedOutputStream chunkedOut = new ChunkedOutputStream(conn.getRequestOutputStream()); byte[] buffer = new byte[StorageProperties.TRANSFER_CHUNK_SIZE]; int bytesRead; long totalBytesProcessed = 0; while ((bytesRead = inputStream.read(buffer)) > 0) { ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPOutputStream zip = new GZIPOutputStream(out); zip.write(buffer, 0, bytesRead); zip.close(); chunkedOut.write(out.toByteArray()); totalBytesProcessed += bytesRead; callback.update(totalBytesProcessed); } if (totalBytesProcessed > 0) { callback.finish(); } else { callback.failed(); } chunkedOut.finish(); inputStream.close(); } else { return false; } return true; }
From source file:edu.ucsb.eucalyptus.cloud.ws.PutMethodWithProgress.java
@Override protected boolean writeRequestBody(HttpState state, HttpConnection conn) throws IOException { InputStream inputStream;//from ww w . j a v a 2 s. co m if (outFile != null) { inputStream = new FileInputStream(outFile); ChunkedOutputStream chunkedOut = new ChunkedOutputStream(conn.getRequestOutputStream()); byte[] buffer = new byte[StorageProperties.TRANSFER_CHUNK_SIZE]; int bytesRead; int numberProcessed = 0; long totalBytesProcessed = 0; while ((bytesRead = inputStream.read(buffer)) > 0) { ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPOutputStream zip = new GZIPOutputStream(out); zip.write(buffer, 0, bytesRead); zip.close(); chunkedOut.write(out.toByteArray()); totalBytesProcessed += bytesRead; if (++numberProcessed >= callback.getUpdateThreshold()) { callback.run(); numberProcessed = 0; } } if (totalBytesProcessed > 0) { callback.finish(); } else { callback.failed(); } chunkedOut.finish(); inputStream.close(); } else { return false; } return true; }