Methods Summary |
---|
public java.lang.String | getAddress()Get the address in the datagram.
return address;
|
public byte[] | getData()Get the buffer.
return buffer;
|
public int | getLength()Get the a number that is either the number of bytes to send or the
number of bytes received.
return length;
|
public int | getOffset()Get the offset.
return offset;
|
public int | read()Reads the next byte of data from the input stream. The value byte is
returned as an int in the range 0 to
255 . If no byte is available because the end of the stream
has been reached, the value -1 is returned. This method
blocks until input data is available, the end of the stream is detected,
or an exception is thrown.
if (readWritePosition >= length) {
return -1;
}
return buffer[offset + readWritePosition++] & 0xFF;
|
public void | reset()Zero the read/write pointer as well as the offset and
length parameters.
readWritePosition = 0;
offset = 0;
length = 0;
|
public void | setAddress(java.lang.String addr)Set datagram address. Must a "datagram://" URI.
HttpUrl url;
int temp;
if (addr == null) {
throw new IllegalArgumentException("Invalid address");
}
url = new HttpUrl(addr);
if (url.scheme == null || !url.scheme.equals("datagram")) {
throw new IllegalArgumentException("Invalid scheme");
}
/*
* Since we reused the HttpUrl parser, we must make sure that
* there was nothing past the authority in the URL.
*/
if (url.path != null || url.query != null || url.fragment != null) {
throw new IllegalArgumentException("Malformed address");
}
port = url.port;
if (url.host == null) {
throw new IllegalArgumentException("Missing host");
}
if (port == -1) {
throw new IllegalArgumentException("Missing port");
}
temp = Protocol.getIpNumber(Util.toCString(url.host));
if (temp == -1) {
throw new IllegalArgumentException("Invalid host");
}
ipNumber = temp;
address = addr;
|
public void | setAddress(Datagram reference)Set datagram address, copying the address from another datagram.
setAddress(reference.getAddress());
|
public void | setData(byte[] buf, int off, int len)Set the buffer, offset and length.
/*
* Check that the offset and length are valid.
* - must be positive
* - must not exceed buffer length
* - must have valid buffer
*/
if (len < 0 || off < 0 ||
(buf == null) ||
(off > 0 && off == buf.length) ||
((len + off) > buf.length)||
((len + off) < 0)) {
throw new IllegalArgumentException("Illegal length or offset");
}
buffer = buf;
offset = off;
length = len;
|
public void | setLength(int len)Set the length. Which can represent either the number of bytes to send
or the maxium number of bytes to receive.
setData(buffer, offset, len);
|
public long | skip(long n)A more effient skip than the one in
GeneralBase .
Skips over and discards n bytes of data from this input
stream. The skip method may, for a variety of reasons, end
up skipping over some smaller number of bytes, possibly 0 .
This may result from any of a number of conditions; reaching end of file
before n bytes have been skipped is only one possibility.
The actual number of bytes skipped is returned. If n is
negative, no bytes are skipped.
if (n < 0) {
return 0;
}
if (readWritePosition >= length) {
return 0;
}
int min = Math.min((int)n, length - readWritePosition);
readWritePosition += min;
return (min);
|
public void | write(int ch)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 ch are ignored.
if (offset + readWritePosition >= buffer.length) {
throw new IOException("Buffer full");
}
buffer[offset + readWritePosition++] = (byte)ch;
length = readWritePosition;
|