us.ihmc.utilities.io
Class DatagramInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by us.ihmc.utilities.io.DatagramInputStream
All Implemented Interfaces:
java.io.Closeable

public class DatagramInputStream
extends java.io.InputStream

DatagramInputStream. Each time you read, it'll give you data from the last packet if there is some, or wait to receive a new packet to replenish the buffer. If the buffer has data, it'll just ignore the incoming DataGrams. May receive data out of order, but probably not a problem on a direct connection. Shouldn't concatenate this with a BufferedInputStream, like you would with TCP, if you want to ignore packets until you are ready for the next one.


Field Summary
static int BUFFER_SIZE
           
 
Constructor Summary
DatagramInputStream(int port)
           
 
Method Summary
 void close()
           
 int read()
          This will block once out of data and need to wait for a new DatagramPacket.
 int read(byte[] b)
          This will block once out of data and need to wait for a new DatagramPacket.
 int read(byte[] b, int offset, int length)
          This will block once out of data and need to wait for a new DatagramPacket.
 void setThrowOutStalePackets(boolean throwOutStalePackets)
           
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

public static final int BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

DatagramInputStream

public DatagramInputStream(int port)
                    throws java.net.SocketException
Throws:
java.net.SocketException
Method Detail

setThrowOutStalePackets

public void setThrowOutStalePackets(boolean throwOutStalePackets)

read

public int read()
         throws java.io.IOException
This will block once out of data and need to wait for a new DatagramPacket.

Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException
This will block once out of data and need to wait for a new DatagramPacket.

Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(byte[] b,
                int offset,
                int length)
         throws java.io.IOException
This will block once out of data and need to wait for a new DatagramPacket.

Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

close

public void close()
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream