/** Recycle the output buffer. */ public void recycle() { state = INITIAL_STATE; // If usage of mark made the buffer too big, reallocate it if (cb.getChars().length > size) { cb = new CharChunk(size); cb.setLimit(size); cb.setOptimizedWrite(false); cb.setCharInputChannel(this); cb.setCharOutputChannel(this); } else { cb.recycle(); } markPos = -1; bb.recycle(); closed = false; if (conv != null) { conv.recycle(); } gotEnc = false; enc = null; }
/** * Alternate constructor which allows specifying the initial buffer size. * * @param size Buffer size to use */ public InputBuffer(int size) { this.size = size; bb = new ByteChunk(size); bb.setLimit(size); bb.setByteInputChannel(this); cb = new CharChunk(size); cb.setLimit(size); cb.setOptimizedWrite(false); cb.setCharInputChannel(this); cb.setCharOutputChannel(this); }
@Override public void mark(int readAheadLimit) throws IOException { if (closed) { throw new IOException(sm.getString("inputBuffer.streamClosed")); } if (cb.getLength() <= 0) { cb.setOffset(0); cb.setEnd(0); } else { if ((cb.getBuffer().length > (2 * size)) && (cb.getLength()) < (cb.getStart())) { System.arraycopy(cb.getBuffer(), cb.getStart(), cb.getBuffer(), 0, cb.getLength()); cb.setEnd(cb.getLength()); cb.setOffset(0); } } cb.setLimit(cb.getStart() + readAheadLimit + size); markPos = cb.getStart(); }