Package org.oscim.tiling.source.mapfile
Class ReadBuffer
java.lang.Object
org.oscim.tiling.source.mapfile.ReadBuffer
Reads from a
RandomAccessFile into a buffer and decodes the data.-
Method Summary
Modifier and TypeMethodDescriptionintbytereadByte()Returns one byte from the read buffer.floatConverts four bytes from the read buffer to a float.booleanreadFromFile(int length) Reads the given amount of bytes from the file into the read buffer and resets the internal buffer position.booleanreadFromFile(long offset, int length) Reads the given amount of bytes from the file into the read buffer and resets the internal buffer position.intreadInt()Converts four bytes from the read buffer to a signed int.longreadLong()Converts eight bytes from the read buffer to a signed long.intConverts two bytes from the read buffer to a signed int.intConverts a variable amount of bytes from the read buffer to a signed int.voidreadSignedInt(int[] values, int length) Converts a variable amount of bytes from the read buffer to a signed int array.intConverts 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.readUTF8EncodedStringAt(int position) Decodes a variable amount of bytes from the read buffer to a string.
-
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
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
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 valueslength- 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
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
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
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).
-