Encapsulates binary payload that can be manipulated on the octet (byte) level. More...
Public Member Functions | |
OctetBuffer | slice () |
Slices buffer. | |
byte[] | getStore () |
Returns internal byte[] store. | |
int | getStoreSize () |
Returns internal byte[] store. | |
int | getPosition () |
Gets current position. | |
int | getFreeSpace () |
Returns remaining space. | |
boolean | hasFreeSpace () |
Returns true if there is free space in the store. | |
short | getShort () |
Gets primitive 'short' from the slice offset in the store. | |
short | getShort (int offset) |
Gets primitive 'short' from the offset in the store. | |
void | putShort (short value) |
Puts primitive 'short' at the slice offset in the store. | |
void | putShort (int offset, short value) |
Puts primitive 'short' at the slice offset in the store. | |
int | getInt () |
Gets primitive 'int' from the slice offset in the store. | |
void | putInt (int value) |
Puts primitive 'int' at the slice offset in the store. | |
byte | get () |
Gets primitive 'byte' from the slice offset in the store. | |
void | put (byte value) |
Puts primitive 'byte' from the slice offset in the store. | |
void | put (byte[] array) |
Puts byte[] array at the slice offset in the store. | |
void | get (byte[] array) |
Gets byte[] array from the slice offset in the store. | |
void | putChar (char value) |
Puts primitive 'char' at the slice offset in the store. | |
void | putChar (int offset, char value) |
Puts primitive 'char' at the slice offset in the store. | |
char | getChar () |
Gets primitive 'char' from the slice offset in the store. | |
char | getChar (int offset) |
Gets primitive 'char' from the slice offset in the store. | |
Static Public Member Functions | |
static OctetBuffer | allocate (int size) |
Allocates buffer. | |
static OctetBuffer | wrap (byte[] bs) |
Wraps existing byte[] array. | |
static int | toInt (byte b) |
Converts a 'byte' to an 'int'. | |
Private Attributes | |
byte[] | store = null |
The octet storage. | |
int | position = 0 |
Position index. | |
int | sliceOffset = 0 |
Offset into backing store to enable slicing. |
Encapsulates binary payload that can be manipulated on the octet (byte) level.
Definition at line 7 of file OctetBuffer.java.
static OctetBuffer utils.OctetBuffer.allocate | ( | int | size ) | [static] |
Allocates buffer.
Definition at line 27 of file OctetBuffer.java.
References utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
Referenced by audio.AudioInterfacePCM.initializeRingerSamples(), and protocol.ProtocolDataUnit.sendPayload().
{ OctetBuffer bb = new OctetBuffer (); bb.store = new byte[ size ]; bb.position = 0; bb.sliceOffset = 0; return bb; }
void utils.OctetBuffer.get | ( | byte[] | array ) |
Gets byte[] array from the slice offset in the store.
Definition at line 234 of file OctetBuffer.java.
References utils.OctetBuffer.getFreeSpace(), utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
{ int l = getFreeSpace(); if (l > array.length) { l = array.length; } System.arraycopy(store, sliceOffset + position, array, 0, l); position += l; }
byte utils.OctetBuffer.get | ( | ) |
Gets primitive 'byte' from the slice offset in the store.
Definition at line 197 of file OctetBuffer.java.
References utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
Referenced by protocol.VoicePDU.onArrivedPDU(), and protocol.ProtocolDataUnit.ProtocolDataUnit().
{ if (sliceOffset + position + 1 > store.length) { throw new IndexOutOfBoundsException(); } return store[sliceOffset + position++]; }
char utils.OctetBuffer.getChar | ( | ) |
Gets primitive 'char' from the slice offset in the store.
Definition at line 273 of file OctetBuffer.java.
References utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
{ if (sliceOffset + position + 2 > store.length) { throw new IndexOutOfBoundsException(); } short s = (short) ( (store[sliceOffset + position] << 8) + (store[sliceOffset + position + 1] & 0xFF)); position += 2; return (char) s; }
char utils.OctetBuffer.getChar | ( | int | offset ) |
Gets primitive 'char' from the slice offset in the store.
Definition at line 287 of file OctetBuffer.java.
References utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
{ if (sliceOffset + offset + 2 > store.length) { throw new IndexOutOfBoundsException(); } short s = (short) ( (store[sliceOffset + offset] << 8) + (store[sliceOffset + offset + 1] & 0xFF)); return (char) s; }
int utils.OctetBuffer.getFreeSpace | ( | ) |
Returns remaining space.
Definition at line 95 of file OctetBuffer.java.
References utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
Referenced by utils.OctetBuffer.get().
{ return store.length - sliceOffset - position; }
int utils.OctetBuffer.getInt | ( | ) |
Gets primitive 'int' from the slice offset in the store.
Definition at line 165 of file OctetBuffer.java.
References utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
Referenced by protocol.ProtocolDataUnit.ProtocolDataUnit().
{ if (sliceOffset + position + 4 > store.length) { throw new IndexOutOfBoundsException(); } int i = (store[sliceOffset + position] << 24) + ( (store[sliceOffset + position + 1] & 0xFF) << 16) + ( (store[sliceOffset + position + 2] & 0xFF) << 8) + (store[sliceOffset + position + 3] & 0xFF); position += 4; return i; }
int utils.OctetBuffer.getPosition | ( | ) |
Gets current position.
Definition at line 87 of file OctetBuffer.java.
References utils.OctetBuffer.position.
Referenced by protocol.DatagramChannel.send().
{ return position; }
short utils.OctetBuffer.getShort | ( | ) |
Gets primitive 'short' from the slice offset in the store.
Definition at line 112 of file OctetBuffer.java.
References utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
Referenced by audio.AudioCodecUlaw.convertFromPCM(), audio.AudioCodecAlaw.convertFromPCM(), protocol.ProtocolDataUnit.ProtocolDataUnit(), and audio.AudioInterfacePCM.resample().
{ if (sliceOffset + position + 2 > store.length) { throw new IndexOutOfBoundsException(); } short s = (short) ( (store[sliceOffset + position] << 8) + (store[sliceOffset + position + 1] & 0xFF)); position += 2; return s; }
short utils.OctetBuffer.getShort | ( | int | offset ) |
Gets primitive 'short' from the offset in the store.
Definition at line 126 of file OctetBuffer.java.
References utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
{ if (sliceOffset + offset + 2 > store.length) { throw new IndexOutOfBoundsException(); } short s = (short) ( (store[sliceOffset + offset] << 8) + (store[sliceOffset + offset + 1] & 0xFF)); return s; }
byte [] utils.OctetBuffer.getStore | ( | ) |
Returns internal byte[] store.
Definition at line 63 of file OctetBuffer.java.
References utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
Referenced by audio.AudioInterfacePCM.initializeRingerSamples(), and protocol.DatagramChannel.send().
{ if ( sliceOffset != 0 ) { throw new java.lang.IllegalStateException (); } return store; }
int utils.OctetBuffer.getStoreSize | ( | ) |
Returns internal byte[] store.
Definition at line 75 of file OctetBuffer.java.
References utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
{ if ( sliceOffset != 0 ) { throw new java.lang.IllegalStateException (); } return store.length; }
boolean utils.OctetBuffer.hasFreeSpace | ( | ) |
Returns true if there is free space in the store.
Definition at line 103 of file OctetBuffer.java.
References utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
{ return sliceOffset + position < store.length; }
void utils.OctetBuffer.put | ( | byte | value ) |
Puts primitive 'byte' from the slice offset in the store.
Definition at line 208 of file OctetBuffer.java.
References utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
Referenced by protocol.ProtocolDataUnit.sendPayload().
void utils.OctetBuffer.put | ( | byte[] | array ) |
Puts byte[] array at the slice offset in the store.
Definition at line 222 of file OctetBuffer.java.
References utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
{ if (sliceOffset + position + array.length > store.length) { throw new IndexOutOfBoundsException(); } System.arraycopy(array, 0, store, sliceOffset + position, array.length); position += array.length; }
void utils.OctetBuffer.putChar | ( | char | value ) |
Puts primitive 'char' at the slice offset in the store.
Definition at line 249 of file OctetBuffer.java.
References utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
Referenced by protocol.ProtocolDataUnit.sendPayload().
{ if (sliceOffset + position + 2 > store.length) { throw new IndexOutOfBoundsException(); } store[sliceOffset + position++] = (byte) ( ( (short) value) >> 8); store[sliceOffset + position++] = (byte) value; }
void utils.OctetBuffer.putChar | ( | int | offset, |
char | value | ||
) |
Puts primitive 'char' at the slice offset in the store.
Definition at line 261 of file OctetBuffer.java.
References utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
{ if (sliceOffset + offset + 2 > store.length) { throw new IndexOutOfBoundsException(); } store[sliceOffset + offset] = (byte) ( ( (short) value) >> 8); store[sliceOffset + offset + 1] = (byte) value; }
void utils.OctetBuffer.putInt | ( | int | value ) |
Puts primitive 'int' at the slice offset in the store.
Definition at line 181 of file OctetBuffer.java.
References utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
Referenced by protocol.ProtocolDataUnit.sendPayload().
{ if (sliceOffset + position + 4 > store.length) { throw new IndexOutOfBoundsException(); } store[sliceOffset + position++] = (byte) (value >> 24); store[sliceOffset + position++] = (byte) ( (value >> 16) & 0xff); store[sliceOffset + position++] = (byte) ( (value >> 8) & 0xff); store[sliceOffset + position++] = (byte) (value & 0xff); }
void utils.OctetBuffer.putShort | ( | int | offset, |
short | value | ||
) |
Puts primitive 'short' at the slice offset in the store.
Definition at line 151 of file OctetBuffer.java.
References utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
{ if (sliceOffset + offset + 2 > store.length) { throw new IndexOutOfBoundsException(); } store[sliceOffset + offset++] = (byte) (value >> 8); store[sliceOffset + offset++] = (byte) (value & 0xff); }
void utils.OctetBuffer.putShort | ( | short | value ) |
Puts primitive 'short' at the slice offset in the store.
Definition at line 139 of file OctetBuffer.java.
References utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
Referenced by audio.AudioCodecUlaw.convertToPCM(), audio.AudioCodecAlaw.convertToPCM(), audio.AudioInterfacePCM.initializeRingerSamples(), and audio.AudioInterfacePCM.resample().
{ if (sliceOffset + position + 2 > store.length) { throw new IndexOutOfBoundsException(); } store[sliceOffset + position++] = (byte) (value >> 8); store[sliceOffset + position++] = (byte) (value & 0xff); }
OctetBuffer utils.OctetBuffer.slice | ( | ) |
Slices buffer.
Definition at line 51 of file OctetBuffer.java.
References utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
Referenced by protocol.ProtocolDataUnit.ProtocolDataUnit().
static int utils.OctetBuffer.toInt | ( | byte | b ) | [static] |
Converts a 'byte' to an 'int'.
Definition at line 300 of file OctetBuffer.java.
Referenced by protocol.ProtocolDataUnit.create(), and protocol.ProtocolDataUnit.ProtocolDataUnit().
{
return ( b + 0x100 ) & 0xFF;
}
static OctetBuffer utils.OctetBuffer.wrap | ( | byte[] | bs ) | [static] |
Wraps existing byte[] array.
Definition at line 39 of file OctetBuffer.java.
References utils.OctetBuffer.position, utils.OctetBuffer.sliceOffset, and utils.OctetBuffer.store.
Referenced by audio.AudioCodecUlaw.convertFromPCM(), audio.AudioCodecAlaw.convertFromPCM(), audio.AudioCodecUlaw.convertToPCM(), audio.AudioCodecAlaw.convertToPCM(), protocol.ProtocolDataUnit.ProtocolDataUnit(), and audio.AudioInterfacePCM.resample().
{ OctetBuffer bb = new OctetBuffer (); bb.store = bs; bb.position = 0; bb.sliceOffset = 0; return bb; }
int utils.OctetBuffer.position = 0 [private] |
Position index.
Definition at line 17 of file OctetBuffer.java.
Referenced by utils.OctetBuffer.allocate(), utils.OctetBuffer.get(), utils.OctetBuffer.getChar(), utils.OctetBuffer.getFreeSpace(), utils.OctetBuffer.getInt(), utils.OctetBuffer.getPosition(), utils.OctetBuffer.getShort(), utils.OctetBuffer.hasFreeSpace(), utils.OctetBuffer.put(), utils.OctetBuffer.putChar(), utils.OctetBuffer.putInt(), utils.OctetBuffer.putShort(), utils.OctetBuffer.slice(), and utils.OctetBuffer.wrap().
int utils.OctetBuffer.sliceOffset = 0 [private] |
Offset into backing store to enable slicing.
Definition at line 22 of file OctetBuffer.java.
Referenced by utils.OctetBuffer.allocate(), utils.OctetBuffer.get(), utils.OctetBuffer.getChar(), utils.OctetBuffer.getFreeSpace(), utils.OctetBuffer.getInt(), utils.OctetBuffer.getShort(), utils.OctetBuffer.getStore(), utils.OctetBuffer.getStoreSize(), utils.OctetBuffer.hasFreeSpace(), utils.OctetBuffer.put(), utils.OctetBuffer.putChar(), utils.OctetBuffer.putInt(), utils.OctetBuffer.putShort(), utils.OctetBuffer.slice(), and utils.OctetBuffer.wrap().
byte [] utils.OctetBuffer.store = null [private] |
The octet storage.
Definition at line 12 of file OctetBuffer.java.
Referenced by utils.OctetBuffer.allocate(), utils.OctetBuffer.get(), utils.OctetBuffer.getChar(), utils.OctetBuffer.getFreeSpace(), utils.OctetBuffer.getInt(), utils.OctetBuffer.getShort(), utils.OctetBuffer.getStore(), utils.OctetBuffer.getStoreSize(), utils.OctetBuffer.hasFreeSpace(), utils.OctetBuffer.put(), utils.OctetBuffer.putChar(), utils.OctetBuffer.putInt(), utils.OctetBuffer.putShort(), utils.OctetBuffer.slice(), and utils.OctetBuffer.wrap().