Ejemplo n.º 1
0
  public void push(byte b) {
    if (room() == 0) expand();

    queue[tail] = b;

    if (head == -1) head = 0;
    tail = (tail + 1) % queue.length;
    size++;
  }
Ejemplo n.º 2
0
  public void push(byte[] b, int pos, int length) {
    if (length == 0) return;

    while (room() < length) expand();

    int tailLength = queue.length - tail;
    if (tailLength > length) System.arraycopy(b, pos, queue, tail, length);
    else System.arraycopy(b, pos, queue, tail, tailLength);

    if (length > tailLength) System.arraycopy(b, tailLength + pos, queue, 0, length - tailLength);

    if (head == -1) head = 0;
    tail = (tail + length) % queue.length;
    size += length;
  }
Ejemplo n.º 3
0
  public void read(InputStream in, int length) throws IOException {
    if (length == 0) return;

    while (room() < length) expand();

    int tailLength = queue.length - tail;
    if (tailLength > length) readImpl(in, tail, length);
    else readImpl(in, tail, tailLength);

    if (length > tailLength) readImpl(in, 0, length - tailLength);

    if (head == -1) head = 0;
    tail = (tail + length) % queue.length;
    size += length;
  }
Ejemplo n.º 4
0
  public void push(ByteBuffer source) {
    int length = source.remaining();
    if (length == 0) return;

    while (room() < length) expand();

    int tailLength = queue.length - tail;
    if (tailLength > length) source.get(queue, tail, length);
    else source.get(queue, tail, tailLength);

    if (length > tailLength) source.get(queue, 0, length - tailLength);

    if (head == -1) head = 0;
    tail = (tail + length) % queue.length;
    size += length;
  }