Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

Copyright © 2006 Sun Microsystems, Inc. All rights reserved.

MID Profile

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 buffer.


Method Summary
 String getAddress()
          Get the address in the datagram
 byte[] getData()
          Get the buffer
 int getLength()
          Get the length
 int getOffset()
          Get the offset
 void reset()
          Reset the read/write pointer and zeros the offset and length parameters.
 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 datagram
Returns:
the address in string form, or null if no address was set

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 parameter 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
Throws:
IllegalArgumentException - if the address is not valid

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.
Throws:
IllegalArgumentException - if the address is not valid

setLength

public void setLength(int len)
Set the length
Parameters:
len - the new length of the data
Throws:
IllegalArgumentException - if the length is negative or larger than the buffer

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
Throws:
IllegalArgumentException - if the length or offset fall outside the buffer

reset

public void reset()
Reset the read/write pointer and zeros the offset and length parameters.

MID Profile

Copyright © 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

For more information, please consult the JSR 37 specification.