net.sf.dexterim.oscar
Class OscarByteBuffer

java.lang.Object
  extended bynet.sf.dexterim.oscar.OscarByteBuffer
Direct Known Subclasses:
BufferArray

public abstract class OscarByteBuffer
extends java.lang.Object

Author:
Christoph Walcher

Constructor Summary
OscarByteBuffer()
           
 
Method Summary
static OscarByteBuffer allocate(int size)
          Allocates a static OscarByteBuffer with size size.
abstract  byte[] array()
          Returns the underlying data structure as byte array.
static OscarByteBuffer dynamic()
          Allocates a dynamic OscarByteBuffer.
abstract  int fill()
          Returns last position with data available
abstract  int getByte()
          Returns byte at current position.
abstract  DWord getDWord()
          Returns the data chunk at current position as DWord.
abstract  Word getWord()
          Returns the data chunk at current position as Word.
abstract  int position()
          Returns the current position.
abstract  int position(int position)
          Sets the position to newPosition and returns the old position.
abstract  int size()
          Returns the current size of the buffer.
abstract  byte[] slice()
          Returns the underlying data structure as byte array.
abstract  int strip()
          Strips the OscarByteBuffer by setting the fill to the current position.
static OscarByteBuffer wrap(byte[] data)
          Creates a new OscarByteBuffer instance that wraps the data byte[]
static OscarByteBuffer wrapDynamic(byte[] data)
          Allocates a dynamic OscarByteBuffer that wraps a byte[] and sets position() to data.length.
abstract  OscarByteBuffer write(byte source)
          Writes a byte value at current position.
abstract  OscarByteBuffer write(ByteBased source)
          Writes a ByteBased value at current position.
abstract  OscarByteBuffer write(OscarByteBuffer source)
          Writes a OscarByteBuffer value at current position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OscarByteBuffer

public OscarByteBuffer()
Method Detail

position

public abstract int position(int position)
Sets the position to newPosition and returns the old position. May throw an ArrayIndexOutOfBounds exception if position was set beyond the end of the underlying data structure.

Parameters:
position - new Position
Returns:
old Position

position

public abstract int position()
Returns the current position.

Returns:
current Position in Buffer

size

public abstract int size()
Returns the current size of the buffer. For dynamic Buffers this size may change after calling writer or position.

Returns:
current size

fill

public abstract int fill()
Returns last position with data available

Returns:
fill

strip

public abstract int strip()
Strips the OscarByteBuffer by setting the fill to the current position.

Returns:
current Position

getWord

public abstract Word getWord()
Returns the data chunk at current position as Word. Throws an ArrayIndexOutOfBounds Exception if not enough bytes are present in Buffer to construct a Word value.

Returns:
Word value at current position

getDWord

public abstract DWord getDWord()
Returns the data chunk at current position as DWord. Throws an ArrayIndexOutOfBounds Exception if not enough bytes are present in Buffer to construct a DWord value.

Returns:
DWord value at current position

getByte

public abstract int getByte()
Returns byte at current position. Throws an ArrayIndexOutOfBounds Exception if position() >= size()

Returns:
byte value at current position

write

public abstract OscarByteBuffer write(ByteBased source)
Writes a ByteBased value at current position. This may throw an ArrayIndexOutOfBounds Exception for allocated buffers if size() <= position() + new DWord().getLength(). Method returns this to be used in command chaining.

Parameters:
source - value to write to buffer
Returns:
this

write

public abstract OscarByteBuffer write(byte source)
Writes a byte value at current position. This may throw an ArrayIndexOutOfBounds Exception for allocated buffers if size() <= position() + 1. Method returns this to be used in command chaining.

Parameters:
source - value to write to buffer
Returns:
this

write

public abstract OscarByteBuffer write(OscarByteBuffer source)
Writes a OscarByteBuffer value at current position. This may throw an ArrayIndexOutOfBounds Exception for allocated buffers if size() <= position() + source.slice().length(). Method returns this to be used in command chaining.

Parameters:
source - value to write to buffer
Returns:
this

array

public abstract byte[] array()
Returns the underlying data structure as byte array. This method does not clone the byte array nor tailor the length of the underlying byte array. Changes commited to this array will affect data in OscarByteBuffer. This method is considered to be more performant than slice().

Returns:
byte array

slice

public abstract byte[] slice()
Returns the underlying data structure as byte array. This method returns a new instance of byte[] by calling Systen.arrayCopy or some other mechanism and tailor it's length to position()

Returns:
byte array

wrap

public static OscarByteBuffer wrap(byte[] data)
Creates a new OscarByteBuffer instance that wraps the data byte[]

Parameters:
data - byte[] to wrap
Returns:
data wraped into OscarByteBuffer

allocate

public static OscarByteBuffer allocate(int size)
Allocates a static OscarByteBuffer with size size.

Parameters:
size - size of the new OscarByteBuffer
Returns:
OscarByteBuffer with size size

dynamic

public static OscarByteBuffer dynamic()
Allocates a dynamic OscarByteBuffer. This Buffer will grow as you write data into it.

Returns:
OscarByteBuffer

wrapDynamic

public static OscarByteBuffer wrapDynamic(byte[] data)
Allocates a dynamic OscarByteBuffer that wraps a byte[] and sets position() to data.length.

Parameters:
data - byte[] to wrap
Returns:
OscarByteBuffer


Copyright © 2003-2004 Dexter IM Team. All Rights Reserved.