|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.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()
|
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 InputBufferpublic void reset()
public int size()
public int readInternal(byte[] b,
int off,
int len)
throws IOException
b - off - len -
IOException
public int readInternal(byte[] b)
throws IOException
b -
IOException
public int readInternal()
throws IOException
IOException
public int read(byte[] b,
int off,
int len)
throws IOException
read in interface InputBufferIOException
public int read(byte[] b)
throws IOException
read in interface InputBufferIOException
public byte readByte()
throws IOException
readByte in interface InputBufferIOException
public boolean readBoolean()
throws IOException
readBoolean in interface InputBufferIOException
public char readChar()
throws IOException
readChar in interface InputBufferIOException
public double readDouble()
throws IOException
readDouble in interface InputBufferIOException
public float readFloat()
throws IOException
readFloat in interface InputBufferIOException
public int readInt()
throws IOException
readInt in interface InputBufferIOException
public long readLong()
throws IOException
readLong in interface InputBufferIOException
public short readShort()
throws IOException
readShort in interface InputBufferIOException
public String readUTF()
throws IOException
readUTF in interface InputBufferIOException
public void clear()
throws IOException
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||