}
/**
- * Read a 3 byte int from a buffer
+ * Read an unsigned byte from a buffer
* @param buffer Buffer containing the bytes
- * @return The int
+ * @return The unsigned byte as an int
*/
public static int getUnsignedByte(ByteBuffer buffer) {
int pos = buffer.position();
}
/**
- * Read a 3 byte int from a buffer
+ * Read an unsigned byte from a buffer
* @param buffer Buffer containing the bytes
* @param offset Offset at which to read the byte
- * @return The int
+ * @return The unsigned byte as an int
*/
public static int getUnsignedByte(ByteBuffer buffer, int offset) {
return asUnsignedByte(buffer.get(offset));
}
+
+ /**
+ * Read an unsigned short from a buffer
+ * @param buffer Buffer containing the short
+ * @return The unsigned short as an int
+ */
+ public static int getUnsignedShort(ByteBuffer buffer) {
+ int pos = buffer.position();
+ int rtn = getUnsignedShort(buffer, pos);
+ buffer.position(pos + 2);
+ return rtn;
+ }
+
+ /**
+ * Read an unsigned short from a buffer
+ * @param buffer Buffer containing the short
+ * @param offset Offset at which to read the short
+ * @return The unsigned short as an int
+ */
+ public static int getUnsignedShort(ByteBuffer buffer, int offset) {
+ return asUnsignedShort(buffer.getShort(offset));
+ }
/**
return b & 0xFF;
}
+ /**
+ * @return the short value converted to an unsigned int value
+ */
+ public static int asUnsignedShort(short s) {
+ return s & 0xFFFF;
+ }
+
}
* 2) bytes encoded using the {@link JetFormat#CHARSET}
*/
private String readName(ByteBuffer buffer) {
- short nameLength = buffer.getShort();
+ int nameLength = ByteUtil.getUnsignedShort(buffer);
byte[] nameBytes = new byte[nameLength];
buffer.get(nameBytes);
return Column.decodeUncompressedText(nameBytes, getFormat());
* expected name format is the same as that for {@link #readName}.
*/
private void skipName(ByteBuffer buffer) {
- short nameLength = buffer.getShort();
+ int nameLength = ByteUtil.getUnsignedShort(buffer);
buffer.position(buffer.position() + nameLength);
}