Package nom.tam.util
Class RandomAccessFileChannel
java.lang.Object
nom.tam.util.RandomAccessFileChannel
- All Implemented Interfaces:
Closeable,AutoCloseable,InputReader,OutputWriter,RandomAccessFileIO,ReadWriteAccess
A random accessible
FileChannel implementation for FITS I/O purposes. It enables file-like access for
nom-tam-fits that goes beyond local files. This class provides a generic implementation, which may be used, for
example, with the NIO SPI file system provider to Amazon S3.- Since:
- 1.21
- Author:
- Dustin Jenkins, Attila Kovacs
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionRandomAccessFileChannel(Path filePath) Constructor for a readable/writable random accessibleFileChannel, which can be used for accessing FITS files.RandomAccessFileChannel(Path filePath, boolean readOnly) Constructor for a random accessibleFileChannel, for reading or for reading and writing. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()final FileChannelObtain the current FileChannel instance.getFD()Obtain the current FileDescriptor instance.final longlength()Returns the current total length of this instance, that is the total number of bytes that may be read from it.final longposition()Returns the current read/write position in this instance.final voidposition(long l) Sets a new position for the next read or write in this instance.intread()Reads a byte.intread(byte[] bytes, int offset, int readLength) Read bytes from the underlying file channel.readUTF()SeeRandomAccessFile.readUTF()for a contract of this method.voidsetLength(long l) SeeRandomAccessFile.setLength(long)for a contract of this method.voidwrite(byte[] bytes, int offset, int writeLength) Write bytes to the underlying file channel.voidwrite(int i) Writes a byte.voidSeeRandomAccessFile.writeUTF(String)for a contract of this method.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface nom.tam.util.RandomAccessFileIO
read, write
-
Constructor Details
-
RandomAccessFileChannel
Constructor for a readable/writable random accessibleFileChannel, which can be used for accessing FITS files.- Parameters:
filePath- The path to the file- Throws:
IOException- if the file is not accessible- Since:
- 1.21
- See Also:
-
RandomAccessFileChannel
Constructor for a random accessibleFileChannel, for reading or for reading and writing. It may be used for accessing FITS files.- Parameters:
filePath- The path to the filereadOnly-trueif the file should only be used for reading, otherwisefalse.- Throws:
IOException- if the file is not accessible- Since:
- 1.21
- See Also:
-
-
Method Details
-
readUTF
Description copied from interface:RandomAccessFileIOSeeRandomAccessFile.readUTF()for a contract of this method.- Specified by:
readUTFin interfaceRandomAccessFileIO- Returns:
- Reads a UTF string from the input, up to an EOL termination (with
\n) or until the end of file, whichever comes first. - See Also:
-
getChannel
Description copied from interface:RandomAccessFileIOObtain the current FileChannel instance. For instances that do not use File backed sources- Specified by:
getChannelin interfaceRandomAccessFileIO- Returns:
- FileChannel instance, possibly null.
- See Also:
-
getFD
Description copied from interface:RandomAccessFileIOObtain the current FileDescriptor instance.- Specified by:
getFDin interfaceRandomAccessFileIO- Returns:
- FileDescriptor instance, or possibly null.
- See Also:
-
setLength
public void setLength(long l) Description copied from interface:RandomAccessFileIOSeeRandomAccessFile.setLength(long)for a contract of this method.- Specified by:
setLengthin interfaceRandomAccessFileIO- Parameters:
l- The new file length.- See Also:
-
writeUTF
Description copied from interface:RandomAccessFileIOSeeRandomAccessFile.writeUTF(String)for a contract of this method.- Specified by:
writeUTFin interfaceRandomAccessFileIO- Parameters:
s- A java string.- See Also:
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
position
Description copied from interface:ReadWriteAccessReturns the current read/write position in this instance. The position may exceed the length, depending on implementation, just asseekmay go beyond the file size inRandomAccessFile.- Specified by:
positionin interfaceReadWriteAccess- Returns:
- the current read/write position.
- Throws:
IOException- if there was an IO error.- See Also:
-
position
Description copied from interface:ReadWriteAccessSets a new position for the next read or write in this instance. The position may exceed the length, depending on implementation, just asseekmay go beyond the file size inRandomAccessFile.- Specified by:
positionin interfaceReadWriteAccess- Parameters:
l- the new read/write position.- Throws:
IOException- if there was an IO error.- See Also:
-
length
public final long length()Description copied from interface:ReadWriteAccessReturns the current total length of this instance, that is the total number of bytes that may be read from it.- Specified by:
lengthin interfaceReadWriteAccess- Returns:
- the total number of bytes contained in this instance
-
read
public int read()Description copied from interface:InputReaderReads a byte. See the general contract ofFilterInputStream.read().- Specified by:
readin interfaceInputReader- Returns:
- the (unsigned) byte value or -1 if there is nothing left to read.
- See Also:
-
read
Read bytes from the underlying file channel.- Specified by:
readin interfaceInputReader- Parameters:
bytes- The byte array to read into.offset- The offset in the FileChannel to start reading.readLength- The number of bytes to read.- Returns:
- The number of bytes read.
- Throws:
IOException- If an error occurs reading from the FileChannel.- See Also:
-
write
public void write(int i) Description copied from interface:OutputWriterWrites a byte. See the general contract ofDataOutputStream.write(int).- Specified by:
writein interfaceOutputWriter- Parameters:
i- the (unsigned) byte value to write.- See Also:
-
write
Write bytes to the underlying file channel.- Specified by:
writein interfaceOutputWriter- Parameters:
bytes- The byte array to write.offset- The offset in the FileChannel to start writing from.writeLength- The number of bytes to write.- Throws:
IOException- If an error occurs writing to the FileChannel.- See Also:
-