net.sf.freecol.common.networking
Class ReceivingThread.FreeColNetworkInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by net.sf.freecol.common.networking.ReceivingThread.FreeColNetworkInputStream
All Implemented Interfaces:
java.io.Closeable
Enclosing class:
ReceivingThread

 class ReceivingThread.FreeColNetworkInputStream
extends java.io.InputStream

Input stream for buffering the data from the network.

This is just a buffered input stream that signals end-of-stream when a given token END_OF_STREAM is encountered. In order to continue receiving data, the method enable() has to be called. Calls to close() has no effect, the underlying input stream has to be closed directly.


Field Summary
private  int bEnd
           
private  int bStart
           
private  byte[] buffer
           
private static int BUFFER_SIZE
           
private  boolean empty
           
private static char END_OF_STREAM
           
private  java.io.InputStream in
           
private  boolean wait
           
 
Constructor Summary
ReceivingThread.FreeColNetworkInputStream(java.io.InputStream in)
          Creates a new FreeColNetworkInputStream.
 
Method Summary
(package private)  void enable()
          Prepares the input stream for a new message.
private  boolean fill()
          Fills the buffer with data.
 int read()
          Reads a single byte.
 int read(byte[] b, int off, int len)
          Reads from the buffer and returns the data.
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

private static final int BUFFER_SIZE
See Also:
Constant Field Values

END_OF_STREAM

private static final char END_OF_STREAM
See Also:
Constant Field Values

in

private final java.io.InputStream in

buffer

private byte[] buffer

bStart

private int bStart

bEnd

private int bEnd

empty

private boolean empty

wait

private boolean wait
Constructor Detail

ReceivingThread.FreeColNetworkInputStream

ReceivingThread.FreeColNetworkInputStream(java.io.InputStream in)
Creates a new FreeColNetworkInputStream.

Parameters:
in - The input stream in which this object should get the data from.
Method Detail

fill

private boolean fill()
              throws java.io.IOException
Fills the buffer with data.

Returns:
true if the buffer has been filled with data, and false if an error occured.
Throws:
java.io.IOException - if thrown by the underlying stream.

enable

void enable()
Prepares the input stream for a new message.

Makes the subsequent calls to read return the data instead of -1.


read

public int read()
         throws java.io.IOException
Reads a single byte.

Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException
See Also:
read(byte[], int, int)

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads from the buffer and returns the data.

Overrides:
read in class java.io.InputStream
Parameters:
b - The place where the data will be put.
off - The offset to use when writing the data to b.
len - Number of bytes to read.
Returns:
The actual number of bytes read and -1 if the message has ended, that is; if the token END_OF_STREAM is encountered.
Throws:
java.io.IOException