Class MultiBufferedRandomAccessFile

java.lang.Object
org.ka2ddo.yaac.io.MultiBufferedRandomAccessFile
All Implemented Interfaces:
Closeable, DataInput, DataOutput, AutoCloseable

public final class MultiBufferedRandomAccessFile extends Object implements DataInput, DataOutput, Closeable
This class provides a cached, buffered variant of RandomAccessFile, so that sequential reads from a starting point can be done with minimal JNI calls and actual kernel calls. It also supports multiple buffers for reading chunks of data that are significantly not sequential.
Author:
Andrew Pavlin, KA2DDO
  • Constructor Summary

    Constructors
    Constructor
    Description
    MultiBufferedRandomAccessFile(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 Type
    Method
    Description
    void
    Clear the cache buffers.
    void
    Closes this file and releases any system resources associated with the buffering.
    void
    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
    Reads the next byte in the file at the current seek position.
    boolean
    See the general contract of the readBoolean method of DataInput.
    byte
    See the general contract of the readByte method of DataInput.
    char
    See the general contract of the readChar method of DataInput.
    double
    See the general contract of the readDouble method of DataInput.
    float
    See the general contract of the readFloat method of DataInput.
    void
    readFully(byte[] b)
    See the general contract of the readFully method of DataInput.
    void
    readFully(byte[] b, int off, int len)
    See the general contract of the readFully method of DataInput.
    int
    See the general contract of the readInt method of DataInput.
    int
    readIntAt(long seekPos)
    Bytes for this operation are read from the contained file.
    See the general contract of the readLine method of DataInput.
    long
    See the general contract of the readLong method of DataInput.
    int
    This is similar to readInt(), but the caller must guarantee that no seek(long) occurred between the last call to readInt() or readNextInt() and this one.
    short
    See the general contract of the readShort method of DataInput.
    int
    See the general contract of the readUnsignedByte method of DataInput.
    int
    See the general contract of the readUnsignedShort method of DataInput.
    See the general contract of the readUTF method of DataInput.
    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 the skipBytes method of DataInput.
    Returns a string representation of the object.
    void
    write(byte[] b)
    Writes to the output stream all the bytes in array b.
    void
    write(byte[] b, int off, int len)
    Writes len bytes from array b, in order, to the output stream.
    void
    write(int b)
    Writes to the output stream the eight low-order bits of the argument b.
    void
    write2Int(int v1, int v2)
    Writes 2 int 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 a boolean value to this output stream.
    void
    writeByte(int v)
    Writes to the output stream the eight low- order bits of the argument v.
    void
    Writes a string to the output stream.
    void
    writeChar(int v)
    Writes a char value, which is comprised of two bytes, to the output stream.
    void
    Writes every character in the string s, to the output stream, in order, two bytes per character.
    void
    writeDouble(double v)
    Writes a double value, which is comprised of eight bytes, to the output stream.
    void
    writeFloat(float v)
    Writes a float value, which is comprised of four bytes, to the output stream.
    void
    writeInt(int v)
    Writes an int value, which is comprised of four bytes, to the output stream.
    void
    writeLong(long v)
    Writes a long 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 string s.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • MultiBufferedRandomAccessFile

      public MultiBufferedRandomAccessFile(File file, int bufSize, int maxBuffers) throws IOException
      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 read
      bufSize - 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 read
      bufSize - size of each buffer in bytes (must be a power of 2)
      maxBuffers - maximum number of buffers to use
      isWriteable - 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 read
      bufSize - size of each buffer in bytes (must be a power of 2)
      maxBuffers - maximum number of buffers to use
      isWriteable - boolean true if this file can be written to
      flushUnloadedBuffers - 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 read
      bufSize - size of each buffer in bytes (must be a power of 2)
      maxBuffers - maximum number of buffers to use
      isWriteable - boolean true if this file can be written to
      flushUnloadedBuffers - specify whether capable systems should flush released buffers from kernel filesystem cache to reduce cache overgrowth
      trackReloadedBlocks - 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 read
      bufSize - size of each buffer in bytes (must be a power of 2)
      maxBuffers - maximum number of buffers to use
      isWriteable - boolean true if this file can be written to
      prefillPattern - 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 read
      bufSize - size of each buffer in bytes (must be a power of 2)
      maxBuffers - maximum number of buffers to use
      isWriteable - boolean true if this file can be written to
      prefillPattern - byte array to iteratively write to a new buffer as a fill pattern
      trackReloadedBlocks - 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

      public int read() throws IOException
      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 file
      IOException - if this input stream has been closed by invoking its close() method, or an I/O error occurs.
      See Also:
    • readBoolean

      public boolean readBoolean() throws IOException
      See the general contract of the readBoolean method of DataInput.

      Bytes for this operation are read from the contained file.

      Specified by:
      readBoolean in interface DataInput
      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

      public byte readByte() throws IOException
      See the general contract of the readByte method of DataInput.

      Bytes for this operation are read from the contained file.

      Specified by:
      readByte in interface DataInput
      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

      public char readChar() throws IOException
      See the general contract of the readChar method of DataInput.

      Bytes for this operation are read from the contained input stream.

      Specified by:
      readChar in interface DataInput
      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

      public double readDouble() throws IOException
      See the general contract of the readDouble method of DataInput.

      Bytes for this operation are read from the contained file.

      Specified by:
      readDouble in interface DataInput
      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

      public float readFloat() throws IOException
      See the general contract of the readFloat method of DataInput.

      Bytes for this operation are read from the contained file.

      Specified by:
      readFloat in interface DataInput
      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

      public void readFully(byte[] b) throws IOException
      See the general contract of the readFully method of DataInput.

      Bytes for this operation are read from the contained file.

      Specified by:
      readFully in interface DataInput
      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

      public void readFully(byte[] b, int off, int len) throws IOException
      See the general contract of the readFully method of DataInput.

      Bytes for this operation are read from the contained file.

      Specified by:
      readFully in interface DataInput
      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

      public int readInt() throws IOException
      See the general contract of the readInt method of DataInput.

      Bytes for this operation are read from the contained file.

      Specified by:
      readInt in interface DataInput
      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

      public String readLine() throws IOException
      See the general contract of the readLine method of DataInput.

      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 interface DataInput
      Returns:
      the next line of text from this input stream.
      Throws:
      IOException - if an I/O error occurs.
    • readLong

      public long readLong() throws IOException
      See the general contract of the readLong method of DataInput.

      Bytes for this operation are read from the contained file.

      Specified by:
      readLong in interface DataInput
      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

      public short readShort() throws IOException
      See the general contract of the readShort method of DataInput.

      Bytes for this operation are read from the contained file.

      Specified by:
      readShort in interface DataInput
      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

      public int readUnsignedByte() throws IOException
      See the general contract of the readUnsignedByte method of DataInput.

      Bytes for this operation are read from the contained file.

      Specified by:
      readUnsignedByte in interface DataInput
      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

      public int readUnsignedShort() throws IOException
      See the general contract of the readUnsignedShort method of DataInput.

      Bytes for this operation are read from the contained file.

      Specified by:
      readUnsignedShort in interface DataInput
      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

      public String readUTF() throws IOException
      See the general contract of the readUTF method of DataInput.

      Bytes for this operation are read from the contained file.

      Specified by:
      readUTF in interface DataInput
      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 the skipBytes method of DataInput.

      No actual bytes are read; the current file seek position pointer is merely updated in preparation for later I/O.

      Specified by:
      skipBytes in interface DataInput
      Parameters:
      n - the number of bytes to be skipped.
      Returns:
      the actual number of bytes skipped.
    • 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

      public int readIntAt(long seekPos) throws IOException
      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

      public void close() throws IOException
      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 interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an I/O error occurs.
    • toString

      public String toString()
      Returns a string representation of the object.
      Overrides:
      toString in class Object
      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

      public int readNextInt() throws IOException
      This is similar to readInt(), but the caller must guarantee that no seek(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

      public void write(byte[] b) throws IOException
      Writes to the output stream all the bytes in array b. If b is null, a NullPointerException is thrown. If b.length is zero, then no bytes are written. Otherwise, the byte b[0] is written first, then b[1], and so on; the last byte written is b[b.length-1].
      Specified by:
      write in interface DataOutput
      Parameters:
      b - the data.
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(int b) throws IOException
      Writes to the output stream the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.
      Specified by:
      write in interface DataOutput
      Parameters:
      b - the byte to be written.
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Writes len bytes from array b, in order, to the output stream. If b is null, a NullPointerException is thrown. If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown. If len is zero, then no bytes are written. Otherwise, the byte b[off] is written first, then b[off+1], and so on; the last byte written is b[off+len-1].
      Specified by:
      write in interface DataOutput
      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

      public void writeBoolean(boolean v) throws IOException
      Writes a boolean value to this output stream. If the argument v is true, the value (byte)1 is written; if v is false, the value (byte)0 is written. The byte written by this method may be read by the readBoolean method of interface DataInput, which will then return a boolean equal to v.
      Specified by:
      writeBoolean in interface DataOutput
      Parameters:
      v - the boolean to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeByte

      public void writeByte(int v) throws IOException
      Writes to the output stream the eight low- order bits of the argument v. The 24 high-order bits of v are ignored. (This means that writeByte does exactly the same thing as write for an integer argument.) The byte written by this method may be read by the readByte method of interface DataInput, which will then return a byte equal to (byte)v.
      Specified by:
      writeByte in interface DataOutput
      Parameters:
      v - the byte value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeShort

      public void writeShort(int v) throws IOException
      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:
      
       (byte)(0xff & (v >> 8))
       (byte)(0xff & v)
        
      The bytes written by this method may be read by the readShort method of interface DataInput , which will then return a short equal to (short)v.
      Specified by:
      writeShort in interface DataOutput
      Parameters:
      v - the short value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeChar

      public void writeChar(int v) throws IOException
      Writes a char value, which is comprised of two bytes, to the output stream. The byte values to be written, in the order shown, are:
      
       (byte)(0xff & (v >> 8))
       (byte)(0xff & v)
       
      The bytes written by this method may be read by the readChar method of interface DataInput , which will then return a char equal to (char)v.
      Specified by:
      writeChar in interface DataOutput
      Parameters:
      v - the char value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeInt

      public void writeInt(int v) throws IOException
      Writes an int value, which is comprised of four bytes, to the output stream. The byte values to be written, in the order shown, are:
      
       (byte)(0xff & (v >> 24))
       (byte)(0xff & (v >> 16))
       (byte)(0xff & (v >>    8))
       (byte)(0xff & v)
       
      The bytes written by this method may be read by the readInt method of interface DataInput , which will then return an int equal to v.
      Specified by:
      writeInt in interface DataOutput
      Parameters:
      v - the int value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • write2Int

      public void write2Int(int v1, int v2) throws IOException
      Writes 2 int values, each of which is comprised of four bytes, to the output stream. The byte values to be written, in the order shown, are:
      
       (byte)(0xff & (v >> 24))
       (byte)(0xff & (v >> 16))
       (byte)(0xff & (v >>    8))
       (byte)(0xff & v)
       
      The bytes written by this method may be read by the readInt method of interface DataInput , which will then return an int equal to v.
      Parameters:
      v1 - the first int value to be written.
      v2 - the first int value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • write2Int

      public void write2Int(long seekPos, int v1, int v2) throws IOException
      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 2 int values, each of which is comprised of four bytes, to the output stream. The byte values to be written, in the order shown, are:
      
       (byte)(0xff & (v >> 24))
       (byte)(0xff & (v >> 16))
       (byte)(0xff & (v >>    8))
       (byte)(0xff & v)
       
      The bytes written by this method may be read by the readInt method of interface DataInput , which will then return an int equal to v1 or v2.
      Parameters:
      seekPos - the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
      v1 - the first int value to be written.
      v2 - the first int value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeLong

      public void writeLong(long v) throws IOException
      Writes a long value, which is comprised of eight bytes, to the output stream. The byte values to be written, in the order shown, are:
      
       (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)
       
      The bytes written by this method may be read by the readLong method of interface DataInput , which will then return a long equal to v.
      Specified by:
      writeLong in interface DataOutput
      Parameters:
      v - the long value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeFloat

      public void writeFloat(float v) throws IOException
      Writes a float value, which is comprised of four bytes, to the output stream. It does this as if it first converts this float value to an int in exactly the manner of the Float.floatToIntBits method and then writes the int value in exactly the manner of the writeInt method. The bytes written by this method may be read by the readFloat method of interface DataInput, which will then return a float equal to v.
      Specified by:
      writeFloat in interface DataOutput
      Parameters:
      v - the float value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeDouble

      public void writeDouble(double v) throws IOException
      Writes a double value, which is comprised of eight bytes, to the output stream. It does this as if it first converts this double value to a long in exactly the manner of the Double.doubleToLongBits method and then writes the long value in exactly the manner of the writeLong method. The bytes written by this method may be read by the readDouble method of interface DataInput, which will then return a double equal to v.
      Specified by:
      writeDouble in interface DataOutput
      Parameters:
      v - the double value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeBytes

      public void writeBytes(String s) throws IOException
      Writes a string to the output stream. For every character in the string s, taken in order, one byte is written to the output stream. If s is null, a NullPointerException is thrown.

      If s.length is zero, then no bytes are written. Otherwise, the character s[0] is written first, then s[1], and so on; the last character written is s[s.length-1]. For each character, one byte is written, the low-order byte, in exactly the manner of the writeByte method . The high-order eight bits of each character in the string are ignored.

      Specified by:
      writeBytes in interface DataOutput
      Parameters:
      s - the string of bytes to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeChars

      public void writeChars(String s) throws IOException
      Writes every character in the string s, to the output stream, in order, two bytes per character. If s is null, a NullPointerException is thrown. If s.length is zero, then no characters are written. Otherwise, the character s[0] is written first, then s[1], and so on; the last character written is s[s.length-1]. For each character, two bytes are actually written, high-order byte first, in exactly the manner of the writeChar method.
      Specified by:
      writeChars in interface DataOutput
      Parameters:
      s - the string value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeUTF

      public void writeUTF(String s) throws IOException
      Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in the string s. If s is null, a NullPointerException is thrown. Each character in the string s 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 character c 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 through uffff, 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 than 65535, then a UTFDataFormatException is thrown. Otherwise, this length is written to the output stream in exactly the manner of the writeShort method; after this, the one-, two-, or three-byte representation of each character in the string s is written.

      The bytes written by this method may be read by the readUTF method of interface DataInput , which will then return a String equal to s.

      Specified by:
      writeUTF in interface DataOutput
      Parameters:
      s - the string value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • flush

      public void flush() throws IOException
      Flush all "dirty" (modified) buffers.
      Throws:
      IOException - if dirty buffers can't be written to disk
      See Also:
    • getRandomAccessFile

      public RandomAccessFile getRandomAccessFile()
      Get the RandomAccessFile underlying this MultiBufferedRandomAccessFile.
      Returns:
      RandomAccessFile if file is still open, null otherwise
      See Also: