com.gc.iotools.stream.store
Class ThresholdStore

java.lang.Object
  extended by com.gc.iotools.stream.store.ThresholdStore
All Implemented Interfaces:
SeekableStore, Store

public class ThresholdStore
extends Object
implements SeekableStore

Store that puts data in memory until threshold size is reach. At that point data is written to the disk.

Since:
1.2.0
Version:
$Id: ThresholdStore.java 463 2013-01-21 23:54:17Z dvd.smnt@gmail.com $
Author:
dvd.smnt

Constructor Summary
ThresholdStore(int treshold)
           Constructor for ThresholdStore.
ThresholdStore(int treshold, File file)
           Constructor for ThresholdStore.
 
Method Summary
 void cleanup()
          Cleans up the Store.
protected  void finalize()
           Clean up the temporary files eventually open.
 int get(byte[] bytes, int offset, int length)
          gets length bytes from the store.
 long getSize()
           Getter for the field size.
 int getTreshold()
           Getter for the field treshold.
 void put(byte[] bytes, int offset, int length)
          put
 void seek(long position)
          Reposition this Store on a previously read position.
 void setPosition(long position)
           Setter for the field position.
 String toString()
           Provides a String representation of the state of the Store for debugging purposes.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ThresholdStore

public ThresholdStore(int treshold)

Constructor for ThresholdStore.

Parameters:
treshold - a int.

ThresholdStore

public ThresholdStore(int treshold,
                      File file)

Constructor for ThresholdStore.

Parameters:
treshold - a int.
file - a File object.
Method Detail

cleanup

public void cleanup()
Cleans up the Store. Forget all the data previously stored.

Specified by:
cleanup in interface Store

finalize

protected void finalize()
                 throws Throwable
Clean up the temporary files eventually open.

Overrides:
finalize in class Object
Throws:
Throwable

get

public int get(byte[] bytes,
               int offset,
               int length)
        throws IOException
gets length bytes from the store.

Specified by:
get in interface Store
Parameters:
bytes - array where to put the data in.
offset - offset in the array to start put the data.
length - length of the bytes got from the store.
Returns:
number of bytes effectively put in the array or -1 if the Store was empty.
Throws:
IOException - when an error occurs in the store, and data can't be retrieved.

getSize

public long getSize()

Getter for the field size.

Returns:
a long.

getTreshold

public int getTreshold()

Getter for the field treshold.

Returns:
a int.

put

public void put(byte[] bytes,
                int offset,
                int length)
         throws IOException

put

Specified by:
put in interface Store
Parameters:
bytes - an array of byte.
offset - a int.
length - a int.
Throws:
IOException - if any.

seek

public void seek(long position)
          throws IOException
Reposition this Store on a previously read position.

Specified by:
seek in interface SeekableStore
Parameters:
position - position to read the data from.
Throws:
IOException - If some error in the internal store happens.
EOFException - If a position is greater than the actual Store size.

setPosition

public void setPosition(long position)

Setter for the field position.

Parameters:
position - a long.

toString

public String toString()
Provides a String representation of the state of the Store for debugging purposes.

Overrides:
toString in class Object


Copyright © 2008–2014. All rights reserved.