javax.microedition.io
Interface Datagram


public interface Datagram
extends DataInput, DataOutput

This is the generic datagram interface. It represents an object that will act as the holder of data to be send 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 function reset() may be called to reset the read/write point to the beginning of the data structure.


Method Summary
 String getAddress()
          Get the address in the datagran
 byte[] getData()
          Get the buffer
 int getLength()
          Get the length
 int getOffset()
          Get the offset
 void reset()
          Reset the read/write pointer
 void setAddress(Datagram reference)
          Set datagram address, copying the address from another datagram.
 void setAddress(String addr)
          Set datagram address.
 void setData(byte[] buffer, int offset, int len)
          Set the buffer, offset and length
 void setLength(int len)
          Set the length
 
Methods inherited from interface java.io.DataInput
readBoolean, readByte, readChar, readFully, readFully, readInt, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytes
 
Methods inherited from interface java.io.DataOutput
write, write, write, writeBoolean, writeByte, writeChar, writeChars, writeInt, writeLong, writeShort, writeUTF
 

Method Detail

getAddress

public String getAddress()
Get the address in the datagran
Returns:
the address in string form

getData

public byte[] getData()
Get the buffer
Returns:
the data buffer

getLength

public int getLength()
Get the length
Returns:
the length of the data

getOffset

public int getOffset()
Get the offset
Returns:
the offset into the data buffer

setAddress

public void setAddress(String addr)
                throws IOException
Set datagram address. The paramter string describing the target of the datagram takes the form:
     {protocol}:{target}
 
E.g. 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 that if the address of a datagram is not specified, then it defaults to that of the connection.
Parameters:
addr - the new target address as a URL

setAddress

public void setAddress(Datagram reference)
Set datagram address, copying the address from another datagram.
Parameters:
reference - the datagram who's address will be copied as the new target address for this datagram.

setLength

public void setLength(int len)
Set the length
Parameters:
len - the new length of the data

setData

public void setData(byte[] buffer,
                    int offset,
                    int len)
Set the buffer, offset and length
Parameters:
addr - the data buffer
offset - the offset into the data buffer
len - the length of the data in the buffer

reset

public void reset()
Reset the read/write pointer