Class MappedFileReaderAndWriter

java.lang.Object
com.irurueta.geometry.io.AbstractFileReaderAndWriter
com.irurueta.geometry.io.MappedFileReaderAndWriter
All Implemented Interfaces:
Closeable, AutoCloseable

public class MappedFileReaderAndWriter extends AbstractFileReaderAndWriter
This class provides methods to access file data at random positions using memory mapping for faster data access.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final MappedByteBuffer
    Buffer where data is stored.
    private final RandomAccessFile
    Underlying input file.
    private boolean
    Internal value indicating if read has been produced.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes this file stream and releases any system resources associated with the stream.
    long
    Returns the current offset in this file.
    boolean
    Determines whether end of file has been reached (next read() will return -1). or not.
    int
    Reads one byte at current file position and advances one position.
    int
    read(byte[] b)
    Reads up to b.length bytes of data from this file into an array of bytes.
    int
    read(byte[] b, int off, int len)
    Reads up to len bytes of data from this file into an array of bytes.
    boolean
    Reads a boolean from this file.
    byte
    Reads a signed eight-bit value from this file.
    double
    Reads a double from this file.
    double
    readDouble(EndianType endianType)
    Reads a double from this file.
    float
    Reads a float from this file.
    float
    readFloat(EndianType endianType)
    Reads a float from this file.
    int
    Reads a signed 32-bit integer from this file.
    int
    readInt(EndianType endianType)
    Reads a signed 32-bit integer from this file.
    Reads the next line of text from this file.
    long
    Reads a signed 64-bit integer from this file.
    long
    readLong(EndianType endianType)
    Reads a signed 64-bit integer from this file.
    short
    Reads a signed 16-bit number from this file.
    short
    readShort(EndianType endianType)
    Reads a signed 16-bit number from this file assuming that file is encoded using provided endian type.
    short
    Reads an unsigned eight-bit number from this file.
    long
    Reads an unsigned 32-bit integer from this file.
    long
    Reads an unsigned 32-bit integer from this file.
    int
    Reads an unsigned 16-bit number from this file.
    int
    Reads an unsigned 16-bit number from this file.
    Sequentially reads characters starting at current file position until one of the characters in provided pattern is found.
    void
    seek(long pos)
    Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.
    long
    skip(long n)
    Attempts to skip over n byte of input discarding the skipped bytes.
    void
    write(byte[] b)
    Writes b.length bytes from the specified byte array to this file, starting at the current file pointer.
    void
    write(byte[] b, int off, int len)
    Writes len bytes from the specified byte array starting at offset off to this file.
    void
    write(int b)
    Writes the specified byte to this file.
    void
    Writes the string to the file as a sequence of bytes.
    void
    writeBoolean(boolean v)
    Writes a boolean to the file as a one-byte value.
    void
    writeByte(byte v)
    Writes a byte to the file as a one-byte value.
    void
    writeDouble(double v)
    Converts the double argument to a long using the doubleToLongBits method in class Double, and then writes that long value to the file as an eight byte quantity, high byte first.
    void
    writeDouble(double v, EndianType endianType)
    Converts the double argument to a long using the doubleToLongBits method in class Double, and then writes that long value to the file as an eight byte quantity, using provided endian type.
    void
    writeFloat(float v)
    Converts the float argument to an int using the floatToIntBits method in class Float, and then write that int value to the file as a four-byte quantity, high byte first.
    void
    writeFloat(float v, EndianType endianType)
    Converts the float argument to an int using the floatToIntBits method in class Float, and then write that int value to the file as a four-byte quantity, using provided endian type.
    void
    writeInt(int v)
    Writes an int to the file as four bytes, high byte first.
    void
    writeInt(int v, EndianType endianType)
    Writes an int to the file as four bytes, using provided endian type.
    void
    writeLong(long v)
    Writes a long to the file as eight bytes, high byte first.
    void
    writeLong(long v, EndianType endianType)
    Writes a long to the file as eight bytes, using provided endian type.
    void
    writeShort(short v)
    Writes a short to the file as two bytes, high byte first.
    void
    writeShort(short v, EndianType endianType)
    Writes a short to the file as two bytes using provided endian type.
    void
    Writes provided value in the range 0-255 as an unsigned byte.
    void
    Writes an unsigned int to the file as four bytes, high byte first.
    void
    writeUnsignedInt(long v, EndianType endianType)
    Writes an unsigned int to the file as four bytes, using provided endian type.
    void
    Writes an unsigned short to the file as two bytes, high byte first.
    void
    writeUnsignedShort(int v, EndianType endianType)
    Writes an unsigned short to the file as two bytes, using provided endian type.

    Methods inherited from class com.irurueta.geometry.io.AbstractFileReaderAndWriter

    readWord

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • randomAccessFile

      private final RandomAccessFile randomAccessFile
      Underlying input file.
    • buffer

      private final MappedByteBuffer buffer
      Buffer where data is stored.
    • read

      private boolean read
      Internal value indicating if read has been produced.
  • Constructor Details

    • MappedFileReaderAndWriter

      public MappedFileReaderAndWriter(File f, FileChannel.MapMode mode) throws IOException
      Constructor.
      Parameters:
      f - file to read from or write to.
      mode - file opening mode (read only or read write).
      Throws:
      IOException - if an I/O error occurs .
  • Method Details

    • read

      public int read() throws IOException
      Reads one byte at current file position and advances one position.
      Specified by:
      read in class AbstractFileReaderAndWriter
      Returns:
      Next byte of data or -1 if end of file is reached.
      Throws:
      IOException - if an I/O error occurs. Not thrown if end-of-file has been reached.
    • read

      public int read(byte[] b) throws IOException
      Reads up to b.length bytes of data from this file into an array of bytes. This method blocks until at least one byte of input is available.
      Specified by:
      read in class AbstractFileReaderAndWriter
      Parameters:
      b - The buffer into which the data is read.
      Returns:
      The total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached.
      Throws:
      IOException - If the first byte cannot be read for any reason other than end of file, or if the file has been closed, or if some other I/O error occurs.
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Reads up to len bytes of data from this file into an array of bytes. This method blocks until at least one byte of input is available. This method behaves in exactly the same way as the InputStream.read(byte[], int, int) method of InputStream.
      Specified by:
      read in class AbstractFileReaderAndWriter
      Parameters:
      b - the buffer into which the data is read.
      off - the start offset in array b at which the data is written.
      len - the maximum number of bytes read.
      Returns:
      the total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached.
      Throws:
      IOException - If the first byte cannot be read for any reason other than end of file, or if the random access file has been closed, or if some other I/O error occurs.
    • skip

      public long skip(long n)
      Attempts to skip over n byte of input discarding the skipped bytes.

      This method may skip over some 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. The actual number of bytes skipped is returned. If n is negative, no bytes are skipped.

      Specified by:
      skip in class AbstractFileReaderAndWriter
      Parameters:
      n - the number of bytes to be skipped.
      Returns:
      the actual number of bytes skipped.
    • write

      public void write(int b) throws IOException
      Writes the specified byte to this file. The write starts at the current file pointer.
      Specified by:
      write in class AbstractFileReaderAndWriter
      Parameters:
      b - the byte to be written.
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(byte[] b) throws IOException
      Writes b.length bytes from the specified byte array to this file, starting at the current file pointer.
      Specified by:
      write in class AbstractFileReaderAndWriter
      Parameters:
      b - the data.
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Writes len bytes from the specified byte array starting at offset off to this file.
      Specified by:
      write in class AbstractFileReaderAndWriter
      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.
    • getPosition

      public long getPosition() throws IOException
      Returns the current offset in this file.
      Specified by:
      getPosition in class AbstractFileReaderAndWriter
      Returns:
      the offset from the beginning of the file, in bytes, at which the next read or write occurs.
      Throws:
      IOException - in an I/O error occurs.
    • isEndOfStream

      public boolean isEndOfStream() throws IOException
      Determines whether end of file has been reached (next read() will return -1). or not.
      Specified by:
      isEndOfStream in class AbstractFileReaderAndWriter
      Returns:
      True if end of file has been reached, false otherwise.
      Throws:
      IOException - if an I/O error occurs..
    • seek

      public void seek(long pos)
      Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs. Setting the offset beyond the end of the file will raise an exception.
      Specified by:
      seek in class AbstractFileReaderAndWriter
      Parameters:
      pos - the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
    • close

      public void close() throws IOException
      Closes this file stream and releases any system resources associated with the stream. A closed 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.
      Throws:
      IOException - if an I/O error occurs.
    • readBoolean

      public boolean readBoolean()
      Reads a boolean from this file. This method reads a single byte from the file, starting at the current file pointer. A value of 0 represents false. Any other value represents true. This method blocks until the byte is read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readBoolean in class AbstractFileReaderAndWriter
      Returns:
      the boolean value read.
    • readByte

      public byte readByte()
      Reads a signed eight-bit value from this file. This method reads a byte from the file, starting from the current file pointer. If the byte read is b, where 0 <= b <= 255, then the result is: (byte)(b) This method blocks until the byte is read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readByte in class AbstractFileReaderAndWriter
      Returns:
      the next byte of this file is a signed eight-bit byte.
    • readUnsignedByte

      public short readUnsignedByte()
      Reads an unsigned eight-bit number from this file. This method reads a byte from this file, starting at the current file pointer, and returns that byte. This method blocks until the byte is read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readUnsignedByte in class AbstractFileReaderAndWriter
      Returns:
      the next byte of this file, interpreted as an unsigned eight-bit number.
    • readShort

      public short readShort()
      Reads a signed 16-bit number from this file. The method reads two byte from this file, starting at the current file pointer. If the two bytes read, in order, are b1 and b2, where each of the two values is between 0 and 255, inclusive, then the result is equal to: (short)(b1 << 8 | b2). This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readShort in class AbstractFileReaderAndWriter
      Returns:
      the next two bytes of this file, interpreted as a signed 16-bit number.
    • readShort

      public short readShort(EndianType endianType)
      Reads a signed 16-bit number from this file assuming that file is encoded using provided endian type. If endian type is big endian type, then natural binary order is preserved, otherwise byte order is reversed. This method blocks until the two bytes of the 16-bit number are read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readShort in class AbstractFileReaderAndWriter
      Parameters:
      endianType - Endian type. Big endian preserves natural binary order, little endian reverses byte order.
      Returns:
      the next two bytes of this file, interpreted as a signed 16-bit number encoded in provided endian type.
    • readUnsignedShort

      public int readUnsignedShort()
      Reads an unsigned 16-bit number from this file. This method reads two bytes from this file, starting at the current file pointer. If the bytes read, in order, are b1 and b2, where 0 <= b1, b2 <= 255, then the result is equal to: (b1 << 8) | b2 This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readUnsignedShort in class AbstractFileReaderAndWriter
      Returns:
      the next two bytes of this file, interpreted as an unsigned 16-bit integer.
    • readUnsignedShort

      public int readUnsignedShort(EndianType endianType)
      Reads an unsigned 16-bit number from this file. This method reads two bytes from this file, starting at the current file pointer and using provided endian type. If endian type is big endian, then natural binary order is preserved, otherwise byte order is reversed. This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readUnsignedShort in class AbstractFileReaderAndWriter
      Parameters:
      endianType - Endian type. Big endian preserves natural binary order, little endian reverses byte order.
      Returns:
      the next two bytes of this file, interpreted as an unsigned 16-bit integer.
    • readInt

      public int readInt()
      Reads 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, are b1, b2, b3, and b4, where 0 <= b1, b3, b4 <= 255, then the result is equal to: (b1 << 24) | (b2 << 16) + (b3 << 8) + b4. This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readInt in class AbstractFileReaderAndWriter
      Returns:
      the next four bytes of this file, interpreted as an int.
    • readInt

      public int readInt(EndianType endianType)
      Reads a signed 32-bit integer from this file. This method reads 4 bytes from the file, starting at the current file pointer and using provided endian type. If endian type is big endian, then natural binary order is preserved, otherwise byte order is reversed. This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readInt in class AbstractFileReaderAndWriter
      Parameters:
      endianType - Endian type. Big endian preserves natural binary order, little endian reverses byte order.
      Returns:
      the next four bytes of this file, interpreted as an int.
    • readUnsignedInt

      public long readUnsignedInt()
      Reads an unsigned 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, are b1, b2, b3, and b4, where 0 <= b1, b3, b4 <= 255, then the result is equal to: (b1 << 24) | (b2 << 16) + (b3 << 8) + b4. This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readUnsignedInt in class AbstractFileReaderAndWriter
      Returns:
      the next four bytes of this file, interpreted as a long.
    • readUnsignedInt

      public long readUnsignedInt(EndianType endianType)
      Reads an unsigned 32-bit integer from this file. This method reads 4 bytes from the file, starting at the current file pointer and using provided endian type. If endian type is big endian, then natural binary order is preserved, otherwise byte order is reversed. This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readUnsignedInt in class AbstractFileReaderAndWriter
      Parameters:
      endianType - Endian type. Big endian preserves natural binary order, little endian reverses byte order.
      Returns:
      the next four bytes of this file, interpreted as an int.
    • readLong

      public long readLong()
      Reads a signed 64-bit integer from this file. This method reads eight bytes from the file, starting at the current file pointer. If the bytes read, in order, are b1, b2, b3, b4, b5, b6, b7, and b8, where: 0 <= b1, b2, b3, b4. b5. b6. b7. b8 <= 255, then the result is equal to: ((long)b1 << 56) + ((long)b2 << 48) + ((long)b3 << 40) + ((long)b4 << 32) + ((long)b5 << 24) + ((long)b6 << 16) + ((long)b7 << 8) + b8 This method blocks until the eight bytes are read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readLong in class AbstractFileReaderAndWriter
      Returns:
      the next eight bytes of this file, interpreted as a long
    • readLong

      public long readLong(EndianType endianType)
      Reads a signed 64-bit integer from this file. This method reads eight bytes from the file, starting at the current file pointer and using provided endian type. If endian type is big endian, then natural binary order is preserved, otherwise byte order is reversed. This method blocks until the eight bytes are read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readLong in class AbstractFileReaderAndWriter
      Parameters:
      endianType - Endian type. Big endian preserves natural binary order, little endian reverses byte order.
      Returns:
      the next eight bytes of this file, interpreted as a long
    • readFloat

      public float readFloat()
      Reads a float from this file. This method reads an int value, starting at the current file pointer, as if by the readInt method and then converts that in to a float using the intBitsToFloat method in class Float. This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readFloat in class AbstractFileReaderAndWriter
      Returns:
      the next four bytes of this file, interpreted as a float.
    • readFloat

      public float readFloat(EndianType endianType)
      Reads a float from this file. This method reads four bytes using provided endian type. If endian type is big endian, then natural binary order is preserved, otherwise byte order is reversed. This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readFloat in class AbstractFileReaderAndWriter
      Parameters:
      endianType - Endian type. Big endian preserves natural binary order, little endian reverses byte order.
      Returns:
      the next four bytes of this file, interpreted as a float.
    • readDouble

      public double readDouble()
      Reads a double from this file. This method reads a long value, starting at the current file pointer, as if by the readLong method and then converts that long to a double using the longBitsToDouble method in class Double. This method blocks until the eight bytes are read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readDouble in class AbstractFileReaderAndWriter
      Returns:
      the next eight bytes of this file, interpreted as a double.
    • readDouble

      public double readDouble(EndianType endianType)
      Reads a double from this file. This method reads eight bytes using provided endian type. If endian type is big endian, then natural binary order is preserved, otherwise byte order is reversed. This method blocks until the eight bytes are read, the end of the stream is detected, or an exception is thrown.
      Specified by:
      readDouble in class AbstractFileReaderAndWriter
      Parameters:
      endianType - Endian type. Big endian preserves natural binary order, little endian reverses byte order.
      Returns:
      the next eight bytes of this file, interpreted as a double.
    • readLine

      public String readLine()
      Reads the next line of text from this file. This method successively reads bytes from the file, starting at the current file pointer, until it reaches a line terminator of the end of the file. Each byte is converted into a character by taking the byte's value for the lower eight bits of the character and setting the high eight bits of the character to zero. This method does not, therefore, support the full Unicode character set. A line of text is terminated by a carriage-return character ('\r'), a newline character('\n'), a carriage-return character immediately followed by a newline character, or the end of the file. Line-terminating characters are discarded and are not included as part of the string returned. This method blocks until a newline character is read, a carriage return and the byte following it are read (to see if it is a newline), the end of the file is reached, or an exception is thrown.
      Specified by:
      readLine in class AbstractFileReaderAndWriter
      Returns:
      the next line of text from this file, or null if end of file is encountered before even one byte is read.
    • readUntilAnyOfTheseCharactersIsFound

      public String readUntilAnyOfTheseCharactersIsFound(String pattern)
      Sequentially reads characters starting at current file position until one of the characters in provided pattern is found. All characters read so far will be returned without including any of the pattern characters.
      Specified by:
      readUntilAnyOfTheseCharactersIsFound in class AbstractFileReaderAndWriter
      Parameters:
      pattern - Stop characters to stop reading when they are found.
      Returns:
      String read so far until any of the pattern characters was found or an empty string if the first character is contained in provided pattern.
      Throws:
      IllegalArgumentException - if no pattern characters are provided.
    • writeBoolean

      public void writeBoolean(boolean v) throws IOException
      Writes a boolean to the file as a one-byte value. The value true is written out as the value (byte)1; the value false is written out as the value (byte)0. The write starts at the current position of the file pointer.
      Specified by:
      writeBoolean in class AbstractFileReaderAndWriter
      Parameters:
      v - a boolean value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeByte

      public void writeByte(byte v) throws IOException
      Writes a byte to the file as a one-byte value. The write starts at the current position of the file pointer.
      Specified by:
      writeByte in class AbstractFileReaderAndWriter
      Parameters:
      v - a byte value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeUnsignedByte

      public void writeUnsignedByte(short v) throws IOException
      Writes provided value in the range 0-255 as an unsigned byte. The write starts at the current position of the file pointer.
      Specified by:
      writeUnsignedByte in class AbstractFileReaderAndWriter
      Parameters:
      v - a value to be written as an unsigned byte.
      Throws:
      IOException - if an I/O error occurs.
    • writeShort

      public void writeShort(short v) throws IOException
      Writes a short to the file as two bytes, high byte first. The write starts at the current position of the file pointer.
      Specified by:
      writeShort in class AbstractFileReaderAndWriter
      Parameters:
      v - a short to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeShort

      public void writeShort(short v, EndianType endianType) throws IOException
      Writes a short to the file as two bytes using provided endian type. If endian type is big endian, then natural byte order is preserved (and high byte is written first), if little endian order is chosen, then byte order is reversed
      Specified by:
      writeShort in class AbstractFileReaderAndWriter
      Parameters:
      v - a short to be written
      endianType - endian type. If it is big endian, natural byte order is preserved, otherwise byte order is reversed.
      Throws:
      IOException - if an I/O error occurs.
    • writeUnsignedShort

      public void writeUnsignedShort(int v) throws IOException
      Writes an unsigned short to the file as two bytes, high byte first. Provided integer value is converted to an unsigned short by taking into account only the two lower bytes. The write starts at the current position of the file pointer.
      Specified by:
      writeUnsignedShort in class AbstractFileReaderAndWriter
      Parameters:
      v - an unsigned short to be written (int is converted to unsigned short).
      Throws:
      IOException - if an I/O error occurs.
    • writeUnsignedShort

      public void writeUnsignedShort(int v, EndianType endianType) throws IOException
      Writes an unsigned short to the file as two bytes, using provided endian type. Provided integer value is converted to an unsigned short by taking into account only the two lower bytes. If endian type is big endian, then natural byte order is preserved (and high byte is written first), if little endian order is chosen, then byte order is reversed The write starts at the current position of the file pointer.
      Specified by:
      writeUnsignedShort in class AbstractFileReaderAndWriter
      Parameters:
      v - an unsigned short to be written (int is converted to unsigned short).
      endianType - endian type. If it is big endian, natural byte order is preserved, otherwise byte order is reversed.
      Throws:
      IOException - if an I/O error occurs.
    • writeInt

      public void writeInt(int v) throws IOException
      Writes an int to the file as four bytes, high byte first. The write starts at the current position of the file pointer.
      Specified by:
      writeInt in class AbstractFileReaderAndWriter
      Parameters:
      v - an int to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeInt

      public void writeInt(int v, EndianType endianType) throws IOException
      Writes an int to the file as four bytes, using provided endian type. If endian type is big endian, then natural byte order is preserved (and high byte is written first), if little endian order is chosen, then byte order is reversed. The write starts at the current position of the file pointer.
      Specified by:
      writeInt in class AbstractFileReaderAndWriter
      Parameters:
      v - an int to be written.
      endianType - endian type. If it is big endian, natural byte order is preserved, otherwise byte order is reversed.
      Throws:
      IOException - if an I/O error occurs.
    • writeUnsignedInt

      public void writeUnsignedInt(long v) throws IOException
      Writes an unsigned int to the file as four bytes, high byte first. Provided integer value is converted to an unsigned int by taking into account only the four lower bytes. The write starts at the current position of the file pointer.
      Specified by:
      writeUnsignedInt in class AbstractFileReaderAndWriter
      Parameters:
      v - an unsigned int to be written (long is converted to unsigned int).
      Throws:
      IOException - if an I/O error occurs.
    • writeUnsignedInt

      public void writeUnsignedInt(long v, EndianType endianType) throws IOException
      Writes an unsigned int to the file as four bytes, using provided endian type. Provided integer value is converted to an unsigned int by taking into account only the four lower bytes. If endian type is big endian, then natural byte order is preserved (and high byte is written first), if little endian order is chosen, then byte order is reversed. The write starts at the current position of the file pointer.
      Specified by:
      writeUnsignedInt in class AbstractFileReaderAndWriter
      Parameters:
      v - an unsigned int to be written (long is converted to unsigned short).
      endianType - endian type. If it is big endian, natural byte order is preserved, otherwise byte order is reversed.
      Throws:
      IOException - if an I/O error occurs.
    • writeLong

      public void writeLong(long v) throws IOException
      Writes a long to the file as eight bytes, high byte first. The write starts at the current position of the file pointer.
      Specified by:
      writeLong in class AbstractFileReaderAndWriter
      Parameters:
      v - a long to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeLong

      public void writeLong(long v, EndianType endianType) throws IOException
      Writes a long to the file as eight bytes, using provided endian type. If endian type is big endian, then natural byte order is preserved (and high byte is written first), if little endian order is chosen, then byte order is reversed. The write starts at the current position of the file pointer.
      Specified by:
      writeLong in class AbstractFileReaderAndWriter
      Parameters:
      v - a long to be written.
      endianType - endian type. If it is big endian, natural byte order is preserved, otherwise byte order is reversed.
      Throws:
      IOException - if an I/O error occurs.
    • writeFloat

      public void writeFloat(float v) throws IOException
      Converts the float argument to an int using the floatToIntBits method in class Float, and then write that int value to the file as a four-byte quantity, high byte first. The write starts at the current position of the file pointer.
      Specified by:
      writeFloat in class AbstractFileReaderAndWriter
      Parameters:
      v - a float value to be written
      Throws:
      IOException - if an I/O error occurs.
    • writeFloat

      public void writeFloat(float v, EndianType endianType) throws IOException
      Converts the float argument to an int using the floatToIntBits method in class Float, and then write that int value to the file as a four-byte quantity, using provided endian type. If endian type is big endian, then natural byte order is preserved (and high byte is written first), if little endian order is chosen, then byte order is reversed. The write starts at the current position of the file pointer.
      Specified by:
      writeFloat in class AbstractFileReaderAndWriter
      Parameters:
      v - a float value to be written
      endianType - endian type. If it is big endian, natural byte order is preserved, otherwise byte order is reversed.
      Throws:
      IOException - if an I/O error occurs.
    • writeDouble

      public void writeDouble(double v) throws IOException
      Converts the double argument to a long using the doubleToLongBits method in class Double, and then writes that long value to the file as an eight byte quantity, high byte first. The write starts at the current position of the file pointer.
      Specified by:
      writeDouble in class AbstractFileReaderAndWriter
      Parameters:
      v - a double value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeDouble

      public void writeDouble(double v, EndianType endianType) throws IOException
      Converts the double argument to a long using the doubleToLongBits method in class Double, and then writes that long value to the file as an eight byte quantity, using provided endian type. If endian type is big endian, then natural byte order is preserved (and high byte is written first), if little endian order is chosen, then byte order is reversed. The write starts at the current position of the file pointer.
      Specified by:
      writeDouble in class AbstractFileReaderAndWriter
      Parameters:
      v - a double value to be written.
      endianType - endian type. If it is big endian, natural byte order is preserved, otherwise byte order is reversed.
      Throws:
      IOException - if an I/O error occurs.
    • writeASCII

      public void writeASCII(String s) throws IOException
      Writes the string to the file as a sequence of bytes. Each character in the string is written out, in sequence, by discarding its high eight bits. The write starts at the current position of the file pointer.
      Specified by:
      writeASCII in class AbstractFileReaderAndWriter
      Parameters:
      s - a string of bytes to be written.
      Throws:
      IOException - if an I/O error occurs.