Class LocalDataFileHandle
- All Implemented Interfaces:
DataFileHandle
LocalDataFileHandle
provides random access to
a local File.-
Constructor Summary
ConstructorDescriptionLocalDataFileHandle
(File file, boolean readOnly) Construct and open a local DataFileHandle. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this random access file stream and releases any system resources associated with the stream.boolean
Returns true if this data file handle is open read-only.long
length()
Returns the length of this file.void
read
(byte[] b) Readsb.length
bytes from this file into the byte array, starting at the current file pointer.void
read
(byte[] b, int off, int len) Reads exactlylen
bytes from this file into the byte array, starting at the current file pointer.void
seek
(long pos) Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.void
setLength
(long newLength) Sets the length of this file.int
skipBytes
(int n) Attempts to skip overn
bytes of input discarding the skipped bytes.void
write
(byte[] b) Writesb.length
bytes from the specified byte array to this file, starting at the current file pointer.void
write
(byte[] b, int off, int len) Writeslen
bytes from the specified byte array starting at offsetoff
to this file.void
write
(int b) Writes the specified byte to this file.
-
Constructor Details
-
LocalDataFileHandle
Construct and open a local DataFileHandle.- Parameters:
file
- file to be openedreadOnly
- if true resulting handle may only be read.- Throws:
FileNotFoundException
- if file was not foundIOException
- if an IO Error occurs
-
-
Method Details
-
read
Description copied from interface:DataFileHandle
Readsb.length
bytes from this file into the byte array, starting at the current file pointer. This method reads repeatedly from the file until the requested number of bytes are read. This method blocks until the requested number of bytes are read, the end of the stream is detected, or an exception is thrown.- Specified by:
read
in interfaceDataFileHandle
- Parameters:
b
- the buffer into which the data is read.- Throws:
IOException
- if an I/O error occurs.
-
read
Description copied from interface:DataFileHandle
Reads exactlylen
bytes from this file into the byte array, starting at the current file pointer. This method reads repeatedly from the file until the requested number of bytes are read. This method blocks until the requested number of bytes are read, the end of the stream is detected, or an exception is thrown.- Specified by:
read
in interfaceDataFileHandle
- Parameters:
b
- the buffer into which the data is read.off
- the start offset of the data.len
- the number of bytes to read.- Throws:
IOException
- if an I/O error occurs.
-
skipBytes
Description copied from interface:DataFileHandle
Attempts to skip overn
bytes of input discarding the skipped bytes.This method may skip over some smaller number of bytes, possibly zero. This may result from any of a number of conditions; reaching end of file before
n
bytes have been skipped is only one possibility. This method never throws anEOFException
. The actual number of bytes skipped is returned. Ifn
is negative, no bytes are skipped.- Specified by:
skipBytes
in interfaceDataFileHandle
- Parameters:
n
- the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
- Throws:
IOException
- if an I/O error occurs.
-
write
Description copied from interface:DataFileHandle
Writes the specified byte to this file. The write starts at the current file pointer.- Specified by:
write
in interfaceDataFileHandle
- Parameters:
b
- thebyte
to be written.- Throws:
IOException
- if an I/O error occurs.
-
write
Description copied from interface:DataFileHandle
Writesb.length
bytes from the specified byte array to this file, starting at the current file pointer.- Specified by:
write
in interfaceDataFileHandle
- Parameters:
b
- the data.- Throws:
IOException
- if an I/O error occurs.
-
write
Description copied from interface:DataFileHandle
Writeslen
bytes from the specified byte array starting at offsetoff
to this file.- Specified by:
write
in interfaceDataFileHandle
- Parameters:
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.- Throws:
IOException
- if an I/O error occurs.
-
seek
Description copied from interface:DataFileHandle
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs. The offset may be set beyond the end of the file. Setting the offset beyond the end of the file does not change the file length. The file length will change only by writing after the offset has been set beyond the end of the file.- Specified by:
seek
in interfaceDataFileHandle
- Parameters:
pos
- the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.- Throws:
IOException
- ifpos
is less than0
or if an I/O error occurs.
-
length
Description copied from interface:DataFileHandle
Returns the length of this file.- Specified by:
length
in interfaceDataFileHandle
- Returns:
- the length of this file, measured in bytes.
- Throws:
IOException
- if an I/O error occurs.
-
setLength
Description copied from interface:DataFileHandle
Sets the length of this file.If the present length of the file as returned by the
length
method is greater than thenewLength
argument then the file will be truncated. In this case, if the file offset as returned by thegetFilePointer
method is greater thennewLength
then after this method returns the offset will be equal tonewLength
.If the present length of the file as returned by the
length
method is smaller than thenewLength
argument then the file will be extended. In this case, the contents of the extended portion of the file are not defined.- Specified by:
setLength
in interfaceDataFileHandle
- Parameters:
newLength
- The desired length of the file- Throws:
IOException
- If an I/O error occurs
-
close
Description copied from interface:DataFileHandle
Closes this random access file stream and releases any system resources associated with the stream. A closed random access file cannot perform input or output operations and cannot be reopened.- Specified by:
close
in interfaceDataFileHandle
- Throws:
IOException
- if an I/O error occurs.
-
isReadOnly
Description copied from interface:DataFileHandle
Returns true if this data file handle is open read-only.- Specified by:
isReadOnly
in interfaceDataFileHandle
- Throws:
IOException
- if an I/O error occurs.
-