JavaGantt 2011.1 API

eu.beesoft.gaia.util
Class InputStreamGobbler

java.lang.Object
  extended by java.io.InputStream
      extended by eu.beesoft.gaia.util.InputStreamGobbler
All Implemented Interfaces:
java.io.Closeable, java.lang.Runnable

public class InputStreamGobbler
extends java.io.InputStream
implements java.lang.Runnable

A special implementation of the InputStream.

The instance creates in its constructor a new thread and starts itself in this thread. It reads in method run() invoked by this thread data from the input stream given as a argument to the instance constructor, and stores data to the internal byte array. When the array size exceeds internal limit, the instance creates temporary file and stores the loaded data in this file.

All loaded data can be read with any InputStream read{} method. These methods block while all data from the source input stream are loaded.

If the instance creates a temporary file, this file is deleted in method close() invoked by programmer or on Java VM exit.

This class is usable when you need load data from other source and process it after all data are loaded, or if you need to load such data but you don't want to process it.


Constructor Summary
InputStreamGobbler(java.io.InputStream is)
          Creates an instance of InputStreamGobbler.
 
Method Summary
 void close()
          Closes this input stream.
 java.lang.Thread getThread()
          Returns the thread in which is this instance running.
 int read()
          Implementation of InputStream.read() method.
 void run()
          Implementation of Runnable interface, invoked from the thread internally started by this instance.
 
Methods inherited from class java.io.InputStream
available, 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

InputStreamGobbler

public InputStreamGobbler(java.io.InputStream is)
Creates an instance of InputStreamGobbler. Starts instance in the new thread.

Parameters:
is - - input stream to gobble
Method Detail

getThread

public java.lang.Thread getThread()
Returns the thread in which is this instance running.

Returns:
thread of this instance

run

public void run()
Implementation of Runnable interface, invoked from the thread internally started by this instance. Reads input stream given to the constructor and stores the received data to internal byte array or temporary file.

Specified by:
run in interface java.lang.Runnable

read

public int read()
         throws java.io.IOException
Implementation of InputStream.read() method. Returns byte from the temporary storage created in run() method. Blocks until run() in the separate thread is running.

Specified by:
read in class java.io.InputStream
Returns:
one byte from internal storage
Throws:
java.io.IOException - if some error occurs

close

public void close()
           throws java.io.IOException
Closes this input stream. Deletes a temporary file, if it was created in run() method.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException - if some error occurs

JavaGantt 2011.1 API