lejos.pc.charting
Class CachingInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by lejos.pc.charting.CachingInputStream
All Implemented Interfaces:
java.io.Closeable

public class CachingInputStream
extends java.io.InputStream

Provide a read-ahead buffer input stream of bytes. The source InputStream (passed in the constructor) is constantly read into a byte buffer which values are then made available through the read methods. This methodology is used to help ensure the NXT does not block on a write() (using BlueTooth or USB) as it would if its limited buffer is filled and nothing is reading from the stream.

If the buffer fills completely, the reader thread will wait/block until bytes are read() so make sure the size of the buffer is appropriate for the application intended.

Author:
Kirk P. Thompson, Sven Köhler

Constructor Summary
CachingInputStream(java.io.InputStream in, int bufferSize)
          Construct an CachingInputStream with the specified buffer size and source.
 
Method Summary
 int available()
           
 int getMaxQueuedBytes()
          Return the maximum number of bytes buffered.
 int read()
           
 
Methods inherited from class java.io.InputStream
close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingInputStream

public CachingInputStream(java.io.InputStream in,
                          int bufferSize)
Construct an CachingInputStream with the specified buffer size and source.

Parameters:
in - The source input stream
bufferSize - The byte buffer size
Method Detail

read

public int read()
         throws java.io.IOException
Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

available

public int available()
              throws java.io.IOException
Overrides:
available in class java.io.InputStream
Throws:
java.io.IOException

getMaxQueuedBytes

public int getMaxQueuedBytes()
Return the maximum number of bytes buffered.

Returns:
byte count