|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectedu.sdsc.grid.io.GeneralRandomAccessFile
edu.sdsc.grid.io.RemoteRandomAccessFile
edu.sdsc.grid.io.irods.IRODSRandomAccessFile
public class IRODSRandomAccessFile
Instances of this class support both reading and writing to a IRODS random access file.
This class behaves exactly as described in
GeneralRandomAccessFile
A random access file behaves like a large
array of bytes stored in the file system. There is a kind of cursor,
or index into the implied array, called the file pointer;
input operations read bytes starting at the file pointer and advance
the file pointer past the bytes read. If the random access file is
created in read/write mode, then output operations are also available;
output operations write bytes starting at the file pointer and advance
the file pointer past the bytes written. Output operations that write
past the current end of the implied array cause the array to be
extended. The file pointer can be read by the
getFilePointer method and set by the seek
method.
It is generally true of all the reading routines in this class that
if end-of-file is reached before the desired number of bytes has been
read, an EOFException (which is a kind of
IOException) is thrown. If any byte cannot be read for
any reason other than end-of-file, an IOException other
than EOFException is thrown. In particular, an
IOException may be thrown if the stream has been closed.
| Field Summary |
|---|
| Fields inherited from class edu.sdsc.grid.io.GeneralRandomAccessFile |
|---|
fd, file, fileFormat, isClosed, mode, rw, SEEK_CURRENT, SEEK_END, SEEK_START, swapNeeded |
| Constructor Summary | |
|---|---|
IRODSRandomAccessFile(IRODSFile file,
java.lang.String mode)
Creates a random access file stream to read from, and optionally to write to, a file with the specified name. |
|
IRODSRandomAccessFile(IRODSFileSystem irodsFileSystem,
java.lang.String filePath,
java.lang.String mode)
Creates a random access file stream to read from, and optionally to write to, a file with the specified name. |
|
| Method Summary | |
|---|---|
void |
close()
Closes this random access file stream and releases any system resources associated with the stream. |
protected void |
finalize()
Finalizes the object by explicitly letting go of each of its internally held values. |
long |
getFilePointer()
Returns the current offset in this file. |
GeneralFileSystem |
getFileSystem()
Returns the irods file system object. |
long |
length()
Returns the length of this file. |
protected void |
open(GeneralFile file)
Opens this file. |
int |
read()
Reads a byte of data from this file. |
protected int |
readBytes(byte[] buffer,
int offset,
int len)
Reads a sub array as a sequence of bytes. |
void |
seek(long position,
int origin)
Sets the file-pointer offset at which the next read or write occurs. |
protected void |
setFileSystem(GeneralFileSystem fileSystem)
Sets the IRODS server used of this IRODSRandomAccessFile object. |
void |
setLength(long newLength)
Sets the length of this file. |
protected void |
writeBytes(byte[] buffer,
int offset,
int len)
Writes a sub array as a sequence of bytes. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public IRODSRandomAccessFile(IRODSFileSystem irodsFileSystem,
java.lang.String filePath,
java.lang.String mode)
throws java.lang.IllegalArgumentException,
java.io.FileNotFoundException,
java.lang.SecurityException,
java.io.IOException
The mode argument specifies the access mode with which the file is to be opened. The permitted values and their meanings are as specified for the GeneralRandomAccessFile(File,String) constructor.
On construction a check is made to see if read access to the file is allowed. If the mode allows writing, write access to the file is also checked.
filePath - the IRODS file pathmode - the access mode
java.lang.IllegalArgumentException - if the mode argument is not equal
to one of "r", "rw", "rws", or
"rwd"
java.io.IOException - If an I/O error occurs
java.io.FileNotFoundException - If the file exists but is a directory
rather than a regular file, or cannot be opened or
created for any other reason
java.lang.SecurityException - If denied read access to the file
or the mode is "rw" and denied write access to the file.
public IRODSRandomAccessFile(IRODSFile file,
java.lang.String mode)
throws java.lang.IllegalArgumentException,
java.io.FileNotFoundException,
java.lang.SecurityException,
java.io.IOException
The mode argument specifies the access mode in which the file is to be opened. The permitted values and their meanings are:
The "rws" and "rwd" modes work much like the
"r" Open for reading only. Invoking any of the write methods of the resulting object will cause an IOExceptionto be thrown."rw" Open for reading and writing. If the file does not already exist then an attempt will be made to create it. "rws" Open for reading and writing, as with "rw", and also require that every update to the file's content or metadata be written synchronously to the underlying storage device. "rwd" Open for reading and writing, as with "rw", and also require that every update to the file's content be written synchronously to the underlying storage device.
force(boolean) method of
the FileChannel class, passing arguments of
true and false, respectively, except that they always
apply to every I/O operation and are therefore often more efficient. If
the file resides on a local storage device then when an invocation of a
method of this class returns it is guaranteed that all changes made to
the file by that invocation will have been written to that device. This
is useful for ensuring that critical information is not lost in the
event of a system crash. If the file does not reside on a local device
then no such guarantee is made.
The "rwd" mode can be used to reduce the number of I/O operations performed. Using "rwd" only requires updates to the file's content to be written to storage; using "rws" requires updates to both the file's content and its metadata to be written, which generally requires at least one more low-level I/O operation.
On construction a check is made to see if read access to the file is allowed. If the mode allows writing, write access to the file is also checked.
file - the file objectmode - the access mode, as described
above
java.io.IOException - If an I/O error occurs
java.lang.IllegalArgumentException - if the mode argument is not equal
to one of "r", "rw", "rws", or
"rwd"
java.io.FileNotFoundException - If the file exists but is a directory
rather than a regular file, or cannot be opened or
created for any other reason
java.lang.SecurityException - If denied read access to the file
or the mode is "rw" and denied write access to the file.| Method Detail |
|---|
protected void finalize()
throws java.lang.Throwable
finalize in class GeneralRandomAccessFilejava.lang.Throwable
protected void open(GeneralFile file)
throws java.io.FileNotFoundException,
java.lang.SecurityException,
java.io.IOException
name refers to a directory, an IOException
is thrown.
open in class GeneralRandomAccessFilefile - the file to open
java.io.IOException - If an I/O error occurs
java.io.FileNotFoundException
java.lang.SecurityException
protected void setFileSystem(GeneralFileSystem fileSystem)
throws java.lang.IllegalArgumentException,
java.lang.ClassCastException
fleServer - The IRODS server to be used.
java.lang.IllegalArgumentException - - if the argument is null.
java.lang.ClassCastException - - if the argument is not a IRODSFileSystem object.public GeneralFileSystem getFileSystem()
getFileSystem in class GeneralRandomAccessFilejava.lang.NullPointerException - if fileSystem is null.
public int read()
throws java.io.IOException
0x00-0x0ff). This
method blocks if no input is yet available.
Although IRODSRandomAccessFile is not a subclass of
InputStream, this method behaves in exactly the same
way as java.io.InputStream.read().
read in class GeneralRandomAccessFile-1 if the end of the
file has been reached.
java.io.IOException - if an I/O error occurs. Not thrown if
end-of-file has been reached.
protected int readBytes(byte[] buffer,
int offset,
int len)
throws java.io.IOException
readBytes in class GeneralRandomAccessFilebuffer - the buffer into which the data is read.offset - the start offset in the datalen - the maximum number of bytes read.
java.io.IOException - If an I/O error has occurred.
protected void writeBytes(byte[] buffer,
int offset,
int len)
throws java.io.IOException
writeBytes in class GeneralRandomAccessFilebuffer - the data to be writtenoffset - the start offset in the datalen - the number of bytes that are written
java.io.IOException - If an I/O error has occurred.
public long getFilePointer()
throws java.io.IOException
getFilePointer in class GeneralRandomAccessFilejava.io.IOException - if an I/O error occurs.
public void seek(long position,
int origin)
throws java.io.IOException
seek in class GeneralRandomAccessFilepos - the offset position, measured in bytes from the
at which to set the file pointer.origin - a Sets offset for the beginning of the seek.java.io.IOException - if pos is less than
0 or if an I/O error occurs.
public long length()
throws java.io.IOException
length in class GeneralRandomAccessFilejava.io.IOException - if an I/O error occurs.
public void setLength(long newLength)
throws java.io.IOException
Truncating a file on the IRODS is not yet supported, so
an UnsupportedOperationException will be thrown.
(If the present length of the file as returned by the
length method is greater than the newLength
argument then the file will be truncated. In this case, if the file
offset as returned by the getFilePointer method is greater
then newLength then after this method returns the offset
will be equal to newLength.)
If the present length of the file as returned by the
length method is smaller than the newLength
argument then the file will be extended. In this case, the contents of
the extended portion of the file are not defined.
setLength in class GeneralRandomAccessFilenewLength - The desired length of the file
java.io.IOException - If an I/O error occurs
java.lang.UnsupportedOperationException - on truncate
public void close()
throws java.io.IOException
close in class GeneralRandomAccessFilejava.io.IOException - if an I/O error occurs.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||