|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.brains2b.thex.io.BinaryIOKit
public class BinaryIOKit
Kit for handling IO for all BinaryDocument
actions
This kit allows for reading from and writing to streams and handles read and writing files.
Files are read, written and altered in blocks determined by BLOCK_SIZE and divided
over BinaryElement
that can be read on a per block base and written per block.
The later to a temporary file that is united with unchanged blocks when the file is saved.
Field Summary | |
---|---|
static int |
BLOCK_SIZE
The size of the blocks in which a file will be divided so blocks can be read and written independently |
static int |
ELEMENT_ALTER
Indicator for a block that is unaltered and on (a temporary) file |
static int |
ELEMENT_MEMORY
Indicator for a block that is in memory, either altered or unaltered |
static int |
ELEMENT_OLD
Indicator for a block that is unaltered and still on file |
Constructor Summary | |
---|---|
BinaryIOKit()
|
Method Summary | |
---|---|
java.io.File |
getFile()
get the file that holds the content for the BinaryDocument |
void |
open(java.io.File f,
BinaryDocument doc)
open a file and set the content to the given document |
void |
read(java.io.InputStream is,
BinaryDocument doc,
int offset)
read the content of an InputStream and insert it into a BinaryDocument starting at offset |
void |
readBlock(BinaryElement be)
read a BinaryElement from the original file if BinaryElement.getState() is ELEMENT_OLD or a temporary file if
BinaryElement.getState() is ELEMENT_ALTER . |
protected void |
releaseBlock(BinaryElement be)
release the BinaryElement clearing it from memory and set BinaryElement.setState(int) to ELEMENT_OLD |
void |
save(java.io.File f,
BinaryDocument doc)
save a BinaryDocument to File |
void |
setBlockData(BinaryElement be)
set the block data to the given block by reading it from file, removing the data for the oldest BinaryElement from cache, writing it
to file if it was changed. |
void |
write(java.io.OutputStream os,
BinaryDocument doc,
int offset,
int len)
write the content of BinaryDocument from offset to length to the OutputStream |
protected void |
writeBlock(BinaryElement be)
write this BinaryElement to the location within a temporary file |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int BLOCK_SIZE
public static final int ELEMENT_OLD
public static final int ELEMENT_ALTER
public static final int ELEMENT_MEMORY
Constructor Detail |
---|
public BinaryIOKit()
Method Detail |
---|
public void write(java.io.OutputStream os, BinaryDocument doc, int offset, int len) throws java.io.IOException, javax.swing.text.BadLocationException
BinaryDocument
from offset to length to the OutputStream
os
- OutputStream, the stream to write todoc
- BinaryDocument, the document to read the content fromoffset
- int, the position to start reading fromlen
- int, the number of bytes to read from the document
java.io.IOException
- thrown if the content cannot be written to the stream
javax.swing.text.BadLocationException
- thrown if the given offset or length cannot be read from the documentpublic void read(java.io.InputStream is, BinaryDocument doc, int offset) throws java.io.IOException, javax.swing.text.BadLocationException
InputStream
and insert it into a BinaryDocument
starting at offset
is
- InputStream, the strea to read fromdoc
- BinaryDocument, the document to insert intooffset
- int, the position to start writing to
java.io.IOException
- thrown if the content cannot be read from the stream
javax.swing.text.BadLocationException
- thrown if the given offset cannot be inserted in the documentpublic void open(java.io.File f, BinaryDocument doc) throws java.io.IOException, javax.swing.text.BadLocationException
The document will be divided into blocks and only the first three blocks are read directly. Other blocks will be read if accessed trhough there offset.
f
- File, the file to readdoc
- BinaryDocument, the document to insert the content to
java.io.IOException
- thrown if the content cannot be read from the file
javax.swing.text.BadLocationException
- thrown if the given offset cannot be inserted in the documentpublic void save(java.io.File f, BinaryDocument doc) throws java.io.IOException, javax.swing.text.BadLocationException
BinaryDocument
to File
f
- File, the file to save todoc
- BinaryDocument the document to save the content from
java.io.IOException
- thrown if the content cannot be written to the file
javax.swing.text.BadLocationException
- thrown if the document cannot be readprotected void writeBlock(BinaryElement be) throws java.io.IOException
BinaryElement
to the location within a temporary file
This method is called from setBlockData(BinaryElement)
if the BinaryElement.getState()
equals ELEMENT_ALTER
be
- BinaryElement containing the content to be written
java.io.IOException
- thrown if the content cannot be written to the fileprotected void releaseBlock(BinaryElement be)
BinaryElement
clearing it from memory and set BinaryElement.setState(int)
to ELEMENT_OLD
be
- BinaryElementpublic void readBlock(BinaryElement be) throws java.io.IOException
BinaryElement
from the original file if BinaryElement.getState()
is ELEMENT_OLD
or a temporary file if
BinaryElement.getState()
is ELEMENT_ALTER
. The status of the Element will be changed to ELEMENT_MEMORY
be
- BinaryElement
java.io.IOException
- thrown if the content cannot be read from the filepublic void setBlockData(BinaryElement be) throws java.io.IOException, javax.swing.text.BadLocationException
BinaryElement
from cache, writing it
to file if it was changed.
be
- BinaryElement
java.io.IOException
- thrown if the content cannot be read from the file or changed data cannot be written
javax.swing.text.BadLocationException
public java.io.File getFile()
BinaryDocument
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |