Package nom.tam.util
Class BufferedFile
java.lang.Object
nom.tam.util.BufferedFile
- All Implemented Interfaces:
Closeable
,DataInput
,DataOutput
,AutoCloseable
,ArrayDataInput
,ArrayDataOutput
,FitsIO
,RandomAccess
-
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, HIGH_INTEGER_MASK, INTEGER_MASK, SHORT_MASK, SHORT_OF_LONG_MASK
-
Constructor Summary
ConstructorsConstructorDescriptionBufferedFile
(File file) Create a buffered file from a File descriptorBufferedFile
(File file, String mode) Create a buffered file from a File descriptorBufferedFile
(File file, String mode, int bufferSize) Create a buffered file from a file descriptorBufferedFile
(String filename) Create a read-only buffered fileBufferedFile
(String filename, String mode) Create a buffered file with the given mode.BufferedFile
(String filename, String mode, int bufferSize) Create a buffered file with the given mode and a specified dataBuffer.buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected void
finalize()
void
flush()
Flush the output bufferGet the channel associated with this file.getFD()
Get the file descriptor associated with this stream.long
Get the current offset into the file.long
length()
void
mark
(int readlimit) See the general contract of themark
method ofInputStream
.int
read()
int
read
(boolean[] b) Read an array of boolean's.int
read
(boolean[] b, int start, int length) Read a segment of an array of boolean's.int
read
(byte[] buf) Read an array of byte's.int
read
(byte[] buf, int offset, int len) Read a segment of an array of byte's.int
read
(char[] c) Read an array of char's.int
read
(char[] c, int start, int length) Read a segment of an array of char's.int
read
(double[] d) Read an array of double's.int
read
(double[] d, int start, int length) Read a segment of an array of double's.int
read
(float[] f) Read an array of float's.int
read
(float[] f, int start, int length) Read a segment of an array of float's.int
read
(int[] i) Read an array of int's.int
read
(int[] i, int start, int length) Read a segment of an array of int's.int
read
(long[] l) Read a segment of an array of long's.int
read
(long[] l, int start, int length) Read a segment of an array of long's.int
read
(short[] s) Read an array of short's.int
read
(short[] s, int start, int length) Read a segment of an array of short's.int
Deprecated.boolean
byte
readByte()
char
readChar()
double
float
void
readFully
(byte[] b) void
readFully
(byte[] b, int off, int len) Read a buffer and signal an EOF if the requested elements cannot be read.int
readInt()
long
readLArray
(Object o) Read an object.readLine()
Read a line of input.long
readLong()
short
int
int
readUTF()
void
reset()
See the general contract of thereset
method ofInputStream
.void
seek
(long offsetFromStart) Move to a specified location in the stream.void
setLength
(long newLength) Set the length of the file.long
skip
(long offset) Skip the number of bytes.void
skipAllBytes
(int toSkip) Skip the number of bytes.void
skipAllBytes
(long toSkip) Skip the number of bytes.int
skipBytes
(int n) void
write
(boolean[] b) Write an array of boolean's.void
write
(boolean[] b, int start, int length) Write a segment of an array of boolean's.void
write
(byte[] buf) void
write
(byte[] buf, int offset, int length) void
write
(char[] c) Write an array of char's.void
write
(char[] c, int start, int length) Write a segment of an array of char's.void
write
(double[] d) Write an array of double's.void
write
(double[] d, int start, int length) Write a segment of an array of double's.void
write
(float[] f) Write an array of float's.void
write
(float[] f, int start, int length) Write a segment of an array of float's.void
write
(int buf) void
write
(int[] i) Write an array of int's.void
write
(int[] i, int start, int length) Write a segment of an array of int's.void
write
(long[] l) Write an array of longs.void
write
(long[] l, int start, int length) Write a segment of an array of longs.void
write
(short[] s) Write an array of shorts.void
write
(short[] s, int start, int length) Write a segment of an array of shorts.void
Write an array of Strings.void
Write a segment of an array of Strings.void
writeArray
(Object o) This routine provides efficient writing of arrays of any primitive type.void
writeBoolean
(boolean b) void
writeByte
(int b) void
writeBytes
(String s) void
writeChar
(int c) void
writeChars
(String s) void
writeDouble
(double d) void
writeFloat
(float f) void
writeInt
(int i) void
writeLong
(long l) void
writeShort
(int s) void
-
Constructor Details
-
BufferedFile
Create a buffered file from a File descriptor- Parameters:
file
- the file to open.- Throws:
IOException
- if the file could not be opened
-
BufferedFile
Create a buffered file from a File descriptor- Parameters:
file
- the file to open.mode
- the mode to open the file in- Throws:
IOException
- if the file could not be opened
-
BufferedFile
Create a buffered file from a file descriptor- Parameters:
file
- the file to open.mode
- the mode to open the file inbufferSize
- the dataBuffer.buffer size to use- Throws:
IOException
- if the file could not be opened
-
BufferedFile
Create a read-only buffered file- Parameters:
filename
- the name of the file to open- Throws:
IOException
- if the file could not be opened
-
BufferedFile
Create a buffered file with the given mode.- Parameters:
filename
- The file to be accessed.mode
- A string composed of "r" and "w" for read and write access.- Throws:
IOException
- if the file could not be opened
-
BufferedFile
Create a buffered file with the given mode and a specified dataBuffer.buffer size.- Parameters:
filename
- The file to be accessed.mode
- A string composed of "r" and "w" indicating read or write access.bufferSize
- The dataBuffer.buffer size to be used. This should be substantially larger than 100 bytes and defaults to 32768 bytes in the other constructors.- Throws:
IOException
- if the file could not be opened
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceFitsIO
- Throws:
IOException
-
finalize
protected void finalize() -
flush
Description copied from interface:ArrayDataOutput
Flush the output buffer- Specified by:
flush
in interfaceArrayDataOutput
- Throws:
IOException
- if the flush of the underlying stream failed
-
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 than the offset of the BufferedFile. This is different than 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 long getFilePointer()Get the current offset into the file.- Specified by:
getFilePointer
in interfaceRandomAccess
- Returns:
- the current position in the stream.
-
length
- Returns:
- the current length of the file.
- Throws:
IOException
- if the operation failed
-
mark
Description copied from interface:ArrayDataInput
See the general contract of themark
method ofInputStream
.- Specified by:
mark
in interfaceArrayDataInput
- Parameters:
readlimit
- the maximum limit of bytes that can be read before the mark position becomes invalid.- Throws:
IOException
- if the operation failed- See Also:
-
read
- Returns:
- Read a byte.
- Throws:
IOException
- if the underlying read operation fails
-
read
Description copied from interface:ArrayDataInput
Read an array of boolean's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
b
- array of boolean's.- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of boolean's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
b
- array of boolean's.start
- start index in the arraylength
- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read an array of byte's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
buf
- array of byte's.- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed- See Also:
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of byte's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
buf
- array of byte's.offset
- start index in the arraylen
- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed- See Also:
-
read
Description copied from interface:ArrayDataInput
Read an array of char's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
c
- array of char's.- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of char's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
c
- array of char's.start
- start index in the arraylength
- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read an array of double's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
d
- array of double's.- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of double's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
d
- array of double's.start
- start index in the arraylength
- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read an array of float's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
f
- array of float's.- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of float's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
f
- array of float's.start
- start index in the arraylength
- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read an array of int's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
i
- array of int's.- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of int's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
i
- array of int's.start
- start index in the arraylength
- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of long's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
l
- array of long's.- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of long's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
l
- array of long's.start
- start index in the arraylength
- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read an array of short's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
s
- array of short's.- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of short's.- Specified by:
read
in interfaceArrayDataInput
- Parameters:
s
- array of short's.start
- start index in the arraylength
- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException
- if one of the underlying read operations failed
-
readArray
Deprecated.Description copied from interface:ArrayDataInput
Read a generic (possibly multidimensional) primitive array. An Object[] array is also a legal argument if each element of the array is a legal.The ArrayDataInput classes do not support String input since it is unclear how one would read in an Array of strings.
- Specified by:
readArray
in interfaceArrayDataInput
- Parameters:
o
- A [multidimensional] primitive (or Object) array.- Returns:
- number of bytes read.
- Throws:
IOException
- if the underlying stream failed
-
readBoolean
- Specified by:
readBoolean
in interfaceDataInput
- Throws:
IOException
-
readByte
- Specified by:
readByte
in interfaceDataInput
- Throws:
IOException
-
readChar
- Specified by:
readChar
in interfaceDataInput
- Throws:
IOException
-
readDouble
- Specified by:
readDouble
in interfaceDataInput
- Throws:
IOException
-
readFloat
- Specified by:
readFloat
in interfaceDataInput
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
readFully
Description copied from interface:ArrayDataInput
Read a buffer and signal an EOF if the requested elements cannot be read. This differs from read(b,off,len) since that call will not signal and end of file unless no bytes can be read. However both of these routines will attempt to fill their buffers completely.- Specified by:
readFully
in interfaceArrayDataInput
- Specified by:
readFully
in interfaceDataInput
- Parameters:
b
- The input buffer.off
- The requested offset into the buffer.len
- The number of bytes requested.- Throws:
IOException
-
readInt
- Specified by:
readInt
in interfaceDataInput
- Throws:
IOException
-
readLArray
Description copied from interface:ArrayDataInput
Read an object. An EOF will be signaled if the object cannot be fully read. This version works even if the underlying data is more than 2 Gigabytes.- Specified by:
readLArray
in interfaceArrayDataInput
- Parameters:
o
- The object to be read. This object should be a primitive (possibly multi-dimensional) array.- Returns:
- number of bytes read.
- Throws:
IOException
- if the underlying stream failed
-
readLine
Read a line of input.- Specified by:
readLine
in interfaceDataInput
- Returns:
- the next line.
- Throws:
IOException
-
readLong
- Specified by:
readLong
in interfaceDataInput
- Throws:
IOException
-
readShort
- Specified by:
readShort
in interfaceDataInput
- Throws:
IOException
-
readUnsignedByte
- Specified by:
readUnsignedByte
in interfaceDataInput
- Throws:
IOException
-
readUnsignedShort
- Specified by:
readUnsignedShort
in interfaceDataInput
- Throws:
IOException
-
readUTF
- Specified by:
readUTF
in interfaceDataInput
- Throws:
IOException
-
reset
Description copied from interface:ArrayDataInput
See the general contract of thereset
method ofInputStream
.If
markpos
is-1
(no mark has been set or the mark has been invalidated), anIOException
is thrown. Otherwise,pos
is set equal tomarkpos
.- Specified by:
reset
in interfaceArrayDataInput
- Throws:
IOException
- if this stream has not been marked or, if the mark has been invalidated, or the stream has been closed by invoking itsFitsIO.close()
method, or an I/O error occurs.- See Also:
-
seek
Description copied from interface:RandomAccess
Move to a specified location in the stream.- Specified by:
seek
in interfaceRandomAccess
- Parameters:
offsetFromStart
- set the offset messured from the start- Throws:
IOException
- if the operation fails
-
setLength
Set the length of the file. This method calls the method of the same name in RandomAccessFile which is only available in JDK1.2 and greater. This method may be deleted for compilation with earlier versions.- Parameters:
newLength
- The number of bytes at which the file is set.- Throws:
IOException
- if the resizing of the underlying stream fails
-
skip
Description copied from interface:ArrayDataInput
Skip the number of bytes. This differs from the skip method in that it will throw an EOF if a forward skip cannot be fully accomplished... (However that isn't supposed to happen with a random access file, so there is probably no operational difference).- Specified by:
skip
in interfaceArrayDataInput
- Parameters:
offset
- the number of bytes to skip- Returns:
- the number of bytes really skipped
- Throws:
IOException
- if the underlying stream failed
-
skipAllBytes
Description copied from interface:ArrayDataInput
Skip the number of bytes. This differs from the skip method in that it will throw an EOF if a forward skip cannot be fully accomplished... (However that isn't supposed to happen with a random access file, so there is probably no operational difference).- Specified by:
skipAllBytes
in interfaceArrayDataInput
- Parameters:
toSkip
- the number of bytes to skip- Throws:
IOException
- if the underlying stream failed
-
skipAllBytes
Description copied from interface:ArrayDataInput
Skip the number of bytes. This differs from the skip method in that it will throw an EOF if a forward skip cannot be fully accomplished... (However that isn't supposed to happen with a random access file, so there is probably no operational difference).- Specified by:
skipAllBytes
in interfaceArrayDataInput
- Parameters:
toSkip
- the number of bytes to skip- Throws:
IOException
- if the underlying stream failed
-
skipBytes
- Specified by:
skipBytes
in interfaceDataInput
- Throws:
IOException
-
write
Description copied from interface:ArrayDataOutput
Write an array of boolean's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
b
- array of boolean's.- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of boolean's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
b
- array of boolean's.start
- start index in the arraylength
- number of array elements to write- Throws:
IOException
- if one of the underlying write operations failed
-
write
- Specified by:
write
in interfaceDataOutput
- Throws:
IOException
-
write
- Specified by:
write
in interfaceDataOutput
- Throws:
IOException
-
write
Description copied from interface:ArrayDataOutput
Write an array of char's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
c
- array of char's.- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of char's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
c
- array of char's.start
- start index in the arraylength
- number of array elements to write- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write an array of double's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
d
- array of double's.- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of double's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
d
- array of double's.start
- start index in the arraylength
- number of array elements to write- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write an array of float's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
f
- array of float's.- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of float's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
f
- array of float's.start
- start index in the arraylength
- number of array elements to write- Throws:
IOException
- if one of the underlying write operations failed
-
write
- Specified by:
write
in interfaceDataOutput
- Throws:
IOException
-
write
Description copied from interface:ArrayDataOutput
Write an array of int's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
i
- array of int's- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of int's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
i
- array of int'sstart
- start index in the arraylength
- number of array elements to write- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write an array of longs.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
l
- array of longs- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of longs.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
l
- array of longsstart
- start index in the arraylength
- number of array elements to write- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write an array of shorts.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
s
- the value to write- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of shorts.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
s
- the value to writestart
- start index in the arraylength
- number of array elements to write- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write an array of Strings. Equivalent to calling writeBytes for the selected elements.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
s
- the array to write- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of Strings. Equivalent to calling writeBytes for the selected elements.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
s
- the array to writestart
- start index in the arraylength
- number of array elements to write- Throws:
IOException
- if one of the underlying write operations failed
-
writeArray
Description copied from interface:ArrayDataOutput
This routine provides efficient writing of arrays of any primitive type. The String class is also handled but it is an error to invoke this method with an object that is not an array of these types. If the array is multidimensional, then it calls itself recursively to write the entire array. Strings are written using the standard 1 byte format (i.e., as in writeBytes). If the array is an array of objects, then writePrimitiveArray will be called for each element of the array.- Specified by:
writeArray
in interfaceArrayDataOutput
- Parameters:
o
- The object to be written. It must be an array of a primitive type, Object, or String.- Throws:
IOException
- if one of the underlying write operations failed
-
writeBoolean
- Specified by:
writeBoolean
in interfaceDataOutput
- Throws:
IOException
-
writeByte
- Specified by:
writeByte
in interfaceDataOutput
- Throws:
IOException
-
writeBytes
- Specified by:
writeBytes
in interfaceDataOutput
- Throws:
IOException
-
writeChar
- Specified by:
writeChar
in interfaceDataOutput
- Throws:
IOException
-
writeChars
- Specified by:
writeChars
in interfaceDataOutput
- Throws:
IOException
-
writeDouble
- Specified by:
writeDouble
in interfaceDataOutput
- Throws:
IOException
-
writeFloat
- Specified by:
writeFloat
in interfaceDataOutput
- Throws:
IOException
-
writeInt
- Specified by:
writeInt
in interfaceDataOutput
- Throws:
IOException
-
writeLong
- Specified by:
writeLong
in interfaceDataOutput
- Throws:
IOException
-
writeShort
- Specified by:
writeShort
in interfaceDataOutput
- Throws:
IOException
-
writeUTF
- Specified by:
writeUTF
in interfaceDataOutput
- Throws:
IOException
-