com.sun.cdc.io.j2me.datagram
Class DatagramObject

java.lang.Object
  extended by java.io.OutputStream
      extended by com.sun.cdc.io.j2me.UniversalOutputStream
          extended by com.sun.cdc.io.j2me.datagram.DatagramObject
All Implemented Interfaces:
DataInput, DataOutput, Datagram

public class DatagramObject
extends UniversalOutputStream
implements Datagram

This class is required because the J2SE Datagram class is final.


Constructor Summary
DatagramObject(DatagramPacket dpkt)
           
DatagramObject(int p)
           
 
Method Summary
 String getAddress()
          Get the address of the datagram.
 byte[] getData()
          Get the contents of the data buffer.
 int getLength()
          Get the length of the datagram.
 int getOffset()
          Get the offset.
 int read()
           
 boolean readBoolean()
          See the general contract of the readBoolean method of DataInput.
 byte readByte()
          See the general contract of the readByte method of DataInput.
 char readChar()
          See the general contract of the readChar method of DataInput.
 double readDouble()
          Reads eight input bytes and returns a double value.
 float readFloat()
          Reads four input bytes and returns a float value.
 void readFully(byte[] b)
          See the general contract of the readFully method of DataInput.
 void readFully(byte[] b, int off, int len)
          See the general contract of the readFully method of DataInput.
 int readInt()
          See the general contract of the readInt method of DataInput.
 String readLine()
          See the general contract of the readLine method of DataInput.
 long readLong()
          See the general contract of the readLong method of DataInput.
 short readShort()
          See the general contract of the readShort method of DataInput.
 int readUnsignedByte()
          See the general contract of the readUnsignedByte method of DataInput.
 int readUnsignedShort()
          See the general contract of the readUnsignedShort method of DataInput.
 String readUTF()
          See the general contract of the readUTF method of DataInput.
 void reset()
          Zero the read/write pointer as well as the offset and length state variables.
 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 state variables.
 void setLength(int len)
          Set the length state variable.
 long skip(long n)
           
 int skipBytes(int n)
          See the general contract of the skipBytes method of DataInput.
 void write(int ch)
          Writes the specified byte to this output stream.
 
Methods inherited from class com.sun.cdc.io.j2me.UniversalOutputStream
checkError, close, flush, print, print, print, print, print, print, print, println, println, println, println, println, println, println, println, seek, setEncoding, setTimeout, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 
Methods inherited from class java.io.OutputStream
write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.DataOutput
write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 

Constructor Detail

DatagramObject

public DatagramObject(DatagramPacket dpkt)

DatagramObject

public DatagramObject(int p)
Method Detail

getAddress

public String getAddress()
Description copied from interface: Datagram
Get the address of the datagram.

Specified by:
getAddress in interface Datagram
Returns:
the address in the form "datagram://{host}:{port}", or null if no address was set.
See Also:
Datagram.setAddress(java.lang.String)

getData

public byte[] getData()
Description copied from interface: Datagram
Get the contents of the data buffer.

Depending on the implementation, this operation may return the internal buffer or a copy of it. However, the user must not assume that the contents of the internal data buffer can be manipulated by modifying the data returned by this operation. Rather, the setData operation should be used for changing the contents of the internal buffer.

Specified by:
getData in interface Datagram
Returns:
the data buffer as a byte array
See Also:
Datagram.setData(byte[], int, int)

getOffset

public int getOffset()
Description copied from interface: Datagram
Get the offset.

Specified by:
getOffset in interface Datagram
Returns:
the offset state variable

getLength

public int getLength()
Description copied from interface: Datagram
Get the length of the datagram.

Specified by:
getLength in interface Datagram
Returns:
the length state variable
See Also:
Datagram.setLength(int)

setAddress

public void setAddress(String addr)
                throws IOException,
                       IllegalArgumentException
Description copied from interface: Datagram
Set datagram address. The address must be in the form "datagram://{host}:{port}".

Note that if the address of a datagram is not specified, then it defaults to that of the connection.

Specified by:
setAddress in interface Datagram
Parameters:
addr - the new target address as a URL
Throws:
IOException - if a some kind of I/O error occurs
IllegalArgumentException - if the address is not valid
See Also:
Datagram.getAddress()

setAddress

public void setAddress(Datagram reference)
                throws IllegalArgumentException
Description copied from interface: Datagram
Set datagram address, copying the address from another datagram.

Specified by:
setAddress in interface Datagram
Parameters:
reference - to the datagram whose address will be copied as the new target address for this datagram.
Throws:
IllegalArgumentException - if the address is not valid
See Also:
Datagram.getAddress()

setData

public void setData(byte[] buffer,
                    int offset,
                    int len)
             throws IllegalArgumentException
Description copied from interface: Datagram
Set the buffer, offset and length state variables. Depending on the implementation, this operation may copy the buffer or just set the state variable buffer to the value of the buffer argument. However, the user must not assume that the contents of the internal data buffer can be manipulated by modifying the buffer passed on to this operation.

Specified by:
setData in interface Datagram
Parameters:
buffer - 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 or offset plus length fall outside the buffer, or if the buffer parameter is invalid
See Also:
Datagram.getData()

setLength

public void setLength(int len)
Description copied from interface: Datagram
Set the length state variable.

Specified by:
setLength in interface Datagram
Parameters:
len - the new length of the datagram
See Also:
Datagram.getLength()

reset

public void reset()
Description copied from interface: Datagram
Zero the read/write pointer as well as the offset and length state variables.

Specified by:
reset in interface Datagram

skip

public long skip(long n)
          throws EOFException
Throws:
EOFException

read

public int read()
         throws IOException
Throws:
IOException

write

public void write(int ch)
           throws IOException
Description copied from class: OutputStream
Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Subclasses of OutputStream must provide an implementation for this method.

Specified by:
write in interface DataOutput
Specified by:
write in class OutputStream
Parameters:
ch - the byte.
Throws:
IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.

readFully

public final void readFully(byte[] b)
                     throws IOException
See the general contract of the readFully method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
readFully in interface DataInput
Parameters:
b - the buffer into which the data is read.
Throws:
EOFException - if this input stream reaches the end before reading all the bytes.
IOException - if an I/O error occurs.

readFully

public final void readFully(byte[] b,
                            int off,
                            int len)
                     throws IOException
See the general contract of the readFully method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
readFully in interface DataInput
Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the number of bytes to read.
Throws:
EOFException - if this input stream reaches the end before reading all the bytes.
IOException - if an I/O error occurs.

skipBytes

public final int skipBytes(int n)
                    throws IOException
See the general contract of the skipBytes method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
skipBytes in interface DataInput
Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
IOException - if an I/O error occurs.

readBoolean

public final boolean readBoolean()
                          throws IOException
See the general contract of the readBoolean method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
readBoolean in interface DataInput
Returns:
the boolean value read.
Throws:
EOFException - if this input stream has reached the end.
IOException - if an I/O error occurs.

readByte

public final byte readByte()
                    throws IOException
See the general contract of the readByte method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
readByte in interface DataInput
Returns:
the next byte of this input stream as a signed 8-bit byte.
Throws:
EOFException - if this input stream has reached the end.
IOException - if an I/O error occurs.

readUnsignedByte

public final int readUnsignedByte()
                           throws IOException
See the general contract of the readUnsignedByte method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
readUnsignedByte in interface DataInput
Returns:
the next byte of this input stream, interpreted as an unsigned 8-bit number.
Throws:
EOFException - if this input stream has reached the end.
IOException - if an I/O error occurs.

readShort

public final short readShort()
                      throws IOException
See the general contract of the readShort method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
readShort in interface DataInput
Returns:
the next two bytes of this input stream, interpreted as a signed 16-bit number.
Throws:
EOFException - if this input stream reaches the end before reading two bytes.
IOException - if an I/O error occurs.

readUnsignedShort

public final int readUnsignedShort()
                            throws IOException
See the general contract of the readUnsignedShort method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
readUnsignedShort in interface DataInput
Returns:
the next two bytes of this input stream, interpreted as an unsigned 16-bit integer.
Throws:
EOFException - if this input stream reaches the end before reading two bytes.
IOException - if an I/O error occurs.

readChar

public final char readChar()
                    throws IOException
See the general contract of the readChar method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
readChar in interface DataInput
Returns:
the next two bytes of this input stream as a Unicode character.
Throws:
EOFException - if this input stream reaches the end before reading two bytes.
IOException - if an I/O error occurs.

readInt

public final int readInt()
                  throws IOException
See the general contract of the readInt method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
readInt in interface DataInput
Returns:
the next four bytes of this input stream, interpreted as an int.
Throws:
EOFException - if this input stream reaches the end before reading four bytes.
IOException - if an I/O error occurs.

readFloat

public final float readFloat()
                      throws IOException
Description copied from interface: DataInput
Reads four input bytes and returns a float value. It does this by first constructing an int value in exactly the manner of the readInt method, then converting this int value to a float in exactly the manner of the method Float.intBitsToFloat. This method is suitable for reading bytes written by the writeFloat method of interface DataOutput.

Specified by:
readFloat in interface DataInput
Returns:
the float value read.
Throws:
EOFException - if this stream reaches the end before reading all the bytes.
IOException - if an I/O error occurs.

readDouble

public final double readDouble()
                        throws IOException
Description copied from interface: DataInput
Reads eight input bytes and returns a double value. It does this by first constructing a long value in exactly the manner of the readlong method, then converting this long value to a double in exactly the manner of the method Double.longBitsToDouble. This method is suitable for reading bytes written by the writeDouble method of interface DataOutput.

Specified by:
readDouble in interface DataInput
Returns:
the double value read.
Throws:
EOFException - if this stream reaches the end before reading all the bytes.
IOException - if an I/O error occurs.

readLong

public final long readLong()
                    throws IOException
See the general contract of the readLong method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
readLong in interface DataInput
Returns:
the next eight bytes of this input stream, interpreted as a long.
Throws:
EOFException - if this input stream reaches the end before reading eight bytes.
IOException - if an I/O error occurs.

readUTF

public final String readUTF()
                     throws IOException
See the general contract of the readUTF method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
readUTF in interface DataInput
Returns:
a Unicode string.
Throws:
EOFException - if this input stream reaches the end before reading all the bytes.
IOException - if an I/O error occurs.
See Also:
DataInputStream.readUTF(java.io.DataInput)

readLine

public final String readLine()
                      throws IOException
See the general contract of the readLine method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
readLine in interface DataInput
Returns:
a Unicode string.
Throws:
EOFException - if this input stream reaches the end before reading all the bytes.
IOException - if an I/O error occurs.
See Also:
DataInputStream.readLine()