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
-
Field Summary
Fields inherited from interface 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_MASKModifier and TypeFieldDescriptionstatic final intnumber of bits in one byte.static final intnumber of bits in two byte.static final intnumber of bits in three byte.static final intnumber of bits in four byte.static final intnumber of bits in five byte.static final intnumber of bits in six byte.static final intnumber of bits in seven byte.static final longbit mask to get the lowest byte of a long.static final longbit mask to get the second lowest byte of a long.static final longbit mask to get the third lowest byte of a long.static final longbit mask to get the fourth lowest byte of a long.static final intbit mask to get the lowest byte from an integer.static final intnumber of bytes occupied by a boolean.static final intnumber of bytes occupied by a byte.static final intnumber of bytes occupied by a char.static final intnumber of bytes occupied by a double.static final intnumber of bytes occupied by a float.static final intnumber of bytes occupied by a integer.static final intnumber of bytes occupied by a long.static final intnumber of bytes occupied by a short.static final intdefault buffer size to use unless specified otherwise.static final longbit mask to get the highest integer from an long.static final longbit mask to get the lowest integer from an long.static final intbit mask to get the lowest short of a integer.static final longbit mask to get the lowest short of a long. -
Constructor Summary
ConstructorsConstructorDescriptionBufferedFile(File file) Deprecated.BufferedFile(File file, String mode) Deprecated.BufferedFile(File file, String mode, int bufferSize) Deprecated.BufferedFile(String filename) Deprecated.BufferedFile(String filename, String mode) Deprecated.BufferedFile(String filename, String mode, int bufferSize) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()final FileChannelGet the channel associated with this file.final FileDescriptorgetFD()Get the file descriptor associated with this stream.final longGets the current read/write position in the file.final booleanhasAvailable(int need) Checks if there are the required number of bytes available to read from this file.final longlength()Returns the current length of the file.final intread()Reads a byte.final intread(byte[] b) Read as many bytes into a byte array as possible.final intread(byte[] b, int from, int len) Reads up to the specified number of bytes into a buffer.final voidreadFully(byte[] b) Reads bytes to completely fill the supplied buffer.voidreadFully(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 StringreadUTF()Same asRandomAccessFile.readUTF().final voidseek(long newPos) Sets a new position in the file for subsequent reading or writing.voidsetLength(long newLength) Sets the length of the file.final longskip(long n) Moves the file pointer by a number of bytes from its current position.final voidwrite(byte[] b) Writes the contents of a byte array into the file.final voidwrite(byte[] b, int from, int len) Writes up to the specified number of bytes from a buffer to the stream.final voidwrite(int b) Writes a byte.final voidMethods inherited from class 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, writeShortModifier and TypeMethodDescriptionReturns the conversion from the binary representation of arrays in file to Java arrays.Returns the conversion from Java arrays to their binary representation in file.booleanChecks whether we are currently at the start of this output file or stream.voidmark(int readlimit) See the general contract of themarkmethod ofInputStream.booleanSee the general contract of themarkSupportedmethod ofInputStream.intread(boolean[] b, int start, int length) Read a segment of an array of boolean's.intread(char[] c, int start, int length) Read a segment of an array of char's.intread(double[] d, int start, int length) Read a segment of an array of double's.intread(float[] f, int start, int length) Read a segment of an array of float's.intread(int[] i, int start, int length) Read a segment of an array of int's.intread(long[] l, int start, int length) Read a segment of an array of long's.intread(short[] s, int start, int length) Read a segment of an array of short's.intReads into an array of booleans, possibly including legalnullvalues.final intDeprecated.booleanfinal bytereadByte()charreadChar()final doublefinal floatfinal intreadInt()readLine()final longreadLong()final shortfinal intfinal intvoidreset()See the general contract of theresetmethod ofInputStream.voidskipAllBytes(long toSkip) Skips a number of bytes from the input.intskipBytes(int toSkip) voidwrite(boolean[] b, int start, int length) Write a segment of an array of boolean's.voidwrite(char[] c, int start, int length) Write a segment of an array of char's.voidwrite(double[] d, int start, int length) Write a segment of an array of double's.voidwrite(float[] f, int start, int length) Write a segment of an array of float's.voidwrite(int[] i, int start, int length) Write a segment of an array of int's.voidwrite(long[] l, int start, int length) Write a segment of an array of longs.voidwrite(short[] s, int start, int length) Write a segment of an array of shorts.voidWrite a segment of an array of booleans, possibly including legalnullvalues.voidWrite a segment of an array of Strings.voidwriteBoolean(boolean v) final voidwriteByte(int v) final voidwriteBytes(String s) voidwriteChar(int v) final voidwriteChars(String s) final voidwriteDouble(double v) final voidwriteFloat(float v) final voidwriteInt(int v) final voidwriteLong(long v) final voidwriteShort(int v) Methods inherited from class ArrayDataFile
readArrayFully, readImage, readLArray, writeArrayModifier and TypeMethodDescriptionvoidSeeArrayDataInput.readArrayFully(Object)for a contract of this method.voidLikeArrayDataFile.readArrayFully(Object)but strictly for numerical types only.longreadLArray(Object o) SeeArrayDataInput.readLArray(Object)for a contract of this method.voidwriteArray(Object o) SeeArrayDataOutput.writeArray(Object)for a contract of this method.Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ArrayDataInput
read, read, read, read, read, read, read, read, read, readArrayFully, readFully, readImage, readLArray, skip, skipAllBytesModifier and TypeMethodDescriptiondefault intread(boolean[] buf) Read an array of boolean's.intread(byte[] buf) Read an array of byte's.default intread(char[] buf) Read an array of char's.default intread(double[] buf) Read an array of double's.default intread(float[] buf) Read an array of float's.default intread(int[] buf) Read an array of int's.default intread(long[] buf) Read a segment of an array of long's.default intread(short[] buf) Read an array of short's.default intRead an array of booleans, possibly including legalnullvalues.default voidReads a Java array from the input, populating all elements, or else throwing andEOFException.voidreadFully(byte[] b, int off, int len) default voidLikeArrayDataInput.readArrayFully(Object)but strictly for numerical types only.longreadLArray(Object o) Reads a Java array from the input, translating it from its binary representation to Java data format.longskip(long distance) Skip the number of bytes.default voidskipAllBytes(int toSkip) Deprecated.This call is handled byArrayDataInput.skipAllBytes(long), without the need for a separate implementation.Methods inherited from interface ArrayDataOutput
flush, write, write, write, write, write, write, write, write, write, writeArrayModifier and TypeMethodDescriptionvoidflush()Flush the output bufferdefault voidwrite(boolean[] buf) Write an array of boolean's.default voidwrite(char[] buf) Write an array of char's.default voidwrite(double[] buf) Write an array of double's.default voidwrite(float[] buf) Write an array of float's.default voidwrite(int[] buf) Write an array of int's.default voidwrite(long[] buf) Write an array of longs.default voidwrite(short[] buf) Write an array of shorts.default voidWrite an array of booleans, including legalnullvalues.default voidWrite an array of Strings.voidwriteArray(Object o) Writes the contents of a Java array to the output translating the data to the required binary representation.Methods inherited from interface DataOutput
write, write, write, writeUTFMethods inherited from interface RandomAccess
getFilePointer, position, position, seekModifier and TypeMethodDescriptionlongReturns the current offset from the beginning of the input.default longposition()Returns the current read/write position in this instance.default voidposition(long pos) Sets a new position for the next read or write in this instance.voidseek(long offsetFromStart) Move to a specified location in the stream.Methods inherited from interface ReadWriteAccess
lengthModifier and TypeMethodDescriptionlonglength()Returns the current total length of this instance, that is the total number of bytes that may be read from it.
-
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:
trueif 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Throws:
IOException
-
write
Description copied from interface:OutputWriterWrites a byte. See the general contract ofDataOutputStream.write(int).- Specified by:
writein 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: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.
- Throws:
IOException- if there was an underlying IO error- See Also:
-
write
Description copied from interface:OutputWriterWrites up to the specified number of bytes from a buffer to the stream. See the general contract ofDataOutputStream.write(byte[], int, int).- Specified by:
writein 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:InputReaderReads up to the specified number of bytes into a buffer. See the general contract ofDataInputStream.read(byte[], int, int).- Specified by:
readin 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, anEOFExceptionwill 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, anEOFExceptionwill 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...
-
FitsFileinstead, which replaces the oldBufferedFilewith 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.