|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.unister.semweb.drums.file.AbstractHeaderFile
com.unister.semweb.drums.file.HeaderIndexFile<Data>
Data
- an implementation of AbstractKVStorable
, e.g. GeneralStorable
public class HeaderIndexFile<Data extends AbstractKVStorable>
This class represents a file, which contains a bunch of datasets. The file also contains a header with some
informations and an IndexForHeaderIndexFile
. This class is for managing and handling equal sized storable
elements. So be very careful if this precondition is not fulfilled.
Header structure:
+-----------+--------------+---------------+---------------+-------------+---------+
= 1024 bytes (to have enough space for more values)
| FILE SIZE | FILLED UP TO | Closed Softly | ReadChunkSize | ElementSize | KeySize |
| 8 bytes . | 8 bytes .... | 1 bytes ..... | 4 bytes ..... | 4 bytes ... | 4 bytes |
+-----------+--------------+---------------+---------------+-------------+---------+
To use this class correctly, have a look at the following methods:
... DBFile dbfile = new DBFile(filename, mode, retries); ByteBuffer readBuffer = ByteBuffer.allocate(blockSize); long offset = 0; while(offset < dbfile.getFilledUpFromContentStart()) { read(offset, readBuffer); // do something with the readBuffer ... offset += readBuffer.limit(); } ...
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.unister.semweb.drums.file.AbstractHeaderFile |
---|
AbstractHeaderFile.AccessMode |
Field Summary |
---|
Fields inherited from class com.unister.semweb.drums.file.AbstractHeaderFile |
---|
DEFAULT_SIZE, HEADER_SIZE, osFile |
Constructor Summary | |
---|---|
HeaderIndexFile(java.lang.String fileName,
AbstractHeaderFile.AccessMode mode,
int max_retries_connect,
DRUMSParameterSet<Data> gp)
This constructor instantiates a new HeaderIndexFile with the given fileName in the given
AbstractHeaderFile.AccessMode . |
|
HeaderIndexFile(java.lang.String fileName,
int max_retries_connect,
DRUMSParameterSet<Data> gp)
This constructor instantiates a new HeaderIndexFile with the given fileName in the given
AbstractHeaderFile.AccessMode . |
Method Summary | |
---|---|
long |
append(byte[] sourceBuffer)
appends the given sourceBuffer to the file and returns the file position of the appended entry |
long |
append(java.nio.ByteBuffer sourceBuffer)
appends the given sourceBuffer to the file and returns the file position of the appended entry |
void |
clear()
Sets all file-pointers to their initial values. |
void |
close()
closes all open channels and the file |
void |
enlargeFile(long toEnlarge)
Rounds up the given size to the next full chunk, and enlarges the file by these amounts of bytes. |
int |
getChunkIndex(long offset)
calculates the index of the belonging readChunk in the files content |
int |
getChunkSize()
|
int |
getElementSize()
|
long |
getFreeSpace()
|
IndexForHeaderIndexFile |
getIndex()
|
boolean |
isConsistent()
This method checks, if the keys of all inserted elements are incrementing continuously. |
boolean |
isConsitentWithIndex()
This method checks, if the data is consistent with the index. |
boolean |
isSoftlyClosed()
|
java.nio.MappedByteBuffer |
map(long offset,
int length)
Create a MappedByteBuffer mapping the given region. |
void |
openChannel()
opens the RandomAccessFile and the corresponding FileChannel . |
int |
read(long offset,
byte[] destBuffer)
Reads x bytes from the file to the given ByteBuffer (position was set to zero), where x is the minimum of the capacity of the buffer and the remaining written bytes in the file. |
int |
read(long offset,
java.nio.ByteBuffer destBuffer)
Reads x bytes from the file to the given ByteBuffer (position was set to zero), where x is the minimum of the capacity of the buffer and the remaining written bytes in the file. |
void |
readIndex()
reads and instantiates the index from the indexBuffer |
void |
repairIndex()
This method repairs the index. |
void |
write(long offset,
byte[] sourceBuffer)
writes the bytes from the given Byte-array to the file beginning at offset. |
void |
write(long offset,
java.nio.ByteBuffer sourceBuffer)
writes the bytes from the given ByteBuffer to the file beginning at offset. |
Methods inherited from class com.unister.semweb.drums.file.AbstractHeaderFile |
---|
delete, getFilledUpFromContentStart, getFilledUpTo, getName, getRemainingBytes, isOpen, lock, unlock |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HeaderIndexFile(java.lang.String fileName, AbstractHeaderFile.AccessMode mode, int max_retries_connect, DRUMSParameterSet<Data> gp) throws FileLockException, java.io.IOException
HeaderIndexFile
with the given fileName
in the given
AbstractHeaderFile.AccessMode
.
fileName
- the filename of the underlying OSfile.mode
- the mode the file should be accessed. READ_ONLY or READ_WRITEmax_retries_connect
- the number of retries to open a channel, if the file is lockedgp
- the DRUMSParameterSet
.
FileLockException
- if the max_retries_connect
is exceeded
java.io.IOException
- if another error with the file-access occuredpublic HeaderIndexFile(java.lang.String fileName, int max_retries_connect, DRUMSParameterSet<Data> gp) throws FileLockException, java.io.IOException
HeaderIndexFile
with the given fileName
in the given
AbstractHeaderFile.AccessMode
. This is a weak constructor and therefore you can only have read-access.
fileName
- the filename of the underlying OSfile.max_retries_connect
- the number of retries to open a channel, if the file is lockedgp
- the DRUMSParameterSet
.
FileLockException
- if the max_retries_connect
is exceeded
java.io.IOException
- if another error with the fileaccess occuredMethod Detail |
---|
public java.nio.MappedByteBuffer map(long offset, int length) throws java.io.IOException
MappedByteBuffer
mapping the given region. The size of the HEADER will be respected
automatically.
offset
- length
-
MappedByteBuffer
pointing to the part of the file specified by offset and length.
java.io.IOException
public void write(long offset, java.nio.ByteBuffer sourceBuffer) throws java.io.IOException
write
in class AbstractHeaderFile
offset
- sourceBuffer
-
java.io.IOException
public void write(long offset, byte[] sourceBuffer) throws java.io.IOException
AbstractHeaderFile
write
in class AbstractHeaderFile
java.io.IOException
public long append(byte[] sourceBuffer) throws java.io.IOException
AbstractHeaderFile
append
in class AbstractHeaderFile
java.io.IOException
public long append(java.nio.ByteBuffer sourceBuffer) throws java.io.IOException
AbstractHeaderFile
append
in class AbstractHeaderFile
java.io.IOException
public int read(long offset, java.nio.ByteBuffer destBuffer) throws java.io.IOException
read
in class AbstractHeaderFile
offset
- the file offset, where to start readingdestBuffer
- the buffer to fill
java.io.IOException
public int read(long offset, byte[] destBuffer) throws java.io.IOException
read
in class AbstractHeaderFile
offset
- the file offset, where to start readingdestBuffer
- the buffer to fill
java.io.IOException
read(long, ByteBuffer)
public void openChannel() throws FileLockException, java.io.IOException
RandomAccessFile
and the corresponding FileChannel
. Reads the header and the index.
This may overwrite previous set parameters.
openChannel
in class AbstractHeaderFile
java.io.IOException
FileLockException
public long getFreeSpace()
getFreeSpace
in class AbstractHeaderFile
public void readIndex()
indexBuffer
public void enlargeFile(long toEnlarge) throws java.io.IOException
enlargeFile
in class AbstractHeaderFile
toEnlarge
-
java.io.IOException
public IndexForHeaderIndexFile getIndex()
IndexForHeaderIndexFile
public boolean isConsistent() throws java.io.IOException
java.io.IOException
public boolean isConsitentWithIndex() throws java.io.IOException
java.io.IOException
public void repairIndex() throws java.io.IOException
IndexForHeaderIndexFile
. This method should be called, if the file was not closed softly (
isSoftlyClosed()
).
java.io.IOException
public void clear()
clear
in class AbstractHeaderFile
public int getChunkIndex(long offset)
offset
- the byteOffset in the content
public int getElementSize()
public int getChunkSize()
public boolean isSoftlyClosed()
public void close()
AbstractHeaderFile
close
in class AbstractHeaderFile
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |