|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object pl.psnc.dl.ege.utils.DataBuffer
public class DataBuffer
Keeps collection of buffered byte data, which is used mainly by conversion
with validation process.
Each singular data item can be kept in memory - if it does not reaches specified
threshold (in number of bytes). If it does DataBuffer is permitted to save data
as temporary file.
Important: while buffer is referenced it is not cleared from data;
assigning new items indefinitely may result in stack overflow.
Memory can be relieved by class methods.
Each allocation in buffer is of type : single-write/multiple-read.
Field Summary | |
---|---|
static int |
DEFAULT_ITEM_MAX_SIZE
Default value : max size of item (in number of bytes), that allows to keep it in memory. |
Constructor Summary | |
---|---|
DataBuffer(int itemMaxSize,
java.lang.String tmpDirectory)
Creates instance of data buffer with specified temporary files directory and threshold for every contained data item. |
|
DataBuffer(java.lang.String tmpDirectory)
Creates instance of data buffer with specified temporary files directory - where overwhelmed data is kept. |
Method Summary | |
---|---|
java.lang.String |
allocate()
Allocates clean data item in buffer. |
java.lang.String |
allocate(java.io.InputStream inputStream)
Reads data from specified input stream and creates single data item. |
java.lang.String |
allocate(java.io.InputStream inputStream,
java.lang.String itemName)
Reads data from specified input stream and creates single data item. |
void |
clear(boolean forceDelete)
Relieves all stored in buffer data items If 'forceDelete' parameter is set to 'true' all temporary files will be deleted immediately, otherwise they will be deleted after release of memory by garbage collector. |
java.io.InputStream |
getDataAsStream(java.lang.String id)
Returns specified by id - data item as input stream. |
java.lang.String |
getDataDir(java.lang.String id)
Returns temp dir of allocated item - can be null if item is stored in memory. |
java.io.OutputStream |
getElementOutputStream(java.lang.String id)
Returns buffer allocation output stream. |
java.lang.String |
getTemporaryDir()
|
boolean |
removeData(java.lang.String id,
boolean forceDelete)
Relieves selected data item. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_ITEM_MAX_SIZE
Constructor Detail |
---|
public DataBuffer(java.lang.String tmpDirectory)
tmpDirectory
- temporary files directorypublic DataBuffer(int itemMaxSize, java.lang.String tmpDirectory)
itemMaxSize
- maximum size of data itemtmpDirectory
- temporary files directoryMethod Detail |
---|
public java.lang.String allocate()
Allocates clean data item in buffer.
Method returns id of allocated data item.
public java.io.OutputStream getElementOutputStream(java.lang.String id) throws java.lang.IllegalStateException
Returns buffer allocation output stream.
If output stream of selected item was closed, using this method again on the same item will result in IllegalStateException.
id
- of buffer item
java.lang.IllegalStateException
public java.lang.String allocate(java.io.InputStream inputStream)
inputStream
- streamed input data
public java.lang.String allocate(java.io.InputStream inputStream, java.lang.String itemName)
If item maximum size is reached, data is written to temporary file with name of 'itemName'.
Method returns unique id of created item.
inputStream
- itemName
-
public java.io.InputStream getDataAsStream(java.lang.String id)
Returns specified by id - data item as input stream.
If item does not exists in buffer method returns 'null'.
'id'
- of a data item.
public java.lang.String getDataDir(java.lang.String id)
id
-
public boolean removeData(java.lang.String id, boolean forceDelete)
Relieves selected data item.
If 'forceDelete' parameter is set to 'true' temporary file (if it was created) will be deleted immediately, otherwise it will be deleted after release of memory by garbage collector.
'id'
- of data itempublic void clear(boolean forceDelete)
Relieves all stored in buffer data items
If 'forceDelete' parameter is set to 'true' all temporary files will be deleted immediately, otherwise they will be deleted after release of memory by garbage collector.
public java.lang.String getTemporaryDir()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |