Package oracle.spatial.util
Class BufferedRandomAccessFile
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- java.io.BufferedInputStream
-
- oracle.spatial.util.BufferedRandomAccessFile
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class BufferedRandomAccessFile extends java.io.BufferedInputStreamBufferedInputStreamimpl with similar facilities as aRandomAccessFile. The advantage is that this class allows buffering larger byte streams from the file upfront, reducing thus the total IO operations to read an entire file.BufferedInputStreamcan be used only for read-operations.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BUFFER_SIZE_BYTES
-
Constructor Summary
Constructors Constructor Description BufferedRandomAccessFile(java.io.File file)Same asBufferedRandomAccessFile(String, int)except that it will use theDEFAULT_BUFFER_SIZE_BYTESforbufferSizeparameter.BufferedRandomAccessFile(java.io.File file, int bufferSize)Creates aBufferedRandomAccessFilewith the specified buffer size, and creates an input stream from thefileargument, which is saved for later use.BufferedRandomAccessFile(java.lang.String file)Same asBufferedRandomAccessFile(String, int)except that it will create aFileobject from thefilestring parameter and it will use theDEFAULT_BUFFER_SIZE_BYTESforbufferSizeparameter.BufferedRandomAccessFile(java.lang.String file, int bufferSize)Same asBufferedRandomAccessFile(File, int)except it will create aFileobject from thefilestring parameter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intbufferSize()Retrieves the buffer size used by this instance.voidclose()Closes this random access file stream and releases any system resources associated with the stream.java.io.FileDescriptorgetFD()Returns the opaque file descriptor object associated with this stream.longgetFilePointer()Returns the current offset in this file.longlength()Returns the length of this file.intread()intread(byte[] b)intread(byte[] b, int off, int len)intreadInt()Reads a signed 32-bit integer from this file.voidresetBufferPositions()Discards the buffer data, by setting the internalposandcountfrom inherited fromBufferedInputStreamback to0.voidseek(long newPosition)Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs, and resets the internal buffer.longskip(long n)
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE_BYTES
public static final int DEFAULT_BUFFER_SIZE_BYTES
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BufferedRandomAccessFile
public BufferedRandomAccessFile(java.lang.String file) throws java.io.IOExceptionSame asBufferedRandomAccessFile(String, int)except that it will create aFileobject from thefilestring parameter and it will use theDEFAULT_BUFFER_SIZE_BYTESforbufferSizeparameter.- Throws:
java.io.IOException
-
BufferedRandomAccessFile
public BufferedRandomAccessFile(java.lang.String file, int bufferSize) throws java.io.IOExceptionSame asBufferedRandomAccessFile(File, int)except it will create aFileobject from thefilestring parameter.- Throws:
java.io.IOException
-
BufferedRandomAccessFile
public BufferedRandomAccessFile(java.io.File file) throws java.io.IOExceptionSame asBufferedRandomAccessFile(String, int)except that it will use theDEFAULT_BUFFER_SIZE_BYTESforbufferSizeparameter.- Throws:
java.io.IOException
-
BufferedRandomAccessFile
public BufferedRandomAccessFile(java.io.File file, int bufferSize) throws java.io.IOExceptionCreates aBufferedRandomAccessFilewith the specified buffer size, and creates an input stream from thefileargument, which is saved for later use. An internal buffer array of lengthbufferSizeis created and stored inbuf.- Parameters:
file- the file object from which the underlying input stream will be created.bufferSize- the buffer size.- Throws:
java.lang.IllegalArgumentException- iffileis null or ifbufferSizeis equal to or less than zero.java.io.FileNotFoundException- if the given file object does not denote an existing regular file, or if some other error occurs while opening the file.java.lang.SecurityException- if a security manager exists and itscheckReadmethod denies read access to the file.java.io.IOException
-
-
Method Detail
-
close
public void close() throws java.io.IOExceptionCloses 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.If this file has an associated channel then the channel is closed as well.
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.BufferedInputStream- Throws:
java.io.IOException- if an I/O error occurs.
-
getFilePointer
public long getFilePointer() throws java.io.IOExceptionReturns the current offset in this file.- Returns:
- the offset from the beginning of the file, in bytes, at which the next read or write occurs.
- Throws:
java.io.IOException- if an I/O error occurs.
-
getFD
public java.io.FileDescriptor getFD() throws java.io.IOExceptionReturns the opaque file descriptor object associated with this stream.- Returns:
- the file descriptor object associated with this stream.
- Throws:
java.io.IOException- if an I/O error occurs.- See Also:
FileDescriptor
-
length
public long length() throws java.io.IOExceptionReturns the length of this file.- Returns:
- the length of this file, measured in bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
seek
public void seek(long newPosition) throws java.io.IOExceptionSets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs, and resets the internal buffer. 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.- Parameters:
newPosition- the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.- Throws:
java.io.IOException- ifnewPositionis less than0or if an I/O error occurs.
-
resetBufferPositions
public void resetBufferPositions()
Discards the buffer data, by setting the internalposandcountfrom inherited fromBufferedInputStreamback to0.
-
bufferSize
public int bufferSize()
Retrieves the buffer size used by this instance.- Returns:
- the number of bytes reserved for buffering.
-
read
public int read() throws java.io.IOException- Overrides:
readin classjava.io.BufferedInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.BufferedInputStream- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException- Overrides:
skipin classjava.io.BufferedInputStream- Throws:
java.io.IOException
-
readInt
public int readInt() throws java.io.IOExceptionReads a signed 32-bit integer from this file. This method reads 4 bytes from the file, starting at the current file pointer. If the bytes read, in order, areb1,b2,b3, andb4, where0 <= b1, b2, b3, b4 <= 255, then the result is equal to:(b1 << 24) | (b2 << 16) + (b3 << 8) + b4This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
- Returns:
- the next four bytes of this file, interpreted as an
int. - Throws:
java.io.EOFException- if this file reaches the end before reading four bytes.java.io.IOException- if an I/O error occurs.
-
-