public class CASAFile extends File
The "shape" of the file is as follows:
+---------------------------+ | file header | +---------------------------+ | block header "_*index" | |-------- | | node record---------------------------+ | node record----------------------+ | | ... | | | +---------------------------+ <----+ | | block header -------------------------------+ +-------- | | | | ... | | | +---------------------------+ <---------+ | | block header | |node +-------- | |continuation | ... | |block +---------------------------+ <---------------+ | block header | +-------- | | ... | +---------------------------+Stream based I/O is supported with CASAInputStream and CASAOutputStream.
Copyright: Copyright 2003-2014, Knowledge Science Group, University of Calgary. Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. The Knowledge Science Group makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.
CASAFileIndex
,
CASAInputStream
,
CASAOutputStream
,
Serialized FormModifier and Type | Field and Description |
---|---|
static String |
DEFAULT_FILE_NAME
the file name used with the default constructor
|
private CASAFileHeader |
header |
static int |
MODE_APPEND
write mode flag used to indicate that data be appended to a node
|
static int |
MODE_OVERWRITE
write mode flag used to indicate that data be written from the start of a node
|
private boolean |
validityChecked |
(package private) String |
validityCheckExplanation |
pathSeparator, pathSeparatorChar, separator, separatorChar
Constructor and Description |
---|
CASAFile() |
CASAFile(String pathname)
Creates a new CASAFile class using the specified pathname.
|
Modifier and Type | Method and Description |
---|---|
void |
appendNode(String nodeName,
byte[] nodeData)
Writes a byte array to a given node, appending it to any data currently
stored in that node.
|
static String |
checkAndFixPathname(String pathname) |
boolean |
createNewFile()
Overrides createNewFile() from File.
|
void |
defragment()
defrag this file
|
void |
defragment(PrintStream log)
Defrag this file, writing progress and summary to out (if != null).
|
boolean |
deleteAllNodes()
Deletes all nodes in the file except those with reserved names (index, etc).
|
boolean |
deleteNode(String nodeName)
Delete the given node from the file.
|
CASAFileFreeList |
getFreeList()
Get this files free block list.
|
CASAFileIndex |
getIndex()
Get this files index.
|
byte[] |
getNode(String nodeName)
Reads and returns the byte array stored in the given node.
|
long |
getNodeLength(String nodeName)
Calculate the size of a node within the file.
|
String |
getVersion()
return the version number of this file
|
long |
getVersionEncoded()
returns the encoded version number.
|
boolean |
isCASAFile()
A file is a CASA file if the file exists, it is a file, and
the files magic number matches the CASAFile magic number.
|
void |
putNode(String nodeName,
byte[] nodeData)
Writes a byte array to a given node, overwriting any data currently stored
in that node.
|
int |
read(byte[] bytes,
NodePosition pos)
convenience method for reading bytes from a node
|
int |
read(byte[] bytes,
NodePosition nodePos,
int start,
int length)
Read length bytes from the given node position within the file and store them
in the supplied byte array.
|
int |
read(byte[] bytes,
String node)
convenience method for reading bytes from a node
|
int |
read(byte[] bytes,
String node,
long dataOffset,
int start,
int length)
convenience method for reading bytes from a node
|
int |
write(byte[] bytes,
NodePosition pos)
convenience method for writing bytes to a node
|
int |
write(byte[] bytes,
NodePosition nodePos,
int start,
int length)
write bytes to the given node position within the file.
|
int |
write(byte[] bytes,
String node)
convenience method for writing bytes to a node
|
int |
write(byte[] bytes,
String node,
int mode,
int start,
int length)
convenience method for writing bytes to a node
|
canExecute, canRead, canWrite, compareTo, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getFreeSpace, getName, getParent, getParentFile, getPath, getTotalSpace, getUsableSpace, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setExecutable, setExecutable, setLastModified, setReadable, setReadable, setReadOnly, setWritable, setWritable, toPath, toString, toURI, toURL
public static final int MODE_APPEND
public static final int MODE_OVERWRITE
public static String DEFAULT_FILE_NAME
private CASAFileHeader header
private boolean validityChecked
String validityCheckExplanation
public CASAFile()
public CASAFile(String pathname)
pathname
- Pathname of the file to create or open.public boolean isCASAFile()
public long getVersionEncoded()
public String getVersion()
public boolean createNewFile() throws IOException
createNewFile
in class File
IOException
File.createNewFile()
public boolean deleteNode(String nodeName) throws CASAIOException, IOException
CASAIOException
- if nodeName is a reserved name or some
other error occurs during node deletionIOException
- if some I/O error occurs during node deletionpublic boolean deleteAllNodes()
public int write(byte[] bytes, String node) throws CASAIOException, IOException
CASAIOException
IOException
public int write(byte[] bytes, String node, int mode, int start, int length) throws CASAIOException, IOException
CASAIOException
IOException
public int write(byte[] bytes, NodePosition pos) throws CASAIOException, IOException
CASAIOException
IOException
public int write(byte[] bytes, NodePosition nodePos, int start, int length) throws CASAIOException, IOException
CASAIOException
- if node is a reserved name or some
other error occurs during writingIOException
- if some underlying I/O error occurs during writingpublic int read(byte[] bytes, String node) throws CASAIOException, IOException
CASAIOException
IOException
public int read(byte[] bytes, String node, long dataOffset, int start, int length) throws CASAIOException, IOException
CASAIOException
IOException
public int read(byte[] bytes, NodePosition pos) throws CASAIOException, IOException
CASAIOException
IOException
public int read(byte[] bytes, NodePosition nodePos, int start, int length) throws CASAIOException, IOException
CASAIOException
- if some CASA error occurs during readingIOException
- if some underlying I/O error occurs during readingpublic long getNodeLength(String nodeName) throws CASAIOException, IOException
CASAIOException
IOException
public CASAFileIndex getIndex() throws CASAIOException, IOException
CASAIOException
IOException
CASAFileIndex
public CASAFileFreeList getFreeList() throws CASAIOException, IOException
CASAIOException
IOException
CASAFileFreeList
public void defragment() throws CASAIOException, IOException
CASAIOException
IOException
public void defragment(PrintStream log) throws CASAIOException, IOException
CASAIOException
IOException
public void putNode(String nodeName, byte[] nodeData) throws IOException
nodeName
- The name of the node to store the data to.nodeData
- The data to be stored in the given node.IOException
- If there was an error writing to the node for any
reason.public void appendNode(String nodeName, byte[] nodeData) throws IOException
nodeName
- The name of the node to store the data to.nodeData
- The data to be stored in the given node.IOException
- If there was an error writing to the node for any
reason.public byte[] getNode(String nodeName) throws IOException
nodeName
- The name of the node to store the data to.IOException
- If there was an error writing to the node for any
reason.