/** * Returns new {@link FastByteArrayOutputStream} using default IO buffer size. * * @return new {@link FastByteArrayOutputStream} using default IO buffer size. */ private static FastByteArrayOutputStream createFastByteArrayOutputStream() { return new FastByteArrayOutputStream(bufferSize()); }
/** * Copies bytes from {@link InputStream} to {@link OutputStream} using buffer. * {@link InputStream} and {@link OutputStream} don't have to be wrapped to buffered, * since copying is already optimized. * * @param input {@link InputStream} to read. * @param output {@link OutputStream} to write to. * @return The total number of bytes read. * @throws IOException if there is an error reading or writing. */ public static int copy(final InputStream input, final OutputStream output) throws IOException { int numToRead = bufferSize(); byte[] buffer = new byte[numToRead]; int totalRead = ZERO; int read; while ((read = input.read(buffer, ZERO, numToRead)) >= ZERO) { output.write(buffer, ZERO, read); totalRead = totalRead + read; } output.flush(); return totalRead; }
/** * Returns new {@link FastCharArrayWriter} using default IO buffer size. * * @return new {@link FastCharArrayWriter} using default IO buffer size. */ private static FastCharArrayWriter createFastCharArrayWriter() { return new FastCharArrayWriter(bufferSize()); }
/** * Copies bytes from {@link Reader} to {@link Writer} using buffer. * {@link Reader} and {@link Writer} don't have to be wrapped to buffered, since copying is already optimized. * * @param input {@link Reader} to read. * @param output {@link Writer} to write to. * @return The total number of characters read. * @throws IOException if there is an error reading or writing. */ public static int copy(final Reader input, final Writer output) throws IOException { int numToRead = bufferSize(); char[] buffer = new char[numToRead]; int totalRead = ZERO; int read; while ((read = input.read(buffer, ZERO, numToRead)) >= ZERO) { output.write(buffer, ZERO, read); totalRead = totalRead + read; } output.flush(); return totalRead; }
/** * Copies specified number of characters from {@link Reader} to {@link Writer} using buffer. * {@link Reader} and {@link Writer} don't have to be wrapped to buffered, since copying is already optimized. * * @param input {@link Reader} to read. * @param output {@link Writer} to write to. * @param count The number of characters to read. * @return The total number of characters read. * @throws IOException if there is an error reading or writing. */ public static int copy(final Reader input, final Writer output, final int count) throws IOException { if (count == ALL) { return copy(input, output); } int numToRead = count; char[] buffer = new char[numToRead]; int totalRead = ZERO; int read; while (numToRead > ZERO) { read = input.read(buffer, ZERO, bufferSize(numToRead)); if (read == NEGATIVE_ONE) { break; } output.write(buffer, ZERO, read); numToRead = numToRead - read; totalRead = totalRead + read; } output.flush(); return totalRead; }
/** * Copies specified number of bytes from {@link InputStream} to {@link OutputStream} using buffer. * {@link InputStream} and {@link OutputStream} don't have to be wrapped to buffered, since copying is already optimized. * * @param input {@link InputStream} to read. * @param output {@link OutputStream} to write to. * @param count The number of bytes to read. * @return The total number of bytes read. * @throws IOException if there is an error reading or writing. */ public static int copy(final InputStream input, final OutputStream output, final int count) throws IOException { if (count == ALL) { return copy(input, output); } int numToRead = count; byte[] buffer = new byte[numToRead]; int totalRead = ZERO; int read; while (numToRead > ZERO) { read = input.read(buffer, ZERO, bufferSize(numToRead)); if (read == NEGATIVE_ONE) { break; } output.write(buffer, ZERO, read); numToRead = numToRead - read; totalRead = totalRead + read; } output.flush(); return totalRead; }
/** * Returns new {@link FastByteArrayOutputStream} using default IO buffer size. * * @return new {@link FastByteArrayOutputStream} using default IO buffer size. */ private static FastByteArrayOutputStream createFastByteArrayOutputStream() { return new FastByteArrayOutputStream(bufferSize()); }
/** * Returns new {@link FastCharArrayWriter} using default IO buffer size. * * @return new {@link FastCharArrayWriter} using default IO buffer size. */ private static FastCharArrayWriter createFastCharArrayWriter() { return new FastCharArrayWriter(bufferSize()); }
/** * Copies bytes from {@link Reader} to {@link Writer} using buffer. * {@link Reader} and {@link Writer} don't have to be wrapped to buffered, since copying is already optimized. * * @param input {@link Reader} to read. * @param output {@link Writer} to write to. * @return The total number of characters read. * @throws IOException if there is an error reading or writing. */ public static int copy(final Reader input, final Writer output) throws IOException { int numToRead = bufferSize(); char[] buffer = new char[numToRead]; int totalRead = ZERO; int read; while ((read = input.read(buffer, ZERO, numToRead)) >= ZERO) { output.write(buffer, ZERO, read); totalRead = totalRead + read; } output.flush(); return totalRead; }
/** * Copies bytes from {@link InputStream} to {@link OutputStream} using buffer. * {@link InputStream} and {@link OutputStream} don't have to be wrapped to buffered, * since copying is already optimized. * * @param input {@link InputStream} to read. * @param output {@link OutputStream} to write to. * @return The total number of bytes read. * @throws IOException if there is an error reading or writing. */ public static int copy(final InputStream input, final OutputStream output) throws IOException { int numToRead = bufferSize(); byte[] buffer = new byte[numToRead]; int totalRead = ZERO; int read; while ((read = input.read(buffer, ZERO, numToRead)) >= ZERO) { output.write(buffer, ZERO, read); totalRead = totalRead + read; } output.flush(); return totalRead; }
/** * Copies specified number of characters from {@link Reader} to {@link Writer} using buffer. * {@link Reader} and {@link Writer} don't have to be wrapped to buffered, since copying is already optimized. * * @param input {@link Reader} to read. * @param output {@link Writer} to write to. * @param count The number of characters to read. * @return The total number of characters read. * @throws IOException if there is an error reading or writing. */ public static int copy(final Reader input, final Writer output, final int count) throws IOException { if (count == ALL) { return copy(input, output); } int numToRead = count; char[] buffer = new char[numToRead]; int totalRead = ZERO; int read; while (numToRead > ZERO) { read = input.read(buffer, ZERO, bufferSize(numToRead)); if (read == NEGATIVE_ONE) { break; } output.write(buffer, ZERO, read); numToRead = numToRead - read; totalRead = totalRead + read; } output.flush(); return totalRead; }
/** * Copies specified number of bytes from {@link InputStream} to {@link OutputStream} using buffer. * {@link InputStream} and {@link OutputStream} don't have to be wrapped to buffered, since copying is already optimized. * * @param input {@link InputStream} to read. * @param output {@link OutputStream} to write to. * @param count The number of bytes to read. * @return The total number of bytes read. * @throws IOException if there is an error reading or writing. */ public static int copy(final InputStream input, final OutputStream output, final int count) throws IOException { if (count == ALL) { return copy(input, output); } int numToRead = count; byte[] buffer = new byte[numToRead]; int totalRead = ZERO; int read; while (numToRead > ZERO) { read = input.read(buffer, ZERO, bufferSize(numToRead)); if (read == NEGATIVE_ONE) { break; } output.write(buffer, ZERO, read); numToRead = numToRead - read; totalRead = totalRead + read; } output.flush(); return totalRead; }