Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| J2ME CDC
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javax.microedition.io
Interface Datagram

All Superinterfaces:
  DataInput, DataOutput

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, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytes`

Methods inherited from interface java.io.DataOutput
`write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, 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.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| J2ME CDC
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Java is a trademark or registred trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2000 Sun Microsystems, Inc. 901 San Antonio Road,
Palo, Alto, California, 94303, U.S.A All Rights Reserved.