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 TypeMethodDescriptionvoid
close()
final FileChannel
Obtain the current FileChannel instance.getFD()
Obtain the current FileDescriptor instance.final long
length()
Returns the current total length of this instance, that is the total number of bytes that may be read from it.final long
position()
Returns the current read/write position in this instance.final void
position
(long l) Sets a new position for the next read or write in this instance.int
read()
Reads a byte.int
read
(byte[] bytes, int offset, int readLength) Read bytes from the underlying file channel.readUTF()
SeeRandomAccessFile.readUTF()
for a contract of this method.void
setLength
(long l) SeeRandomAccessFile.setLength(long)
for a contract of this method.void
write
(byte[] bytes, int offset, int writeLength) Write bytes to the underlying file channel.void
write
(int i) Writes a byte.void
SeeRandomAccessFile.writeUTF(String)
for a contract of this method.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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
-true
if 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:RandomAccessFileIO
SeeRandomAccessFile.readUTF()
for a contract of this method.- Specified by:
readUTF
in 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:RandomAccessFileIO
Obtain the current FileChannel instance. For instances that do not use File backed sources- Specified by:
getChannel
in interfaceRandomAccessFileIO
- Returns:
- FileChannel instance, possibly null.
- See Also:
-
getFD
Description copied from interface:RandomAccessFileIO
Obtain the current FileDescriptor instance.- Specified by:
getFD
in interfaceRandomAccessFileIO
- Returns:
- FileDescriptor instance, or possibly null.
- See Also:
-
setLength
public void setLength(long l) Description copied from interface:RandomAccessFileIO
SeeRandomAccessFile.setLength(long)
for a contract of this method.- Specified by:
setLength
in interfaceRandomAccessFileIO
- Parameters:
l
- The new file length.- See Also:
-
writeUTF
Description copied from interface:RandomAccessFileIO
SeeRandomAccessFile.writeUTF(String)
for a contract of this method.- Specified by:
writeUTF
in interfaceRandomAccessFileIO
- Parameters:
s
- A java string.- See Also:
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
position
Description copied from interface:ReadWriteAccess
Returns the current read/write position in this instance. The position may exceed the length, depending on implementation, just asseek
may go beyond the file size inRandomAccessFile
.- Specified by:
position
in interfaceReadWriteAccess
- Returns:
- the current read/write position.
- Throws:
IOException
- if there was an IO error.- See Also:
-
position
Description copied from interface:ReadWriteAccess
Sets a new position for the next read or write in this instance. The position may exceed the length, depending on implementation, just asseek
may go beyond the file size inRandomAccessFile
.- Specified by:
position
in 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:ReadWriteAccess
Returns the current total length of this instance, that is the total number of bytes that may be read from it.- Specified by:
length
in interfaceReadWriteAccess
- Returns:
- the total number of bytes contained in this instance
-
read
public int read()Description copied from interface:InputReader
Reads a byte. See the general contract ofFilterInputStream.read()
.- Specified by:
read
in 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:
read
in 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:OutputWriter
Writes a byte. See the general contract ofDataOutputStream.write(int)
.- Specified by:
write
in interfaceOutputWriter
- Parameters:
i
- the (unsigned) byte value to write.- See Also:
-
write
Write bytes to the underlying file channel.- Specified by:
write
in 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:
-