示例#1
0
  /** 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;
  }
示例#2
0
  /**
   * 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);
  }
示例#3
0
  @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();
  }