Class MultiBufferedRandomAccessFile
- All Implemented Interfaces:
Closeable
,DataInput
,DataOutput
,AutoCloseable
- Author:
- Andrew Pavlin, KA2DDO
-
Constructor Summary
ConstructorDescriptionMultiBufferedRandomAccessFile
(File file, int bufSize, int maxBuffers) Create a read-only random access file with the specified maximum number of buffers of the specified size.MultiBufferedRandomAccessFile
(File file, int bufSize, int maxBuffers, boolean isWriteable) Create a read-only or read-write random access file with the specified maximum number of buffers of the specified size.MultiBufferedRandomAccessFile
(File file, int bufSize, int maxBuffers, boolean isWriteable, boolean flushUnloadedBuffers) Create a read-only or read-write random access file with the specified maximum number of buffers of the specified size.MultiBufferedRandomAccessFile
(File file, int bufSize, int maxBuffers, boolean isWriteable, boolean flushUnloadedBuffers, boolean trackReloadedBlocks) Create a read-only or read-write random access file with the specified maximum number of buffers of the specified size.MultiBufferedRandomAccessFile
(File file, int bufSize, int maxBuffers, boolean isWriteable, byte[] prefillPattern) Create a read-only or read-write random access file with the specified maximum number of buffers of the specified size.MultiBufferedRandomAccessFile
(File file, int bufSize, int maxBuffers, boolean isWriteable, byte[] prefillPattern, boolean trackReloadedBlocks) Create a read-only or read-write random access file with the specified maximum number of buffers of the specified size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear the cache buffers.void
close()
Closes this file and releases any system resources associated with the buffering.void
flush()
Flush all "dirty" (modified) buffers.long
Returns the current offset in this file.int
Get number of consecutive times a read matched data already in the buffers or a write overwrote data already in the buffers.int
Get the number of times write-modified buffers had to be flushed to disk.long
Get number of times a read matched data already in the buffers or a write overwrote data already in the buffers.long
Get the number of times a read or write required loading a buffer from disk.int
Get the number of times a block that had already been read into a buffer was read again.Get the RandomAccessFile underlying this MultiBufferedRandomAccessFile.int
read()
Reads the next byte in the file at the current seek position.boolean
See the general contract of thereadBoolean
method ofDataInput
.byte
readByte()
See the general contract of thereadByte
method ofDataInput
.char
readChar()
See the general contract of thereadChar
method ofDataInput
.double
See the general contract of thereadDouble
method ofDataInput
.float
See the general contract of thereadFloat
method ofDataInput
.void
readFully
(byte[] b) See the general contract of thereadFully
method ofDataInput
.void
readFully
(byte[] b, int off, int len) See the general contract of thereadFully
method ofDataInput
.int
readInt()
See the general contract of thereadInt
method ofDataInput
.int
readIntAt
(long seekPos) Bytes for this operation are read from the contained file.readLine()
See the general contract of thereadLine
method ofDataInput
.long
readLong()
See the general contract of thereadLong
method ofDataInput
.int
This is similar toreadInt()
, but the caller must guarantee that noseek(long)
occurred between the last call to readInt() or readNextInt() and this one.short
See the general contract of thereadShort
method ofDataInput
.int
See the general contract of thereadUnsignedByte
method ofDataInput
.int
See the general contract of thereadUnsignedShort
method ofDataInput
.readUTF()
See the general contract of thereadUTF
method ofDataInput
.void
If being used, clear the history of already-accessed pages.void
Reset the statistics counters that are reported by the toString() method.void
seek
(long seekPos) Sets the file-pointer offset, measured from the beginning of this file, at which the next read occurs.int
skipBytes
(int n) See the general contract of theskipBytes
method ofDataInput
.toString()
Returns a string representation of the object.void
write
(byte[] b) Writes to the output stream all the bytes in arrayb
.void
write
(byte[] b, int off, int len) Writeslen
bytes from arrayb
, in order, to the output stream.void
write
(int b) Writes to the output stream the eight low-order bits of the argumentb
.void
write2Int
(int v1, int v2) Writes 2int
values, each of which is comprised of four bytes, to the output stream.void
write2Int
(long seekPos, int v1, int v2) Sets the file-pointer offset, measured from the beginning of this file, at which the next read occurs.void
writeBoolean
(boolean v) Writes aboolean
value to this output stream.void
writeByte
(int v) Writes to the output stream the eight low- order bits of the argumentv
.void
writeBytes
(String s) Writes a string to the output stream.void
writeChar
(int v) Writes achar
value, which is comprised of two bytes, to the output stream.void
writeChars
(String s) Writes every character in the strings
, to the output stream, in order, two bytes per character.void
writeDouble
(double v) Writes adouble
value, which is comprised of eight bytes, to the output stream.void
writeFloat
(float v) Writes afloat
value, which is comprised of four bytes, to the output stream.void
writeInt
(int v) Writes anint
value, which is comprised of four bytes, to the output stream.void
writeLong
(long v) Writes along
value, which is comprised of eight bytes, to the output stream.void
writeShort
(int v) Writes two bytes to the output stream to represent the value of the argument.void
Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in the strings
.
-
Constructor Details
-
MultiBufferedRandomAccessFile
Create a read-only random access file with the specified maximum number of buffers of the specified size.- Parameters:
file
- File pointing at the disk file to readbufSize
- size of each buffer in bytes (must be a power of 2)maxBuffers
- maximum number of buffers to use- Throws:
IOException
- if file cannot be opened for read-only access
-
MultiBufferedRandomAccessFile
public MultiBufferedRandomAccessFile(File file, int bufSize, int maxBuffers, boolean isWriteable) throws IOException Create a read-only or read-write random access file with the specified maximum number of buffers of the specified size.- Parameters:
file
- File pointing at the disk file to readbufSize
- size of each buffer in bytes (must be a power of 2)maxBuffers
- maximum number of buffers to useisWriteable
- boolean true if this file can be written to- Throws:
IOException
- if file cannot be opened for the requested access
-
MultiBufferedRandomAccessFile
public MultiBufferedRandomAccessFile(File file, int bufSize, int maxBuffers, boolean isWriteable, boolean flushUnloadedBuffers) throws IOException Create a read-only or read-write random access file with the specified maximum number of buffers of the specified size.- Parameters:
file
- File pointing at the disk file to readbufSize
- size of each buffer in bytes (must be a power of 2)maxBuffers
- maximum number of buffers to useisWriteable
- boolean true if this file can be written toflushUnloadedBuffers
- specify whether capable systems should flush released buffers from kernel filesystem cache to reduce cache overgrowth- Throws:
IOException
- if file cannot be opened for the requested access
-
MultiBufferedRandomAccessFile
public MultiBufferedRandomAccessFile(File file, int bufSize, int maxBuffers, boolean isWriteable, boolean flushUnloadedBuffers, boolean trackReloadedBlocks) throws IOException Create a read-only or read-write random access file with the specified maximum number of buffers of the specified size.- Parameters:
file
- File pointing at the disk file to readbufSize
- size of each buffer in bytes (must be a power of 2)maxBuffers
- maximum number of buffers to useisWriteable
- boolean true if this file can be written toflushUnloadedBuffers
- specify whether capable systems should flush released buffers from kernel filesystem cache to reduce cache overgrowthtrackReloadedBlocks
- boolean true if rereads of blocks should be tracked, false if not- Throws:
IOException
- if file cannot be opened for the requested access
-
MultiBufferedRandomAccessFile
public MultiBufferedRandomAccessFile(File file, int bufSize, int maxBuffers, boolean isWriteable, byte[] prefillPattern) throws IOException Create a read-only or read-write random access file with the specified maximum number of buffers of the specified size.- Parameters:
file
- File pointing at the disk file to readbufSize
- size of each buffer in bytes (must be a power of 2)maxBuffers
- maximum number of buffers to useisWriteable
- boolean true if this file can be written toprefillPattern
- byte array to iteratively write to a new buffer as a fill pattern- Throws:
IOException
- if file cannot be opened for the requested access
-
MultiBufferedRandomAccessFile
public MultiBufferedRandomAccessFile(File file, int bufSize, int maxBuffers, boolean isWriteable, byte[] prefillPattern, boolean trackReloadedBlocks) throws IOException Create a read-only or read-write random access file with the specified maximum number of buffers of the specified size.- Parameters:
file
- File pointing at the disk file to readbufSize
- size of each buffer in bytes (must be a power of 2)maxBuffers
- maximum number of buffers to useisWriteable
- boolean true if this file can be written toprefillPattern
- byte array to iteratively write to a new buffer as a fill patterntrackReloadedBlocks
- boolean true if rereads of blocks should be tracked, false if not- Throws:
IOException
- if file cannot be opened for the requested access
-
-
Method Details
-
read
Reads the next byte in the file at the current seek position.- Returns:
- the next byte of data
- Throws:
EOFException
- if attempt to read past the end of fileIOException
- if this input stream has been closed by invoking itsclose()
method, or an I/O error occurs.- See Also:
-
readBoolean
See the general contract of thereadBoolean
method ofDataInput
.Bytes for this operation are read from the contained file.
- Specified by:
readBoolean
in interfaceDataInput
- Returns:
- the
boolean
value read. - Throws:
EOFException
- if this input stream has reached the end.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readByte
See the general contract of thereadByte
method ofDataInput
.Bytes for this operation are read from the contained file.
- Specified by:
readByte
in interfaceDataInput
- Returns:
- the next byte of this input stream as a signed 8-bit
byte
. - Throws:
EOFException
- if this input stream has reached the end.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readChar
See the general contract of thereadChar
method ofDataInput
.Bytes for this operation are read from the contained input stream.
- Specified by:
readChar
in interfaceDataInput
- Returns:
- the next two bytes of this input stream, interpreted as a
char
. - Throws:
EOFException
- if this input stream reaches the end before reading two bytes.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readDouble
See the general contract of thereadDouble
method ofDataInput
.Bytes for this operation are read from the contained file.
- Specified by:
readDouble
in interfaceDataInput
- Returns:
- the next eight bytes of this input stream, interpreted as a
double
. - Throws:
EOFException
- if this input stream reaches the end before reading eight bytes.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.- See Also:
-
readFloat
See the general contract of thereadFloat
method ofDataInput
.Bytes for this operation are read from the contained file.
- Specified by:
readFloat
in interfaceDataInput
- Returns:
- the next four bytes of this input stream, interpreted as a
float
. - Throws:
EOFException
- if this input stream reaches the end before reading four bytes.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.- See Also:
-
readFully
See the general contract of thereadFully
method ofDataInput
.Bytes for this operation are read from the contained file.
- Specified by:
readFully
in interfaceDataInput
- Parameters:
b
- the buffer into which the data is read.- Throws:
EOFException
- if this input stream reaches the end before reading all the bytes.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readFully
See the general contract of thereadFully
method ofDataInput
.Bytes for this operation are read from the contained file.
- Specified by:
readFully
in interfaceDataInput
- 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:
EOFException
- if this input stream reaches the end before reading all the bytes.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readInt
See the general contract of thereadInt
method ofDataInput
.Bytes for this operation are read from the contained file.
- Specified by:
readInt
in interfaceDataInput
- Returns:
- the next four bytes of this input stream, interpreted as an
int
. - Throws:
EOFException
- if this input stream reaches the end before reading four bytes.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readLine
See the general contract of thereadLine
method ofDataInput
.Bytes for this operation are read from the contained file. Note that this method only supports extended 8-bit ASCII; it does not support UTF-8 or other locale-specific character sets.
- Specified by:
readLine
in interfaceDataInput
- Returns:
- the next line of text from this input stream.
- Throws:
IOException
- if an I/O error occurs.
-
readLong
See the general contract of thereadLong
method ofDataInput
.Bytes for this operation are read from the contained file.
- Specified by:
readLong
in interfaceDataInput
- Returns:
- the next eight bytes of this input stream, interpreted as a
long
. - Throws:
EOFException
- if this input stream reaches the end before reading eight bytes.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readShort
See the general contract of thereadShort
method ofDataInput
.Bytes for this operation are read from the contained file.
- Specified by:
readShort
in interfaceDataInput
- Returns:
- the next two bytes of this input stream, interpreted as a signed 16-bit number.
- Throws:
EOFException
- if this input stream reaches the end before reading two bytes.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readUnsignedByte
See the general contract of thereadUnsignedByte
method ofDataInput
.Bytes for this operation are read from the contained file.
- Specified by:
readUnsignedByte
in interfaceDataInput
- Returns:
- the next byte of this input stream, interpreted as an unsigned 8-bit number.
- Throws:
EOFException
- if this input stream has reached the end.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readUnsignedShort
See the general contract of thereadUnsignedShort
method ofDataInput
.Bytes for this operation are read from the contained file.
- Specified by:
readUnsignedShort
in interfaceDataInput
- Returns:
- the next two bytes of this input stream, interpreted as an unsigned 16-bit integer.
- Throws:
EOFException
- if this input stream reaches the end before reading two bytes.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readUTF
See the general contract of thereadUTF
method ofDataInput
.Bytes for this operation are read from the contained file.
- Specified by:
readUTF
in interfaceDataInput
- Returns:
- a Unicode string.
- Throws:
EOFException
- if this input stream reaches the end before reading all the bytes.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.UTFDataFormatException
- if the bytes do not represent a valid modified UTF-8 encoding of a string.
-
skipBytes
public int skipBytes(int n) See the general contract of theskipBytes
method ofDataInput
.No actual bytes are read; the current file seek position pointer is merely updated in preparation for later I/O.
-
seek
public void seek(long seekPos) Sets the file-pointer offset, measured from the beginning of this file, at which the next read 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.- Parameters:
seekPos
- the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
-
readIntAt
Bytes for this operation are read from the contained file.- Parameters:
seekPos
- the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.- Returns:
- the next four bytes of this input stream, interpreted as an
int
. - Throws:
EOFException
- if this input stream reaches the end before reading four bytes.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
getFilePointer
public long getFilePointer()Returns 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.
-
close
Closes this file and releases any system resources associated with the buffering. Once the file has been closed, further read(), available(), or skipBytes() invocations will throw an IOException. Closing a previously closed stream has no effect.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if an I/O error occurs.
-
toString
Returns a string representation of the object. -
resetStatistics
public void resetStatistics()Reset the statistics counters that are reported by the toString() method.- See Also:
-
resetOldPages
public void resetOldPages()If being used, clear the history of already-accessed pages. -
getNumHits
public long getNumHits()Get number of times a read matched data already in the buffers or a write overwrote data already in the buffers.- Returns:
- long hit count since last statistics reset
- See Also:
-
getNumConsecutiveHits
public int getNumConsecutiveHits()Get number of consecutive times a read matched data already in the buffers or a write overwrote data already in the buffers.- Returns:
- int maximum consecutive hit count since last statistics reset
- See Also:
-
getNumMisses
public long getNumMisses()Get the number of times a read or write required loading a buffer from disk.- Returns:
- long miss count since last statistics reset
- See Also:
-
getNumFlushes
public int getNumFlushes()Get the number of times write-modified buffers had to be flushed to disk.- Returns:
- int flush count since last statistics reset
- See Also:
-
getNumReReads
public int getNumReReads()Get the number of times a block that had already been read into a buffer was read again.- Returns:
- number of re-reads
-
readNextInt
This is similar toreadInt()
, but the caller must guarantee that noseek(long)
occurred between the last call to readInt() or readNextInt() and this one.- Returns:
- the next four bytes of this input stream, interpreted as an
int
. - Throws:
EOFException
- if this input stream reaches the end before reading four bytes.IOException
- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.- See Also:
-
clearCache
public void clearCache()Clear the cache buffers. Useful if the file is changed through another file descriptor such that this caching RandomAccessFile's caches might be stale. Note that any unflushed writes will be lost. -
write
Writes to the output stream all the bytes in arrayb
. Ifb
isnull
, aNullPointerException
is thrown. Ifb.length
is zero, then no bytes are written. Otherwise, the byteb[0]
is written first, thenb[1]
, and so on; the last byte written isb[b.length-1]
.- Specified by:
write
in interfaceDataOutput
- Parameters:
b
- the data.- Throws:
IOException
- if an I/O error occurs.
-
write
Writes to the output stream the eight low-order bits of the argumentb
. The 24 high-order bits ofb
are ignored.- Specified by:
write
in interfaceDataOutput
- Parameters:
b
- the byte to be written.- Throws:
IOException
- if an I/O error occurs.
-
write
Writeslen
bytes from arrayb
, in order, to the output stream. Ifb
isnull
, aNullPointerException
is thrown. Ifoff
is negative, orlen
is negative, oroff+len
is greater than the length of the arrayb
, then anIndexOutOfBoundsException
is thrown. Iflen
is zero, then no bytes are written. Otherwise, the byteb[off]
is written first, thenb[off+1]
, and so on; the last byte written isb[off+len-1]
.- Specified by:
write
in interfaceDataOutput
- 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.
-
writeBoolean
Writes aboolean
value to this output stream. If the argumentv
istrue
, the value(byte)1
is written; ifv
isfalse
, the value(byte)0
is written. The byte written by this method may be read by thereadBoolean
method of interfaceDataInput
, which will then return aboolean
equal tov
.- Specified by:
writeBoolean
in interfaceDataOutput
- Parameters:
v
- the boolean to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeByte
Writes to the output stream the eight low- order bits of the argumentv
. The 24 high-order bits ofv
are ignored. (This means thatwriteByte
does exactly the same thing aswrite
for an integer argument.) The byte written by this method may be read by thereadByte
method of interfaceDataInput
, which will then return abyte
equal to(byte)v
.- Specified by:
writeByte
in interfaceDataOutput
- Parameters:
v
- the byte value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeShort
Writes two bytes to the output stream to represent the value of the argument. The byte values to be written, in the order shown, are:
The bytes written by this method may be read by the(byte)(0xff & (v >> 8)) (byte)(0xff & v)
readShort
method of interfaceDataInput
, which will then return ashort
equal to(short)v
.- Specified by:
writeShort
in interfaceDataOutput
- Parameters:
v
- theshort
value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeChar
Writes achar
value, which is comprised of two bytes, to the output stream. The byte values to be written, in the order shown, are:
The bytes written by this method may be read by the(byte)(0xff & (v >> 8)) (byte)(0xff & v)
readChar
method of interfaceDataInput
, which will then return achar
equal to(char)v
.- Specified by:
writeChar
in interfaceDataOutput
- Parameters:
v
- thechar
value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeInt
Writes anint
value, which is comprised of four bytes, to the output stream. The byte values to be written, in the order shown, are:
The bytes written by this method may be read by the(byte)(0xff & (v >> 24)) (byte)(0xff & (v >> 16)) (byte)(0xff & (v >> 8)) (byte)(0xff & v)
readInt
method of interfaceDataInput
, which will then return anint
equal tov
.- Specified by:
writeInt
in interfaceDataOutput
- Parameters:
v
- theint
value to be written.- Throws:
IOException
- if an I/O error occurs.
-
write2Int
Writes 2int
values, each of which is comprised of four bytes, to the output stream. The byte values to be written, in the order shown, are:
The bytes written by this method may be read by the(byte)(0xff & (v >> 24)) (byte)(0xff & (v >> 16)) (byte)(0xff & (v >> 8)) (byte)(0xff & v)
readInt
method of interfaceDataInput
, which will then return anint
equal tov
.- Parameters:
v1
- the firstint
value to be written.v2
- the firstint
value to be written.- Throws:
IOException
- if an I/O error occurs.
-
write2Int
Sets the file-pointer offset, measured from the beginning of this file, at which the next read 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. Then writes 2int
values, each of which is comprised of four bytes, to the output stream. The byte values to be written, in the order shown, are:
The bytes written by this method may be read by the(byte)(0xff & (v >> 24)) (byte)(0xff & (v >> 16)) (byte)(0xff & (v >> 8)) (byte)(0xff & v)
readInt
method of interfaceDataInput
, which will then return anint
equal tov1
orv2
.- Parameters:
seekPos
- the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.v1
- the firstint
value to be written.v2
- the firstint
value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeLong
Writes along
value, which is comprised of eight bytes, to the output stream. The byte values to be written, in the order shown, are:
The bytes written by this method may be read by the(byte)(0xff & (v >> 56)) (byte)(0xff & (v >> 48)) (byte)(0xff & (v >> 40)) (byte)(0xff & (v >> 32)) (byte)(0xff & (v >> 24)) (byte)(0xff & (v >> 16)) (byte)(0xff & (v >> 8)) (byte)(0xff & v)
readLong
method of interfaceDataInput
, which will then return along
equal tov
.- Specified by:
writeLong
in interfaceDataOutput
- Parameters:
v
- thelong
value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeFloat
Writes afloat
value, which is comprised of four bytes, to the output stream. It does this as if it first converts thisfloat
value to anint
in exactly the manner of theFloat.floatToIntBits
method and then writes theint
value in exactly the manner of thewriteInt
method. The bytes written by this method may be read by thereadFloat
method of interfaceDataInput
, which will then return afloat
equal tov
.- Specified by:
writeFloat
in interfaceDataOutput
- Parameters:
v
- thefloat
value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeDouble
Writes adouble
value, which is comprised of eight bytes, to the output stream. It does this as if it first converts thisdouble
value to along
in exactly the manner of theDouble.doubleToLongBits
method and then writes thelong
value in exactly the manner of thewriteLong
method. The bytes written by this method may be read by thereadDouble
method of interfaceDataInput
, which will then return adouble
equal tov
.- Specified by:
writeDouble
in interfaceDataOutput
- Parameters:
v
- thedouble
value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeBytes
Writes a string to the output stream. For every character in the strings
, taken in order, one byte is written to the output stream. Ifs
isnull
, aNullPointerException
is thrown.If
s.length
is zero, then no bytes are written. Otherwise, the characters[0]
is written first, thens[1]
, and so on; the last character written iss[s.length-1]
. For each character, one byte is written, the low-order byte, in exactly the manner of thewriteByte
method . The high-order eight bits of each character in the string are ignored.- Specified by:
writeBytes
in interfaceDataOutput
- Parameters:
s
- the string of bytes to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeChars
Writes every character in the strings
, to the output stream, in order, two bytes per character. Ifs
isnull
, aNullPointerException
is thrown. Ifs.length
is zero, then no characters are written. Otherwise, the characters[0]
is written first, thens[1]
, and so on; the last character written iss[s.length-1]
. For each character, two bytes are actually written, high-order byte first, in exactly the manner of thewriteChar
method.- Specified by:
writeChars
in interfaceDataOutput
- Parameters:
s
- the string value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeUTF
Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in the strings
. Ifs
isnull
, aNullPointerException
is thrown. Each character in the strings
is converted to a group of one, two, or three bytes, depending on the value of the character.If a character
c
is in the range\u0001
through\u007f
, it is represented by one byte:(byte)c
If a characterc
is\u0000
or is in the range\u0080
through\u07ff
, then it is represented by two bytes, to be written in the order shown:(byte)(0xc0 | (0x1f & (c >> 6))) (byte)(0x80 | (0x3f & c))
If a character
c
is in the range\u0800
throughuffff
, then it is represented by three bytes, to be written in the order shown:(byte)(0xe0 | (0x0f & (c >> 12))) (byte)(0x80 | (0x3f & (c >> 6))) (byte)(0x80 | (0x3f & c))
First, the total number of bytes needed to represent all the characters of
s
is calculated. If this number is larger than65535
, then aUTFDataFormatException
is thrown. Otherwise, this length is written to the output stream in exactly the manner of thewriteShort
method; after this, the one-, two-, or three-byte representation of each character in the strings
is written.The bytes written by this method may be read by the
readUTF
method of interfaceDataInput
, which will then return aString
equal tos
.- Specified by:
writeUTF
in interfaceDataOutput
- Parameters:
s
- the string value to be written.- Throws:
IOException
- if an I/O error occurs.
-
flush
Flush all "dirty" (modified) buffers.- Throws:
IOException
- if dirty buffers can't be written to disk- See Also:
-
getRandomAccessFile
Get the RandomAccessFile underlying this MultiBufferedRandomAccessFile.- Returns:
- RandomAccessFile if file is still open, null otherwise
- See Also:
-