|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.rim.device.api.util.DataBuffer
net.rim.device.api.io.DatagramBase
public class DatagramBase
Generic datagram object defines holder of data sent or received from a datagram connection.
The DataInput
and DataOutput
interfaces are extended by
this interface to provide a simple way to read and write binary data in and
out of the datagram buffer. A special method, DatagramBase.reset()
, may be called to
reset the read/write point to the beginning of the buffer.
Field Summary | ||
---|---|---|
static int |
DG_NULL_ID
Datagram has null ID. |
|
protected DatagramAddressBase |
_addressBase
|
|
protected int |
_datagramId
|
|
protected int |
_flags
|
|
protected DatagramStatusListener |
_listener
|
|
protected Hashtable |
_properties
|
|
protected int |
_validFlags
|
Fields inherited from interface net.rim.device.api.io.IOProperties |
---|
CDMA_SET_FAST_DORMANCY_FLAG, FLAG_INVALID, FLAG_SET, FLAG_UNSET, GME_ADD_SRC_FIELD_FLAG, GME_DELAYED_ACK_FLAG, GME_FAIL_ON_MISSING_ROUTING_INFO_FLAG, GME_REQUEST_CONFIRMATION_FLAG, MDP_DATAGRAM_ACK_FLAG, MDP_DONT_SET_FAST_DORMANCY_FLAG, MDP_PACKET_ACK_FLAG, MOBITEX_MAILBOX_FLAG, MOBITEX_REQUEST_ACK_FLAG, UDP_RETRY_ON_NO_CONTEXT |
Constructor Summary | ||
---|---|---|
DatagramBase()
Constructs a new DatagramBase instance. |
||
DatagramBase(byte[] buffer,
int offset,
int length)
Constructs a new DatagramBase instance from provided data. |
||
DatagramBase(byte[] buffer,
int offset,
int length,
String address)
Constructs a new DatagramBase instance from provided data and target address. |
||
DatagramBase(byte[] buffer,
int offset,
int length,
DatagramAddressBase addressBase)
Constructs a new DatagramBase instance from provided data and address base. |
Method Summary | ||
---|---|---|
void |
copy(DatagramBase dgram)
Copies state and data from provided datagram. |
|
void |
copyFlagsInto(DatagramBase dst)
Copies flags from this datagram into provided datagram. |
|
String |
getAddress()
Retrieves the target address for this datagram. |
|
DatagramAddressBase |
getAddressBase()
Retrieves the address base for this datagram. |
|
byte[] |
getData()
Retrieves this datagram's data. |
|
int |
getDatagramId()
Retrieves this datagram's datagram ID. |
|
DatagramStatusListener |
getDatagramStatusListener()
Retrieves current status listener object. |
|
int |
getFlag(int flag)
Retrieves state of named flag. |
|
int |
getLength()
Retrieves this datagram's data length. |
|
int |
getOffset()
Retrieves the offset into this datagram's data. |
|
Object |
getProperty(String name)
Retrieves property by name. |
|
boolean |
isFlagSet(int flag)
Determines if named flag is set. |
|
protected DatagramAddressBase |
newAddressBase()
Retrieve new address base. |
|
void |
reset()
Resets state and data of this datagram. |
|
void |
resetDataBuffer()
Resets only the data of this datagram. |
|
void |
setAddress(String address)
Sets this datagram's address. |
|
void |
setAddress(Datagram datagram)
Sets this datagram's address, copying from provided datagram. |
|
void |
setAddressBase(DatagramAddressBase addressBase)
Sets this datagram's address base, copying from provided address base object. |
|
void |
setData(byte[] buffer,
int offset,
int length)
Sets this datagram's data. |
|
void |
setDatagramId(int datagramId)
Sets datagram ID for this datagram. |
|
void |
setDatagramStatusListener(DatagramStatusListener listener)
Registers status listener to receive events. |
|
void |
setFlag(int flag,
boolean value)
Sets state of named flag. |
|
void |
setLength(int length)
Sets this datagram's data length. |
|
Object |
setProperty(String name,
Object data)
Sets a property for this datagram. |
|
void |
simpleReset()
Resets only the state of this datagram Use this method to remove this datagram's properties and flags. |
Methods inherited from class net.rim.device.api.util.DataBuffer |
---|
available, ensureBuffer, ensureCapacity, ensureLength, eof, getArray, getArrayLength, getArrayPosition, getArrayStart, getCompressedIntSize, getPosition, isBigEndian, read, read, read, read, readBoolean, readByte, readByteArray, readChar, readCompressedInt, readCompressedLong, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUTF, readUnsignedByte, readUnsignedShort, rewind, setBigEndian, setData, setPosition, skipBytes, toArray, trim, trim, write, write, write, write, write, write, write, writeBoolean, writeByte, writeByteArray, writeByteArray, writeByteArray, writeBytes, writeChar, writeChars, writeCompressedInt, writeCompressedLong, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF, zero |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.io.DataInput |
---|
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLong, readShort, readUTF, readUnsignedByte, readUnsignedShort, skipBytes |
Methods inherited from interface java.io.DataOutput |
---|
write, write, write, writeBoolean, writeByte, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF |
Field Detail |
---|
public static final int DG_NULL_ID
protected DatagramAddressBase _addressBase
protected Hashtable _properties
protected int _flags
protected int _validFlags
protected int _datagramId
protected DatagramStatusListener _listener
Constructor Detail |
---|
public DatagramBase()
public DatagramBase(byte[] buffer, int offset, int length)
buffer
- Data buffer containing data for datagram.offset
- First byte in buffer to read.length
- Number of bytes to read from buffer.public DatagramBase(byte[] buffer, int offset, int length, String address) throws IOException
buffer
- Data buffer containing data for datagram.offset
- First byte in buffer to read.length
- Number of bytes to read from buffer.address
- Address for datagram.
IOException
public DatagramBase(byte[] buffer, int offset, int length, DatagramAddressBase addressBase)
buffer
- Data buffer containing data for datagram.offset
- First byte in buffer to read.length
- Number of bytes to read from buffer.addressBase
- Address base for datagram.Method Detail |
---|
public String getAddress()
getAddress
in interface Datagram
public DatagramAddressBase getAddressBase()
protected DatagramAddressBase newAddressBase()
By default, this method constructs and returns a new datagram address base object. Sub-classes should override this method for more specific functionality.
public byte[] getData()
getData
in interface Datagram
public int getLength()
getLength
in interface Datagram
getLength
in class DataBuffer
public int getOffset()
getOffset
in interface Datagram
public void setAddress(String address)
The parameter string describing the target of the datagram takes this form:
{protocol}:{target}
For example, the "target" can be "//{host}:{port}
"
(but is not necessarily limited to this).
So in this example a datagram connection for sending to a server could be addressed as so:
datagram://123.456.789.12:1234
Note: If the address of a datagram is not specified, then it defaults to that of the connection.
setAddress
in interface Datagram
address
- New target address.
IllegalArgumentException
- If you provide an invalid address.public void setAddress(Datagram datagram)
setAddress
in interface Datagram
datagram
- The datagram who's address will be copied as the new
target address for this datagram.
IllegalArgumentException
- If the address is not valid.public void setAddressBase(DatagramAddressBase addressBase)
addressBase
- Address base to serve as source.public void setLength(int length)
setLength
in interface Datagram
setLength
in class DataBuffer
length
- New length for this datagram's data; must not be less than
zero.
IllegalArgumentException
- If provided length is negative.public void setData(byte[] buffer, int offset, int length)
Note: This method resets the stream to big endian mode.
setData
in interface Datagram
setData
in class DataBuffer
buffer
- Data buffer.offset
- Offset into the data buffer.length
- Length of the data in the buffer.
IllegalArgumentException
- If the length or offset fall outside
the buffer.public Object setProperty(String name, Object data)
setProperty
in interface IOProperties
name
- Name of the property to set.data
- Data for property; pass null to remove the named property
from this datagram.
public Object getProperty(String name)
getProperty
in interface IOProperties
name
- Name for property to find.
public void setFlag(int flag, boolean value)
setFlag
in interface IOProperties
flag
- Flag to set or unset.value
- True to set flag; false to unset it.public int getFlag(int flag)
getFlag
in interface IOProperties
flag
- Flag for which to retrieve state.
IOProperties.FLAG_SET
if set; IOProperties.FLAG_UNSET
if unset;
IOProperties.FLAG_INVALID
if not a valid flag.public boolean isFlagSet(int flag)
isFlagSet
in interface IOProperties
flag
- Flag to test.
public void copyFlagsInto(DatagramBase dst)
dst
- Datagram to receive flags.public void setDatagramStatusListener(DatagramStatusListener listener)
public DatagramStatusListener getDatagramStatusListener()
public void setDatagramId(int datagramId)
datagramID
- Dstagram ID to set.public int getDatagramId()
public void reset()
Use this method to flush this datagram, making it an empty datagram with a length of 0 bytes, with no properties or flags. The address is set to null and the registered listener (if present) is removed.
reset
in interface Datagram
reset
in class DataBuffer
DatagramBase.simpleReset()
public void simpleReset()
Use this method to remove this datagram's properties and flags. The address is set to null and the registered listener (if present) is removed. This method does not flush this datagram's data or alter its length.
DatagramBase.reset()
public void resetDataBuffer()
Use this method to flush this datagram, making it an empty datagram with a length of 0 bytes. This method does not affect any of the datagram's internal state variables (properties, flags, address).
public void copy(DatagramBase dgram) throws IOException
Use this method to copy the data and internal state (poperties, flags, address) from provied datagram into this datagram.
Sub-classes are expected to override this method for specific
functionality, but should first call super.copy( datagram )
and then copy the subclass-specific material (including any
subclass-specific properties).
dgram
- Source datagram that things should copy from
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.