org.mpisws.p2p.transport.util
Class SocketInputBuffer
java.lang.Object
org.mpisws.p2p.transport.util.SocketInputBuffer
- All Implemented Interfaces:
- InputBuffer
public class SocketInputBuffer
- extends java.lang.Object
- implements InputBuffer
Allows reading in from a socket, throws exception when there is not enough data, but
caches the data so that it can be read when there is enough.
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
c) throw a ClosedChannelException, which means the socket was closed,
d) other IOException
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();
- Author:
- Jeff Hoye
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SocketInputBuffer
public SocketInputBuffer(P2PSocket socket,
int size)
bytesRemaining
public int bytesRemaining()
- Description copied from interface:
InputBuffer
- May be UNKNOWN
- Specified by:
bytesRemaining
in interface InputBuffer
reset
public void reset()
size
public int size()
readInternal
public int readInternal(byte[] b,
int off,
int len)
throws java.io.IOException
- Throws:
java.io.IOException
readInternal
public int readInternal(byte[] b)
throws java.io.IOException
- Throws:
java.io.IOException
readInternal
public int readInternal()
throws java.io.IOException
- Throws:
java.io.IOException
read
public int read(byte[] b,
int off,
int len)
throws java.io.IOException
- Specified by:
read
in interface InputBuffer
- Throws:
java.io.IOException
read
public int read(byte[] b)
throws java.io.IOException
- Specified by:
read
in interface InputBuffer
- Throws:
java.io.IOException
readByte
public byte readByte()
throws java.io.IOException
- Specified by:
readByte
in interface InputBuffer
- Throws:
java.io.IOException
readBoolean
public boolean readBoolean()
throws java.io.IOException
- Specified by:
readBoolean
in interface InputBuffer
- Throws:
java.io.IOException
readChar
public char readChar()
throws java.io.IOException
- Specified by:
readChar
in interface InputBuffer
- Throws:
java.io.IOException
readDouble
public double readDouble()
throws java.io.IOException
- Specified by:
readDouble
in interface InputBuffer
- Throws:
java.io.IOException
readFloat
public float readFloat()
throws java.io.IOException
- Specified by:
readFloat
in interface InputBuffer
- Throws:
java.io.IOException
readInt
public int readInt()
throws java.io.IOException
- Specified by:
readInt
in interface InputBuffer
- Throws:
java.io.IOException
readLong
public long readLong()
throws java.io.IOException
- Specified by:
readLong
in interface InputBuffer
- Throws:
java.io.IOException
readShort
public short readShort()
throws java.io.IOException
- Specified by:
readShort
in interface InputBuffer
- Throws:
java.io.IOException
readUTF
public java.lang.String readUTF()
throws java.io.IOException
- Specified by:
readUTF
in interface InputBuffer
- Throws:
java.io.IOException
clear
public void clear()
throws java.io.IOException
- Clears the cache from memory, resetting it to the initial size. This is a
good thing to do after you read an object.
- Throws:
java.io.IOException
Copyright © 2001-2005 - Rice Pastry.