net.sf.asyncobjects.io
Class ByteQueue

java.lang.Object
  extended by net.sf.asyncobjects.io.ByteQueue

public final class ByteQueue
extends Object

actually JDK 1.4 buffer should be used instead of this one, but there is an intention to make sources compatible with 1.3 and personal profile platform. Also there is only one kind of buffer to simplify compatibility issues. This class is not thread safe.

Author:
const

Constructor Summary
ByteQueue(int size)
          size of buffer
 
Method Summary
 int availableForGet()
          avaiable for get
 int availableForPut()
           
 int capacity()
           
 void clear()
          clear queue from all elements
 int get(byte[] buffer)
          Get bytes into array
 int get(byte[] buffer, int start, int length)
          Get bytes into array
 boolean isEmpty()
           
 boolean isFull()
           
 int peek(int offset, byte[] buffer, int start, int length)
          Peek bytes
 int put(byte[] buffer)
          Peek bytes
 int put(byte[] buffer, int start, int length)
          Peek bytes
 void skip(int n)
          consume some bytes in buffer
 int transferFrom(ByteQueue buffer)
          transfer data from one buffer to another, this method gets data from first buffer by method gets, so data is consumed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteQueue

public ByteQueue(int size)
size of buffer

Parameters:
size - buffer size
Method Detail

availableForGet

public int availableForGet()
avaiable for get

Returns:
amount of bytes avaiable for get

availableForPut

public int availableForPut()
Returns:
amount of bytes available for put

skip

public void skip(int n)
consume some bytes in buffer

Parameters:
n - amount of bytes to consume

get

public int get(byte[] buffer)
Get bytes into array

Parameters:
buffer - an target array
Returns:
amount of received bytes

get

public int get(byte[] buffer,
               int start,
               int length)
Get bytes into array

Parameters:
buffer - an target array
start - start position in target array
length - maximum amount of bytes to copy
Returns:
amount of received bytes

peek

public int peek(int offset,
                byte[] buffer,
                int start,
                int length)
Peek bytes

Parameters:
offset - a position inside data
buffer - a target buffer
start - a start position in the buffer
length - max amount to get
Returns:
amount of actually recived data

put

public int put(byte[] buffer)
Peek bytes

Parameters:
buffer - a target buffer
Returns:
amount of actually recived data

put

public int put(byte[] buffer,
               int start,
               int length)
Peek bytes

Parameters:
buffer - a target buffer
start - a start position in the buffer
length - max amount to get
Returns:
amount of actually recived data

transferFrom

public int transferFrom(ByteQueue buffer)
transfer data from one buffer to another, this method gets data from first buffer by method gets, so data is consumed.

Parameters:
buffer - source buffer
Returns:
amount of bytes put into buffer

isEmpty

public boolean isEmpty()
Returns:
true if queue is empty

isFull

public boolean isFull()
Returns:
true if queue is full

clear

public void clear()
clear queue from all elements


capacity

public int capacity()
Returns:
capacity of bytequeue


Copyright © 2002-2007 Constantine Plotnikov. All Rights Reserved.