LiveGraph
data visualisation and analysis framework

org.LiveGraph.dataCache
Class DataStreamToCacheReader

java.lang.Object
  extended by org.LiveGraph.dataCache.DataStreamToCacheReader
All Implemented Interfaces:
java.io.Closeable, DataStreamObserver

public class DataStreamToCacheReader
extends java.lang.Object
implements java.io.Closeable, DataStreamObserver

This reader will parse a data stream using DataStreamReader and store all information in a data cache for further processing by the application.

See DataStreamWriter for the details of the data file format.

This product includes software developed by the LiveGraph project and its contributors.
(http://www.live-graph.org)
Copyright (c) 2007 G. Paperin.
All rights reserved.

File: DataStreamToCacheReader.java

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following terms and conditions are met:

1. Redistributions of source code must retain the above acknowledgement of the LiveGraph project and its web-site, the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above acknowledgement of the LiveGraph project and its web-site, the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software or any derived software must display the following acknowledgement:
This product includes software developed by the LiveGraph project and its contributors.
(http://www.live-graph.org)

4. All advertising materials distributed in form of HTML pages or any other technology permitting active hyper-links that mention features or use of this software or any derived software must display the acknowledgment specified in condition 3 of this agreement, and in addition, include a visible and working hyper-link to the LiveGraph homepage (http://www.live-graph.org).

THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Version:
"1.1.1"
Author:
Greg Paperin (http://www.paperin.org)

Field Summary
private  DataCache cache
          Cache for storage of extracted data.
private  DataStreamReader in
          Data stream reader.
 
Constructor Summary
DataStreamToCacheReader(java.io.InputStream is, DataCache cache)
          Creates a data reader on the specified stream.
 
Method Summary
 void close()
          Closes the underlying data stream.
 void eventCommentLine(java.lang.String line, DataStreamReader reader)
          Used for callback by the DataStreamReader; does nothing.
 void eventDataLineRead(java.util.List<java.lang.String> dataTokens, int datasetIndex, DataStreamReader reader)
          Used for callback by the DataStreamReader; adds a dataset to the cache.
 void eventFileInfoLine(java.lang.String info, DataStreamReader reader)
          Used for callback by the DataStreamReader; adds a file info line to the cache.
 void eventLabelsSet(java.util.List<java.lang.String> labels, DataStreamReader reader)
          Used for callback by the DataStreamReader; setts the data column labels in the cache.
 void eventSeparatorSet(java.lang.String separator, DataStreamReader reader)
          Used for callback by the DataStreamReader; does nothing.
 DataCache getDataCache()
           
 int readFromStream()
          Reads as many data lines from the underlying stream as there are available, parses the lines and stores the extracted information (if any) in this reader's data cache.
 boolean ready()
          Tells whether this reader's underlying data stream is ready to be read.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

private DataStreamReader in
Data stream reader.


cache

private DataCache cache
Cache for storage of extracted data.

Constructor Detail

DataStreamToCacheReader

public DataStreamToCacheReader(java.io.InputStream is,
                               DataCache cache)
Creates a data reader on the specified stream.

Parameters:
is - The stream from which to read.
cache - The data cache into which to store the data.
Method Detail

getDataCache

public DataCache getDataCache()
Returns:
The data cache used by this reader.

ready

public boolean ready()
              throws java.io.IOException
Tells whether this reader's underlying data stream is ready to be read.

Returns:
true if the next readFromStream() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.
Throws:
java.io.IOException - If an I/O error occurs.

close

public void close()
           throws java.io.IOException
Closes the underlying data stream. Further reading is not possible after calling this method.

Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException - If an I/O error occurs.

readFromStream

public int readFromStream()
                   throws java.io.IOException,
                          DataFormatException
Reads as many data lines from the underlying stream as there are available, parses the lines and stores the extracted information (if any) in this reader's data cache.

Returns:
number of non-empty file lines read.
Throws:
java.io.IOException - If an I/O error occurs.
DataFormatException - If the data stream contents do not conform with the expected data stream format.
See Also:
DataStreamWriter, DataStreamReader

eventCommentLine

public void eventCommentLine(java.lang.String line,
                             DataStreamReader reader)
Used for callback by the DataStreamReader; does nothing.

Specified by:
eventCommentLine in interface DataStreamObserver
Parameters:
line - The comment line.
reader - The reader which produced this event.

eventDataLineRead

public void eventDataLineRead(java.util.List<java.lang.String> dataTokens,
                              int datasetIndex,
                              DataStreamReader reader)
Used for callback by the DataStreamReader; adds a dataset to the cache.

Specified by:
eventDataLineRead in interface DataStreamObserver
Parameters:
dataTokens - An unmodifiable list containing all data tokens parsed from this line.
datasetIndex - The number of this data line in the stream (i.e. dataset file index).
reader - The reader which produced this event.

eventFileInfoLine

public void eventFileInfoLine(java.lang.String info,
                              DataStreamReader reader)
Used for callback by the DataStreamReader; adds a file info line to the cache.

Specified by:
eventFileInfoLine in interface DataStreamObserver
Parameters:
info - File description/info string.
reader - The reader which produced this event.

eventLabelsSet

public void eventLabelsSet(java.util.List<java.lang.String> labels,
                           DataStreamReader reader)
Used for callback by the DataStreamReader; setts the data column labels in the cache.

Specified by:
eventLabelsSet in interface DataStreamObserver
Parameters:
labels - An unmodifiable list containing all parsed data series labels.
reader - The reader which produced this event.

eventSeparatorSet

public void eventSeparatorSet(java.lang.String separator,
                              DataStreamReader reader)
Used for callback by the DataStreamReader; does nothing.

Specified by:
eventSeparatorSet in interface DataStreamObserver
Parameters:
separator - The new data values separator string.
reader - The reader which produced this event.

LiveGraph
data visualisation and analysis framework