/** Creates a new fast buffered output stream by wrapping a given output stream with a given buffer size. * * @param os an output stream to wrap. * @param bufferSize the size in bytes of the internal buffer. */ public FastBufferedOutputStream(final OutputStream os, final int bufferSize) { this(os, new byte[ensureBufferSize(bufferSize)]); }
/** Creates a new fast buffered output stream by wrapping a given output stream with a given buffer. * * @param os an output stream to wrap. * @param buffer a buffer of positive length. */ public FastBufferedOutputStream(final OutputStream os, final byte[] buffer) { this.os = os; ensureBufferSize(buffer.length); this.buffer = buffer; avail = buffer.length; if (os instanceof RepositionableStream) repositionableStream = (RepositionableStream)os; if (os instanceof MeasurableStream) measurableStream = (MeasurableStream)os; if (repositionableStream == null) { try { fileChannel = (FileChannel)(os.getClass().getMethod("getChannel", new Class<?>[] {})).invoke(os); } catch(IllegalAccessException e) {} catch(IllegalArgumentException e) {} catch(NoSuchMethodException e) {} catch(java.lang.reflect.InvocationTargetException e) {} catch(ClassCastException e) {} } }