public class OnDiskArray
extends java.lang.Object
implements java.lang.AutoCloseable
Modifier and Type | Field and Description |
---|---|
private java.io.RandomAccessFile |
file
Random Access File object.
|
private java.io.File |
filename
File name.
|
private static int |
HEADER_POS_SIZE
Position of file size (in records).
|
private int |
headersize
Size of the header in the file.
|
private static int |
INTERNAL_HEADER_SIZE
Size of the classes header size.
|
private java.nio.channels.FileLock |
lock
Lock for the file that will be kept while writing.
|
protected int |
magic
Magic number used to identify files.
|
private java.nio.MappedByteBuffer |
map
The memory mapped buffer.
|
private int |
numrecs
Number of records in the file.
|
private int |
recordsize
Size of the records in the file.
|
private static long |
serialVersionUID
Serial version.
|
private boolean |
writable
Writable or read-only object.
|
Constructor and Description |
---|
OnDiskArray(java.io.File filename,
int magicseed,
int extraheadersize,
boolean writable)
Constructor to open an existing file.
|
OnDiskArray(java.io.File filename,
int magicseed,
int extraheadersize,
int recordsize,
boolean writable)
Constructor to open an existing file.
|
OnDiskArray(java.io.File filename,
int magicseed,
int extraheadersize,
int recordsize,
int initialsize)
Constructor to write a new file.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Explicitly close the file.
|
void |
ensureSize(int size)
Ensure that the file can fit the given number of records.
|
java.nio.ByteBuffer |
getExtraHeader()
Read the extra header data.
|
protected int |
getExtraHeaderSize()
Return the size of the extra header.
|
java.io.File |
getFilename()
Get the file name.
|
int |
getNumRecords()
Get number of records in file.
|
java.nio.ByteBuffer |
getRecordBuffer(int index)
Get a record buffer
|
protected int |
getRecordsize()
Get the size of a single record.
|
private long |
indexToFileposition(long index)
Compute file position from index number
|
boolean |
isWritable()
Check if the file is writable.
|
private void |
mapArray()
(Re-) map the data array.
|
static int |
mixMagic(int magic1,
int magic2)
Mix two magic numbers into one, to obtain a combined magic.
|
void |
resizeFile(int newsize)
Resize file to the intended size
|
private void |
validateHeader(boolean validateRecordSize)
Validates the header and throws an IOException if the header is invalid.
|
private static final long serialVersionUID
protected int magic
private int headersize
private int recordsize
private int numrecs
private java.io.File filename
private final java.io.RandomAccessFile file
private java.nio.channels.FileLock lock
private boolean writable
private java.nio.MappedByteBuffer map
private static final int INTERNAL_HEADER_SIZE
private static final int HEADER_POS_SIZE
public OnDiskArray(java.io.File filename, int magicseed, int extraheadersize, int recordsize, int initialsize) throws java.io.IOException
filename
- File name to be opened.magicseed
- Magic number to derive real magic from.extraheadersize
- header size NOT including the internal headerrecordsize
- Record sizeinitialsize
- Initial file size (in records)java.io.IOException
- on IO errorspublic OnDiskArray(java.io.File filename, int magicseed, int extraheadersize, int recordsize, boolean writable) throws java.io.IOException
filename
- File name to be opened.magicseed
- Magic number to derive real magic from.extraheadersize
- header size NOT including the internal headerrecordsize
- Record sizewritable
- flag to open the file writablejava.io.IOException
- on IO errorspublic OnDiskArray(java.io.File filename, int magicseed, int extraheadersize, boolean writable) throws java.io.IOException
getRecordsize()
filename
- File name to be opened.magicseed
- Magic number to derive real magic from.extraheadersize
- header size NOT including the internal headerwritable
- flag to open the file writablejava.io.IOException
- on IO errorsprivate void mapArray() throws java.io.IOException
java.io.IOException
- on mapping error.private void validateHeader(boolean validateRecordSize) throws java.io.IOException
validateRecordSize
- java.io.IOException
public static final int mixMagic(int magic1, int magic2)
magic1
- Magic number to mix.magic2
- Magic number to mix.private long indexToFileposition(long index)
index
- Index offsetpublic void resizeFile(int newsize) throws java.io.IOException
newsize
- New file size.java.io.IOException
- on IO errorspublic java.nio.ByteBuffer getRecordBuffer(int index) throws java.io.IOException
index
- Record indexjava.io.IOException
- on IO errorsprotected int getExtraHeaderSize()
public java.nio.ByteBuffer getExtraHeader() throws java.io.IOException
java.io.IOException
- on IO errorsprotected int getRecordsize()
public java.io.File getFilename()
public boolean isWritable()
public void close() throws java.io.IOException
close
in interface java.lang.AutoCloseable
java.io.IOException
- on IO errorspublic int getNumRecords()
public void ensureSize(int size) throws java.io.IOException
size
- Sizejava.io.IOException
Copyright © 2019 ELKI Development Team. License information.