Class ReadBuffer

java.lang.Object
org.oscim.tiling.source.mapfile.ReadBuffer

public class ReadBuffer extends Object
Reads from a RandomAccessFile into a buffer and decodes the data.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    byte
    Returns one byte from the read buffer.
    float
    Converts four bytes from the read buffer to a float.
    boolean
    readFromFile(int length)
    Reads the given amount of bytes from the file into the read buffer and resets the internal buffer position.
    boolean
    readFromFile(long offset, int length)
    Reads the given amount of bytes from the file into the read buffer and resets the internal buffer position.
    int
    Converts four bytes from the read buffer to a signed int.
    long
    Converts eight bytes from the read buffer to a signed long.
    int
    Converts two bytes from the read buffer to a signed int.
    int
    Converts a variable amount of bytes from the read buffer to a signed int.
    void
    readSignedInt(int[] values, int length)
    Converts a variable amount of bytes from the read buffer to a signed int array.
    int
    Converts a variable amount of bytes from the read buffer to an unsigned int.
    Decodes a variable amount of bytes from the read buffer to a string.
    readUTF8EncodedString(int stringLength)
    Decodes the given amount of bytes from the read buffer to a string.
    Decodes a variable amount of bytes from the read buffer to a string.

    Methods inherited from class java.lang.Object

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

    • readByte

      public byte readByte()
      Returns one byte from the read buffer.
      Returns:
      the byte value.
    • readFloat

      public float readFloat()
      Converts four bytes from the read buffer to a float.

      The byte order is big-endian.

      Returns:
      the float value.
    • readFromFile

      public boolean readFromFile(int length) throws IOException
      Reads the given amount of bytes from the file into the read buffer and resets the internal buffer position. If the capacity of the read buffer is too small, a larger one is created automatically.
      Parameters:
      length - the amount of bytes to read from the file.
      Returns:
      true if the whole data was read successfully, false otherwise.
      Throws:
      IOException - if an error occurs while reading the file.
    • readFromFile

      public boolean readFromFile(long offset, int length) throws IOException
      Reads the given amount of bytes from the file into the read buffer and resets the internal buffer position. If the capacity of the read buffer is too small, a larger one is created automatically.
      Parameters:
      offset - the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
      length - the amount of bytes to read from the file.
      Returns:
      true if the whole data was read successfully, false otherwise.
      Throws:
      IOException - if an error occurs while reading the file.
    • readInt

      public int readInt()
      Converts four bytes from the read buffer to a signed int.

      The byte order is big-endian.

      Returns:
      the int value.
    • readLong

      public long readLong()
      Converts eight bytes from the read buffer to a signed long.

      The byte order is big-endian.

      Returns:
      the long value.
    • readShort

      public int readShort()
      Converts two bytes from the read buffer to a signed int.

      The byte order is big-endian.

      Returns:
      the int value.
    • readSignedInt

      public int readSignedInt()
      Converts a variable amount of bytes from the read buffer to a signed int.

      The first bit is for continuation info, the other six (last byte) or seven (all other bytes) bits are for data. The second bit in the last byte indicates the sign of the number.

      Returns:
      the value.
    • readSignedInt

      public void readSignedInt(int[] values, int length)
      Converts a variable amount of bytes from the read buffer to a signed int array.

      The first bit is for continuation info, the other six (last byte) or seven (all other bytes) bits are for data. The second bit in the last byte indicates the sign of the number.

      Parameters:
      values - result values
      length - number of values to read
    • readUnsignedInt

      public int readUnsignedInt()
      Converts a variable amount of bytes from the read buffer to an unsigned int.

      The first bit is for continuation info, the other seven bits are for data.

      Returns:
      the int value.
    • readUTF8EncodedString

      public String readUTF8EncodedString()
      Decodes a variable amount of bytes from the read buffer to a string.
      Returns:
      the UTF-8 decoded string (may be null).
    • getPositionAndSkip

      public int getPositionAndSkip()
      Returns:
      ...
    • readUTF8EncodedString

      public String readUTF8EncodedString(int stringLength)
      Decodes the given amount of bytes from the read buffer to a string.
      Parameters:
      stringLength - the length of the string in bytes.
      Returns:
      the UTF-8 decoded string (may be null).
    • readUTF8EncodedStringAt

      public String readUTF8EncodedStringAt(int position)
      Decodes a variable amount of bytes from the read buffer to a string.
      Parameters:
      position - buffer offset position of string
      Returns:
      the UTF-8 decoded string (may be null).