com.epam.common.utils
Class ByteBuffer

java.lang.Object
  extended by com.epam.common.utils.ByteBuffer

public final class ByteBuffer
extends Object

The byte buffer helper class.


Field Summary
static int NO_GROWTH_INCREMENT
           
 
Constructor Summary
ByteBuffer()
          Creates the ByteBuffer with allocated byte buffer.
ByteBuffer(int length)
          Creates the ByteBuffer with allocated byte buffer.
ByteBuffer(int length, boolean useNIOBuffer)
           
ByteBuffer(int length, int growIncrement)
           
ByteBuffer(int size, int growIncrement, boolean useNIOBuffer)
           
 
Method Summary
 ByteBuffer add(byte b)
          Adds byte to buffer.
 ByteBuffer add(byte[] array)
          Appends the array argument to internal buffer.
 ByteBuffer add(byte[] array, int start, int len)
          Appends the array argument to internal buffer.
 ByteBuffer add(char b)
          Adds char to buffer.
 ByteBuffer add(long value)
           
 ByteBuffer add(String s)
           
static int formatInt(long value, byte[] buffer, int offset)
           
static int formatIntLength(long value)
           
 byte[] getBulk()
           
 byte[] getByteArray()
          Gets internal byte buffer.
 int getLength()
          Gets buffer length.
 ByteBuffer getNioBuffer()
           
 int getOffset()
          Gets buffer offset.
 byte[] getSubArray(int start, int length)
           
 ByteBuffer getSubBuffer(int start, int length)
           
 void increaseBuffer(int incNumOfBytes)
          Increases the buffer.
 boolean isAvailable(int numOfBytes)
          Checks if buffer has a numOfBytes.
 boolean isEmpty()
           
 void resetBuffer()
          Resets the buffer.
 void setOffset(int offset)
          Sets offset of buffer.
static ByteBuffer wrapBuffer(byte[] buffer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_GROWTH_INCREMENT

public static final int NO_GROWTH_INCREMENT
See Also:
Constant Field Values
Constructor Detail

ByteBuffer

public ByteBuffer()
Creates the ByteBuffer with allocated byte buffer.
The default buffer length if 1024 bytes.


ByteBuffer

public ByteBuffer(int length)
Creates the ByteBuffer with allocated byte buffer.

Parameters:
length - allocated buffer length

ByteBuffer

public ByteBuffer(int length,
                  boolean useNIOBuffer)

ByteBuffer

public ByteBuffer(int length,
                  int growIncrement)

ByteBuffer

public ByteBuffer(int size,
                  int growIncrement,
                  boolean useNIOBuffer)
Parameters:
size - buffer size in bytes
growIncrement - grow size in bytes
useNIOBuffer -
Method Detail

getNioBuffer

public ByteBuffer getNioBuffer()

resetBuffer

public void resetBuffer()
Resets the buffer.


add

public ByteBuffer add(byte[] array)
Appends the array argument to internal buffer.

Returns:
a reference to this object.

formatIntLength

public static int formatIntLength(long value)

formatInt

public static int formatInt(long value,
                            byte[] buffer,
                            int offset)

add

public ByteBuffer add(long value)

add

public ByteBuffer add(String s)

add

public ByteBuffer add(byte[] array,
                      int start,
                      int len)
Appends the array argument to internal buffer.

Returns:
a reference to this object.

increaseBuffer

public void increaseBuffer(int incNumOfBytes)
Increases the buffer.

Parameters:
incNumOfBytes - the number of bytes

setOffset

public void setOffset(int offset)
Sets offset of buffer.

Parameters:
offset - the new offset

getOffset

public int getOffset()
Gets buffer offset.


add

public ByteBuffer add(byte b)
Adds byte to buffer.

Parameters:
b - a byte

add

public ByteBuffer add(char b)
Adds char to buffer.

Parameters:
b - a char

getByteArray

public byte[] getByteArray()
Gets internal byte buffer.


getLength

public int getLength()
Gets buffer length.

Returns:
int length

isAvailable

public boolean isAvailable(int numOfBytes)
Checks if buffer has a numOfBytes.

Parameters:
numOfBytes - the requested space
Returns:
boolean true if has

getBulk

public byte[] getBulk()

isEmpty

public boolean isEmpty()

wrapBuffer

public static ByteBuffer wrapBuffer(byte[] buffer)

getSubBuffer

public ByteBuffer getSubBuffer(int start,
                               int length)

getSubArray

public byte[] getSubArray(int start,
                          int length)


Copyright © 2000-2014 EPAM Systems. All Rights Reserved.