SRJRCFrames
v0.1.296

de.schwarzrot.data.support
Class OffsetBuffer

java.lang.Object
  extended by de.schwarzrot.data.support.OffsetBuffer

public class OffsetBuffer
extends Object

is a buffer implementation, that can be used as a record base to interpret binary data from an arbitrary byte-buffer. This buffer can be put anywhere at the byte-buffer and (opposed to the java standard class ByteBuffer) it does not care about data, that is before offset or after offset+size - so it can be used as a little viewport to a huge byte-buffer.

The OffsetBuffer can be moved over the arbitrary byte-buffer just by changing the offset and the position of the getters and setters are relative to the new offset - and so transparent to the user.

Neither the size, nor the abitrary byte-buffer can be changed.

All methods, that normally don't return a value return the instance to relax chaining of commands.

Author:
Reinhard Mantey

Constructor Summary
OffsetBuffer(byte[] buf, int offset, int size)
           
 
Method Summary
protected  int checkPos(int pos)
           
 int get(int pos)
           
 int get3ByteInt(int pos)
           
 byte[] getBytes(int pos, int size)
           
 int getInt(int pos)
           
 int getShort(int pos)
           
 int offset()
           
 OffsetBuffer offset(int newOffset)
          moves the record (in arbitrary byte buffer) to interpret a different buffer portion as the same record.
 ByteOrder order()
           
 OffsetBuffer order(ByteOrder order)
           
 OffsetBuffer put(int pos, byte value)
           
 OffsetBuffer put3ByteInt(int pos, int value)
           
 OffsetBuffer putBytes(int pos, byte[] content)
           
 OffsetBuffer putInt(int pos, int value)
           
 OffsetBuffer putShort(int pos, short value)
           
 int rel2abs(int pos)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OffsetBuffer

public OffsetBuffer(byte[] buf,
                    int offset,
                    int size)
Method Detail

get

public final int get(int pos)

get3ByteInt

public final int get3ByteInt(int pos)

getBytes

public final byte[] getBytes(int pos,
                             int size)

getInt

public final int getInt(int pos)

getShort

public final int getShort(int pos)

offset

public final int offset()
Returns:
the offset of the record (from arbitrary byte buffer) this buffer is base of.

offset

public final OffsetBuffer offset(int newOffset)
moves the record (in arbitrary byte buffer) to interpret a different buffer portion as the same record.

Parameters:
newOffset - new start position of the record (from arbitrary byte buffer) this buffer is base of.
Returns:
the instance of the OffsetBuffer, that has been moved to the new offset.

order

public final ByteOrder order()

order

public final OffsetBuffer order(ByteOrder order)

put

public final OffsetBuffer put(int pos,
                              byte value)

put3ByteInt

public final OffsetBuffer put3ByteInt(int pos,
                                      int value)

putBytes

public final OffsetBuffer putBytes(int pos,
                                   byte[] content)

putInt

public final OffsetBuffer putInt(int pos,
                                 int value)

putShort

public final OffsetBuffer putShort(int pos,
                                   short value)

rel2abs

public final int rel2abs(int pos)

checkPos

protected final int checkPos(int pos)

SRJRCFrames
v0.1.296

hosted at
Find SRJRCFrames at SourceForge.net. Fast, secure and free:
           Open Source Software download
Submit a bug or request a feature

SRJRCFrames is published according to the GNU General Public License
Copyright 2005-2012 Reinhard Mantey - some rights reserved.