/** * This method is a shorthand for {@link #fillWithConstant(java.io.OutputStream, byte, long, int)} called with a * {@link BufferPool#getDefaultBufferSize default buffer size}. * * @param out the OutputStream to write to * @param value the byte constant to write len times * @param len number of bytes to write * @throws java.io.IOException if an error occurred while writing */ public static void fillWithConstant(OutputStream out, byte value, long len) throws IOException { fillWithConstant(out, value, len, BufferPool.getDefaultBufferSize()); }
/** * Returns this stream's digest, expressed as an hexadecimal string. * * @return this stream's digest, expressed as an hexadecimal string */ public String getChecksumString() { return ByteUtils.toHexString(getChecksumBytes()); } }
/** * This method is a shorthand for {@link #copyStream(java.io.InputStream, java.io.OutputStream, int)} called with a * {@link BufferPool#getDefaultBufferSize() default buffer size}. * * @param in the InputStream to read from * @param out the OutputStream to write to * @return the number of bytes that were copied * @throws FileTransferException if something went wrong while reading from or writing to one of the provided streams */ public static long copyStream(InputStream in, OutputStream out) throws FileTransferException { return copyStream(in, out, BufferPool.getDefaultBufferSize()); }
/** * This method is a shorthand for {@link #readUntilEOF(java.io.InputStream, int)} called with a * {@link BufferPool#getDefaultBufferSize default buffer size}. * * @param in the InputStream to read * @throws IOException if an I/O error occurs */ public static void readUntilEOF(InputStream in) throws IOException { readUntilEOF(in, BufferPool.getDefaultBufferSize()); }
/** * Convenience method that has the same effect as calling {@link #getByteArray(int)} with * a length equal to {@link #getDefaultBufferSize()}. * * @return a byte array with a length of {@link #getDefaultBufferSize()} */ public static synchronized byte[] getByteArray() { return getByteArray(getDefaultBufferSize()); }
/** * This method is a shorthand for {@link #copyChunk(RandomAccessInputStream, RandomAccessOutputStream, long, long, long, int)} * called with a {@link BufferPool#getDefaultBufferSize default buffer size}. * * @param rais the source stream * @param raos the destination stream * @param srcOffset offset to the beginning of the chunk in the source stream * @param destOffset offset to the beginning of the chunk in the destination stream * @param length number of bytes to copy * @throws java.io.IOException if an error occurred while copying data */ public static void copyChunk(RandomAccessInputStream rais, RandomAccessOutputStream raos, long srcOffset, long destOffset, long length) throws IOException { copyChunk(rais, raos, srcOffset, destOffset, length, BufferPool.getDefaultBufferSize()); }
/** * Returns the length of the given buffer, as defined by {@link com.mucommander.commons.io.BufferPool.BufferContainer#getLength()}. * * @param buffer the buffer for which to return the length * @param factory the factory that was used to create the buffer * @return the length of the given buffer */ private int getBufferLength(Object buffer, BufferPool.BufferFactory factory) { return factory.newBufferContainer(buffer).getLength(); }
/** * Returns the size in bytes of the given buffer, as defined by {@link com.mucommander.commons.io.BufferPool.BufferContainer#getSize()}. * * @param buffer the buffer for which to return the size * @param factory the factory that was used to create the buffer * @return the size in bytes of the given buffer */ private int getBufferSize(Object buffer, BufferPool.BufferFactory factory) { return factory.newBufferContainer(buffer).getSize(); }
/** * Creates a new <code>BufferedRandomOutputStream</code> on top of the given {@link RandomAccessOutputStream}. * An internal buffer of the specified size is created. * * @param raos the underlying RandomAccessOutputStream used by this buffered output stream * @param size size of the buffer in bytes */ public BufferedRandomOutputStream(RandomAccessOutputStream raos, int size) { this.raos = raos; this.buffer = BufferPool.getByteArray(size); }
/** * Returns the number of bytes that have been skipped in the current file. Bytes are skipped when file transfers * are resumed. * * @return the number of bytes that have been skipped in the current file */ public long getCurrentFileSkippedByteCount() { return currentFileSkippedByteCounter.getByteCount(); }
/** * Flushes this buffered output stream. This forces any buffered * output bytes to be written out to the underlying output stream. * * @throws IOException if an I/O error occurs. */ @Override public synchronized void flush() throws IOException { flushBuffer(); raos.flush(); }
/** * Returns this stream's digest, expressed as an hexadecimal string. * * @return this stream's digest, expressed as an hexadecimal string */ public String getChecksumString() { return ByteUtils.toHexString(getChecksumBytes()); } }
/** * Checks if the current buffered block has been read completely (i.e. no more data is available) and if it has, * calls {@link #readBlock(long, byte[], int)} to fetch the next block. * * @throws IOException if an I/O error occurred */ private void checkBuffer() throws IOException { if(blockOff >= blockLen) // True initially readBlock(); }
/** * Increases the number of bytes read this second to the given number. * * @param nbRead number of bytes that have been read or skipped from the underlying stream. */ private void addToLimitCounter(long nbRead) { updateLimitCounter(); this.nbBytesReadThisSecond += nbRead; }
@Override public void close() throws IOException { super.close(); // Declare the zip file and entries tree up-to-date and add the new entry to the entries tree finishAddEntry(entry); } };
/** * Returns the total number of bytes that have been processed by this job so far. * * @return the total number of bytes that have been processed by this job so far */ public long getTotalByteCount() { return totalByteCounter.getByteCount(); }
public void seek(long newOffset) throws IOException { // If the new offset is within the current buffer's range, simply reposition the offsets if(newOffset>=offset && newOffset<offset+ blockLen) { blockOff += (int)(newOffset-offset); offset = newOffset; } // If not, retrieve a block of data starting at the new offset and fill the buffer with it else { offset = newOffset; readBlock(); } }