uk.ac.rdg.resc.jstyx.gridservice.server
Class GeneralCachingStreamReader

java.lang.Object
  extended by uk.ac.rdg.resc.jstyx.gridservice.server.GeneralCachingStreamReader
Direct Known Subclasses:
CachedStreamReader

public abstract class GeneralCachingStreamReader
extends java.lang.Object

Abstract class that reads from an InputStream in a separate thread, caching the results to the local hard disk. Permits multiple clients to make DataRequests for data, replying with chunks of data when they are ready.

Author:
Jon Blower $Revision: 507 $ $Date: 2005-12-01 08:21:56 +0000 (Thu, 01 Dec 2005) $ $Log$ Revision 1.5 2005/12/01 08:21:56 jonblower Fixed javadoc comments Revision 1.4 2005/09/01 07:49:39 jonblower Set to print stack trace of IOException whether or not logger is debug-enabled Revision 1.3 2005/06/10 07:54:49 jonblower Added code to convert event-based StreamViewer to InputStream-based one Revision 1.2 2005/05/27 21:22:39 jonblower Further development of caching stream readers Revision 1.1 2005/05/27 17:02:59 jonblower Initial import

Nested Class Summary
static class GeneralCachingStreamReader.DataRequest
          Class representing a client that is waiting for data
 
Constructor Summary
GeneralCachingStreamReader()
           
 
Method Summary
 void delete()
          Called when the file is removed from the server.
abstract  void error(GeneralCachingStreamReader.DataRequest originalRequest, java.lang.Exception e)
           
 java.io.File getCacheFile()
          Gets the File that is being used to cache the contents of the stream
 long getCacheLength()
          Gets the size of the cache in bytes
 boolean isEOF()
           
abstract  void newData(GeneralCachingStreamReader.DataRequest originalRequest, byte[] data, int offset, int count)
           
 void read(GeneralCachingStreamReader.DataRequest dr)
          Get data from the stream's cache.
 void setCacheFile(java.io.File cacheFile)
           
 void startReading(java.io.InputStream is)
          Sets the input stream from which the CachingStreamReader gets data and immediately starts reading from this stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeneralCachingStreamReader

public GeneralCachingStreamReader()
Method Detail

getCacheFile

public java.io.File getCacheFile()
Gets the File that is being used to cache the contents of the stream


getCacheLength

public long getCacheLength()
Gets the size of the cache in bytes


setCacheFile

public void setCacheFile(java.io.File cacheFile)
                  throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException

isEOF

public boolean isEOF()
Returns:
true if we have reached end of file

startReading

public void startReading(java.io.InputStream is)
                  throws java.io.IOException
Sets the input stream from which the CachingStreamReader gets data and immediately starts reading from this stream

Throws:
java.lang.IllegalStateException - if this object is already reading from a stream
java.io.IOException - if the cache file could not be created

read

public void read(GeneralCachingStreamReader.DataRequest dr)
Get data from the stream's cache.


newData

public abstract void newData(GeneralCachingStreamReader.DataRequest originalRequest,
                             byte[] data,
                             int offset,
                             int count)

error

public abstract void error(GeneralCachingStreamReader.DataRequest originalRequest,
                           java.lang.Exception e)

delete

public void delete()
Called when the file is removed from the server. This deletes the underlying cache file.



Copyright © 2004-2006 Reading e-Science Centre. All Rights Reserved.