Package nom.tam.util
Class BufferedFile
java.lang.Object
nom.tam.util.ArrayDataFile
nom.tam.util.FitsFile
nom.tam.util.BufferedFile
- All Implemented Interfaces:
Closeable
,DataInput
,DataOutput
,Flushable
,AutoCloseable
,ArrayDataInput
,ArrayDataOutput
,FitsIO
,FitsOutput
,InputReader
,OutputWriter
,RandomAccess
,ReadWriteAccess
Deprecated.
- See Also:
-
Field Summary
Fields inherited from interface nom.tam.util.FitsIO
BITS_OF_1_BYTE, BITS_OF_2_BYTES, BITS_OF_3_BYTES, BITS_OF_4_BYTES, BITS_OF_5_BYTES, BITS_OF_6_BYTES, BITS_OF_7_BYTES, BYTE_1_OF_LONG_MASK, BYTE_2_OF_LONG_MASK, BYTE_3_OF_LONG_MASK, BYTE_4_OF_LONG_MASK, BYTE_MASK, BYTES_IN_BOOLEAN, BYTES_IN_BYTE, BYTES_IN_CHAR, BYTES_IN_DOUBLE, BYTES_IN_FLOAT, BYTES_IN_INTEGER, BYTES_IN_LONG, BYTES_IN_SHORT, DEFAULT_BUFFER_SIZE, HIGH_INTEGER_MASK, INTEGER_MASK, SHORT_MASK, SHORT_OF_LONG_MASK
-
Constructor Summary
ConstructorDescriptionBufferedFile
(File file) Deprecated.Constructs a buffered FITS file with the default buffer size and default access mode.BufferedFile
(File file, String mode) Deprecated.Constructs a buffered FITS file with the default buffer size.BufferedFile
(File file, String mode, int bufferSize) Deprecated.Constructs a buffered FITS fileBufferedFile
(String filename) Deprecated.Constructs a buffered FITS file with the default buffer size and default access modeBufferedFile
(String filename, String mode) Deprecated.Constructs a buffered FITS file with the default buffer sizeBufferedFile
(String filename, String mode, int bufferSize) Deprecated.Constructs a buffered FITS file -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
flush()
final FileChannel
Get the channel associated with this file.final FileDescriptor
getFD()
Get the file descriptor associated with this stream.final long
Gets the current read/write position in the file.final boolean
hasAvailable
(int need) Checks if there are the required number of bytes available to read from this file.final long
length()
Returns the current length of the file.final int
read()
Reads a byte.final int
read
(byte[] b) Read as many bytes into a byte array as possible.final int
read
(byte[] b, int from, int len) Reads up to the specified number of bytes into a buffer.final void
readFully
(byte[] b) Reads bytes to completely fill the supplied buffer.void
readFully
(byte[] b, int off, int len) Reads bytes to fill the supplied buffer with the requested number of bytes from the given starting buffer index.final String
readUTF()
Same asRandomAccessFile.readUTF()
.final void
seek
(long newPos) Sets a new position in the file for subsequent reading or writing.void
setLength
(long newLength) Sets the length of the file.final long
skip
(long n) Moves the file pointer by a number of bytes from its current position.final void
write
(byte[] b) Writes the contents of a byte array into the file.final void
write
(byte[] b, int from, int len) Writes up to the specified number of bytes from a buffer to the stream.final void
write
(int b) Writes a byte.final void
Methods inherited from class nom.tam.util.FitsFile
getDecoder, getEncoder, isAtStart, mark, markSupported, read, read, read, read, read, read, read, read, readArray, readBoolean, readByte, readChar, readDouble, readFloat, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, reset, skipAllBytes, skipBytes, write, write, write, write, write, write, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort
Methods inherited from class nom.tam.util.ArrayDataFile
readArrayFully, readImage, readLArray, writeArray
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface nom.tam.util.ArrayDataInput
read, read, read, read, read, read, read, read, read, readArrayFully, readFully, readImage, readLArray, skip, skipAllBytes
Methods inherited from interface nom.tam.util.ArrayDataOutput
flush, write, write, write, write, write, write, write, write, write, writeArray
Methods inherited from interface java.io.DataOutput
write, write, write, writeUTF
Methods inherited from interface nom.tam.util.InputReader
read, read
Methods inherited from interface nom.tam.util.OutputWriter
write, write
Methods inherited from interface nom.tam.util.RandomAccess
getFilePointer, position, position, seek
Methods inherited from interface nom.tam.util.ReadWriteAccess
length
-
Constructor Details
-
BufferedFile
Deprecated.Constructs a buffered FITS file- Parameters:
file
- the underlying filemode
- the access mode as a string, e.g. "rw"bufferSize
- the buffer size in bytes- Throws:
IOException
- if there was an error opening the file
-
BufferedFile
Deprecated.Constructs a buffered FITS file with the default buffer size.- Parameters:
file
- the underlying filemode
- the access mode as a string, e.g. "rw"- Throws:
IOException
- if there was an error opening the file
-
BufferedFile
Deprecated.Constructs a buffered FITS file with the default buffer size and default access mode.- Parameters:
file
- the underlying file- Throws:
IOException
- if there was an error opening the file
-
BufferedFile
Deprecated.Constructs a buffered FITS file- Parameters:
filename
- the file name / pathmode
- the access mode as a string, e.g. "rw"bufferSize
- the buffer size in bytes- Throws:
IOException
- if there was an error opening the file
-
BufferedFile
Deprecated.Constructs a buffered FITS file with the default buffer size- Parameters:
filename
- the file name / pathmode
- the access mode as a string, e.g. "rw"- Throws:
IOException
- if there was an error opening the file
-
BufferedFile
Deprecated.Constructs a buffered FITS file with the default buffer size and default access mode- Parameters:
filename
- the file name / path- Throws:
IOException
- if there was an error opening the file
-
-
Method Details
-
seek
Sets a new position in the file for subsequent reading or writing.- Parameters:
newPos
- the new byte offset from the beginning of the file. It may be beyond the current end of the file, for example for writing more data after some 'gap'.- Throws:
IOException
- if the position is negative or cannot be set.
-
getChannel
Get the channel associated with this file. Note that this returns the channel of the associated RandomAccessFile. Note that since the BufferedFile buffers the I/O's to the underlying file, the offset of the channel may be different from the offset of the BufferedFile. This is different for a RandomAccessFile where the offsets are guaranteed to be the same.- Returns:
- the file channel
-
getFD
Get the file descriptor associated with this stream. Note that this returns the file descriptor of the associated RandomAccessFile.- Returns:
- the file descriptor
- Throws:
IOException
- if the descriptor could not be accessed.
-
getFilePointer
public final long getFilePointer()Gets the current read/write position in the file.- Returns:
- the current byte offset from the beginning of the file.
-
hasAvailable
Checks if there are the required number of bytes available to read from this file.- Parameters:
need
- the number of bytes we need.- Returns:
true
if the needed number of bytes can be read from the file or elsefalse
.- Throws:
IOException
- if there was an IO error accessing the file.
-
length
Returns the current length of the file.- Returns:
- the current length of the file.
- Throws:
IOException
- if the operation failed
-
setLength
Sets the length of the file. This method calls the method of the same name inRandomAccessFileIO
.- Parameters:
newLength
- The number of bytes at which the file is set.- Throws:
IOException
- if the resizing of the underlying stream fails
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Throws:
IOException
-
write
Description copied from interface:OutputWriter
Writes a byte. See the general contract ofDataOutputStream.write(int)
.- Specified by:
write
in interfaceOutputWriter
- Parameters:
b
- the (unsigned) byte value to write.- Throws:
IOException
- if there was an underlying IO error- See Also:
-
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.
- Throws:
IOException
- if there was an underlying IO error- See Also:
-
write
Description copied from interface:OutputWriter
Writes up to the specified number of bytes from a buffer to the stream. See the general contract ofDataOutputStream.write(byte[], int, int)
.- Specified by:
write
in interfaceOutputWriter
- Parameters:
b
- the bufferfrom
- the starting buffer indexlen
- the number of bytes to write.- Throws:
IOException
- if there was an underlying IO error- See Also:
-
read
Description copied from interface:InputReader
Reads up to the specified number of bytes into a buffer. See the general contract ofDataInputStream.read(byte[], int, int)
.- Specified by:
read
in interfaceInputReader
- Parameters:
b
- the bufferfrom
- the starting buffer indexlen
- the number of bytes to read.- Returns:
- the number of bytes actually read, or -1 if there is nothing left to read.
- Throws:
IOException
- if there was an underlying IO error- See Also:
-
readFully
Reads bytes to completely fill the supplied buffer. If not enough bytes are avaialable in the file to fully fill the buffer, anEOFException
will be thrown.- Parameters:
b
- the buffer- Throws:
EOFException
- if already at the end of file.IOException
- if there was an IO error before the buffer could be fully populated.
-
readFully
Reads bytes to fill the supplied buffer with the requested number of bytes from the given starting buffer index. If not enough bytes are avaialable in the file to deliver the reqauested number of bytes the buffer, anEOFException
will be thrown.- Parameters:
b
- the bufferoff
- the buffer index at which to start reading datalen
- the total number of bytes to read.- Throws:
EOFException
- if already at the end of file.IOException
- if there was an IO error before the requested number of bytes could all be read.
-
readUTF
Same asRandomAccessFile.readUTF()
.- Returns:
- a string
- Throws:
IOException
- if there was an IO error while reading from the file.
-
writeUTF
- Parameters:
s
- a string- Throws:
IOException
- if there was an IO error while writing to the file.
-
skip
Moves the file pointer by a number of bytes from its current position.- Parameters:
n
- the number of byter to move. Negative values are allowed and result in moving the pointer backward.- Returns:
- the actual number of bytes that the pointer moved, which may be fewer than requested if the file boundary was reached.
- Throws:
IOException
- if there was an IO error.
-
read
Read as many bytes into a byte array as possible. The number of bytes read may be fewer than the size of the array, for example because the end-of-file is reached during the read.- Parameters:
b
- the byte buffer to fill with data from the file.- Returns:
- the number of bytes actually read.
- Throws:
IOException
- if there was an IO error while reading, other than the end-of-file.
-
write
Writes the contents of a byte array into the file.- Parameters:
b
- the byte buffer to write into the file.- Throws:
IOException
- if there was an IO error while writing to the file...
-
FitsFile
instead, which replaces the oldBufferedFile
with a less misleading name, or elseArrayDataFile
, which provides a base for a more more generic implementation for efficient reading/writing arrays using any (non-FITS) encoding.