|
Rice Pastry API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.mpisws.p2p.transport.util.SocketInputBuffer
public class SocketInputBuffer
An easy way to read a complete object in from a socket. Wraps a Socket as an InputBuffer Throws an InsufficientBytesExceptoin when there is not enough data available locally, but caches the data so you can attempt to deserialize the object from the beginning when there are additional bytes. Not thread safe! The read operations will either: a) succeed b) throw a InsufficientBytesException, which you should probably retry later when there are more bytes (automatically calls reset) c) throw a ClosedChannelException, which means the socket was closed, d) other IOException If you don't complete reading the object, and want to start from the beginning of the cache, call reset(). If you complete reading the object, but want to reuse the SocketInputBuffer, call clear(). Note that the bytesRemaining() field always returns UNKNOWN because Java's socket api doesn't give us this information To find the size of the cache call size(). This is the amount of usable bytes in the cache, not the capacity. SocketInputBuffer automatically grows. Implementation notes: readPtr/writePtr are operating on the same byte[] called cache
Field Summary |
---|
Fields inherited from interface rice.p2p.commonapi.rawserialization.InputBuffer |
---|
UNKNOWN |
Constructor Summary | |
---|---|
SocketInputBuffer(P2PSocket socket)
|
|
SocketInputBuffer(P2PSocket socket,
int size)
|
Method Summary | |
---|---|
int |
bytesRemaining()
How much data is left in the InputBuffer. |
void |
clear()
Clears the cache from memory, resetting it to the initial size. |
int |
read(byte[] b)
|
int |
read(byte[] b,
int off,
int len)
|
boolean |
readBoolean()
|
byte |
readByte()
|
char |
readChar()
|
double |
readDouble()
|
float |
readFloat()
|
int |
readInt()
|
int |
readInternal()
|
int |
readInternal(byte[] b)
|
int |
readInternal(byte[] b,
int off,
int len)
|
long |
readLong()
|
short |
readShort()
|
java.lang.String |
readUTF()
|
void |
reset()
Resets the read pointer to the beginning of the cache. |
int |
size()
Note that this is not the number of bytes that can be read without throwing an exception, since some of these bytes may already have been consumed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SocketInputBuffer(P2PSocket socket)
public SocketInputBuffer(P2PSocket socket, int size)
Method Detail |
---|
public int bytesRemaining()
InputBuffer
bytesRemaining
in interface InputBuffer
public void reset()
public int size()
public int readInternal(byte[] b, int off, int len) throws java.io.IOException
b
- off
- len
-
java.io.IOException
public int readInternal(byte[] b) throws java.io.IOException
b
-
java.io.IOException
public int readInternal() throws java.io.IOException
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in interface InputBuffer
java.io.IOException
public int read(byte[] b) throws java.io.IOException
read
in interface InputBuffer
java.io.IOException
public byte readByte() throws java.io.IOException
readByte
in interface InputBuffer
java.io.IOException
public boolean readBoolean() throws java.io.IOException
readBoolean
in interface InputBuffer
java.io.IOException
public char readChar() throws java.io.IOException
readChar
in interface InputBuffer
java.io.IOException
public double readDouble() throws java.io.IOException
readDouble
in interface InputBuffer
java.io.IOException
public float readFloat() throws java.io.IOException
readFloat
in interface InputBuffer
java.io.IOException
public int readInt() throws java.io.IOException
readInt
in interface InputBuffer
java.io.IOException
public long readLong() throws java.io.IOException
readLong
in interface InputBuffer
java.io.IOException
public short readShort() throws java.io.IOException
readShort
in interface InputBuffer
java.io.IOException
public java.lang.String readUTF() throws java.io.IOException
readUTF
in interface InputBuffer
java.io.IOException
public void clear() throws java.io.IOException
java.io.IOException
|
Rice Pastry API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |