/** * Extracts buffered data into the provided byte[] array, starting at position bPos, up to a maximum of bAvail * bytes. Returns how many bytes were actually extracted. * <p> * Package protected for access from I/O streams. * * @param b * byte[] array to extract the buffered data into. * @param bPos * position in byte[] array to start extraction at. * @param bAvail * amount of bytes we're allowed to extract. We may extract fewer (if fewer are available). * @param context * the context to be used * @return The number of bytes successfully extracted into the provided byte[] array. */ int readResults(final byte[] b, final int bPos, final int bAvail, final Context context) { if (context.buffer != null) { final int len = Math.min(available(context), bAvail); System.arraycopy(context.buffer, context.readPos, b, bPos, len); context.readPos += len; if (context.readPos >= context.pos) { context.buffer = null; // so hasData() will return false, and this method can return -1 } return len; } return context.eof ? EOF : 0; }
/** * Flushes this output stream and forces any buffered output bytes to be written out to the stream. If propagate is * true, the wrapped stream will also be flushed. * * @param propagate * boolean flag to indicate whether the wrapped OutputStream should also be flushed. * @throws IOException * if an I/O error occurs. */ private void flush(final boolean propagate) throws IOException { final int avail = baseNCodec.available(context); if (avail > 0) { final byte[] buf = new byte[avail]; final int c = baseNCodec.readResults(buf, 0, avail, context); if (c > 0) { out.write(buf, 0, c); } } if (propagate) { out.flush(); } }
/** * Extracts buffered data into the provided byte[] array, starting at position bPos, up to a maximum of bAvail * bytes. Returns how many bytes were actually extracted. * <p> * Package protected for access from I/O streams. * * @param b * byte[] array to extract the buffered data into. * @param bPos * position in byte[] array to start extraction at. * @param bAvail * amount of bytes we're allowed to extract. We may extract fewer (if fewer are available). * @param context * the context to be used * @return The number of bytes successfully extracted into the provided byte[] array. */ int readResults(final byte[] b, final int bPos, final int bAvail, final Context context) { if (context.buffer != null) { final int len = Math.min(available(context), bAvail); System.arraycopy(context.buffer, context.readPos, b, bPos, len); context.readPos += len; if (context.readPos >= context.pos) { context.buffer = null; // so hasData() will return false, and this method can return -1 } return len; } return context.eof ? EOF : 0; }
/** * Extracts buffered data into the provided byte[] array, starting at position bPos, up to a maximum of bAvail * bytes. Returns how many bytes were actually extracted. * <p> * Package protected for access from I/O streams. * * @param b * byte[] array to extract the buffered data into. * @param bPos * position in byte[] array to start extraction at. * @param bAvail * amount of bytes we're allowed to extract. We may extract fewer (if fewer are available). * @param context * the context to be used * @return The number of bytes successfully extracted into the provided byte[] array. */ int readResults(final byte[] b, final int bPos, final int bAvail, final Context context) { if (context.buffer != null) { final int len = Math.min(available(context), bAvail); System.arraycopy(context.buffer, context.readPos, b, bPos, len); context.readPos += len; if (context.readPos >= context.pos) { context.buffer = null; // so hasData() will return false, and this method can return -1 } return len; } return context.eof ? EOF : 0; }
/** * Extracts buffered data into the provided byte[] array, starting at position bPos, up to a maximum of bAvail * bytes. Returns how many bytes were actually extracted. * <p> * Package protected for access from I/O streams. * * @param b * byte[] array to extract the buffered data into. * @param bPos * position in byte[] array to start extraction at. * @param bAvail * amount of bytes we're allowed to extract. We may extract fewer (if fewer are available). * @param context * the context to be used * @return The number of bytes successfully extracted into the provided byte[] array. */ int readResults(final byte[] b, final int bPos, final int bAvail, final Context context) { if (context.buffer != null) { final int len = Math.min(available(context), bAvail); System.arraycopy(context.buffer, context.readPos, b, bPos, len); context.readPos += len; if (context.readPos >= context.pos) { context.buffer = null; // so hasData() will return false, and this method can return -1 } return len; } return context.eof ? EOF : 0; }
/** * Extracts buffered data into the provided byte[] array, starting at position bPos, up to a maximum of bAvail * bytes. Returns how many bytes were actually extracted. * <p> * Package protected for access from I/O streams. * * @param b * byte[] array to extract the buffered data into. * @param bPos * position in byte[] array to start extraction at. * @param bAvail * amount of bytes we're allowed to extract. We may extract fewer (if fewer are available). * @param context * the context to be used * @return The number of bytes successfully extracted into the provided byte[] array. */ int readResults(final byte[] b, final int bPos, final int bAvail, final Context context) { if (context.buffer != null) { final int len = Math.min(available(context), bAvail); System.arraycopy(context.buffer, context.readPos, b, bPos, len); context.readPos += len; if (context.readPos >= context.pos) { context.buffer = null; // so hasData() will return false, and this method can return -1 } return len; } return context.eof ? EOF : 0; }
/** * Extracts buffered data into the provided byte[] array, starting at position bPos, up to a maximum of bAvail * bytes. Returns how many bytes were actually extracted. * <p> * Package protected for access from I/O streams. * * @param b * byte[] array to extract the buffered data into. * @param bPos * position in byte[] array to start extraction at. * @param bAvail * amount of bytes we're allowed to extract. We may extract fewer (if fewer are available). * @param context * the context to be used * @return The number of bytes successfully extracted into the provided byte[] array. */ int readResults(final byte[] b, final int bPos, final int bAvail, final Context context) { if (context.buffer != null) { final int len = Math.min(available(context), bAvail); System.arraycopy(context.buffer, context.readPos, b, bPos, len); context.readPos += len; if (context.readPos >= context.pos) { context.buffer = null; // so hasData() will return false, and this method can return -1 } return len; } return context.eof ? EOF : 0; }
/** * Flushes this output stream and forces any buffered output bytes to be written out to the stream. If propagate is * true, the wrapped stream will also be flushed. * * @param propagate * boolean flag to indicate whether the wrapped OutputStream should also be flushed. * @throws IOException * if an I/O error occurs. */ private void flush(final boolean propagate) throws IOException { final int avail = baseNCodec.available(context); if (avail > 0) { final byte[] buf = new byte[avail]; final int c = baseNCodec.readResults(buf, 0, avail, context); if (c > 0) { out.write(buf, 0, c); } } if (propagate) { out.flush(); } }
/** * Flushes this output stream and forces any buffered output bytes to be written out to the stream. If propagate is * true, the wrapped stream will also be flushed. * * @param propagate * boolean flag to indicate whether the wrapped OutputStream should also be flushed. * @throws IOException * if an I/O error occurs. */ private void flush(final boolean propagate) throws IOException { final int avail = baseNCodec.available(context); if (avail > 0) { final byte[] buf = new byte[avail]; final int c = baseNCodec.readResults(buf, 0, avail, context); if (c > 0) { out.write(buf, 0, c); } } if (propagate) { out.flush(); } }
/** * Flushes this output stream and forces any buffered output bytes to be written out to the stream. If propagate is * true, the wrapped stream will also be flushed. * * @param propagate * boolean flag to indicate whether the wrapped OutputStream should also be flushed. * @throws IOException * if an I/O error occurs. */ private void flush(final boolean propagate) throws IOException { final int avail = baseNCodec.available(context); if (avail > 0) { final byte[] buf = new byte[avail]; final int c = baseNCodec.readResults(buf, 0, avail, context); if (c > 0) { out.write(buf, 0, c); } } if (propagate) { out.flush(); } }
/** * Flushes this output stream and forces any buffered output bytes to be written out to the stream. If propagate is * true, the wrapped stream will also be flushed. * * @param propagate * boolean flag to indicate whether the wrapped OutputStream should also be flushed. * @throws IOException * if an I/O error occurs. */ private void flush(final boolean propagate) throws IOException { final int avail = baseNCodec.available(context); if (avail > 0) { final byte[] buf = new byte[avail]; final int c = baseNCodec.readResults(buf, 0, avail, context); if (c > 0) { out.write(buf, 0, c); } } if (propagate) { out.flush(); } }
/** * Flushes this output stream and forces any buffered output bytes to be written out to the stream. If propagate is * true, the wrapped stream will also be flushed. * * @param propagate * boolean flag to indicate whether the wrapped OutputStream should also be flushed. * @throws IOException * if an I/O error occurs. */ private void flush(final boolean propagate) throws IOException { final int avail = baseNCodec.available(context); if (avail > 0) { final byte[] buf = new byte[avail]; final int c = baseNCodec.readResults(buf, 0, avail, context); if (c > 0) { out.write(buf, 0, c); } } if (propagate) { out.flush(); } }