offset += 2;
}
- int rtn = toUnsignedInt(buffer.get(offset));
- rtn += (toUnsignedInt(buffer.get(offset + (1 * offInc))) << 8);
- rtn += (toUnsignedInt(buffer.get(offset + (2 * offInc))) << 16);
- rtn &= 0xFFFFFF;
+ int rtn = getUnsignedByte(buffer, offset);
+ rtn += (getUnsignedByte(buffer, offset + (1 * offInc)) << 8);
+ rtn += (getUnsignedByte(buffer, offset + (2 * offInc)) << 16);
return rtn;
}
/**
+ * Read a 3 byte int from a buffer
+ * @param buffer Buffer containing the bytes
+ * @return The int
+ */
+ public static int getUnsignedByte(ByteBuffer buffer) {
+ int pos = buffer.position();
+ int rtn = getUnsignedByte(buffer, pos);
+ buffer.position(pos + 1);
+ return rtn;
+ }
+
+ /**
+ * Read a 3 byte int from a buffer
+ * @param buffer Buffer containing the bytes
+ * @param offset Offset at which to read the byte
+ * @return The int
+ */
+ public static int getUnsignedByte(ByteBuffer buffer, int offset) {
+ return asUnsignedByte(buffer.get(offset));
+ }
+
+
+ /**
+ * @param buffer Buffer containing the bytes
+ * @param order the order of the bytes of the int
* @return an int from the current position in the given buffer, read using
* the given ByteOrder
*/
}
/**
+ * @param buffer Buffer containing the bytes
+ * @param offset Offset at which to start reading the int
+ * @param order the order of the bytes of the int
* @return an int from the given position in the given buffer, read using
* the given ByteOrder
*/
/**
* Writes an int at the current position in the given buffer, using the
* given ByteOrder
+ * @param buffer buffer into which to insert the int
+ * @param val Int to insert
+ * @param order the order to insert the bytes of the int
*/
public static void putInt(ByteBuffer buffer, int val, ByteOrder order) {
int offset = buffer.position();
/**
* Writes an int at the given position in the given buffer, using the
* given ByteOrder
+ * @param buffer buffer into which to insert the int
+ * @param val Int to insert
+ * @param offset offset at which to insert the int
+ * @param order the order to insert the bytes of the int
*/
public static void putInt(ByteBuffer buffer, int val, int offset,
ByteOrder order)
return toHexString(buffer, 0, size);
}
+ /**
+ * Convert a byte array to a hexadecimal string for display
+ * @param buffer Buffer to display, starting at offset 0
+ * @return The display String
+ */
+ public static String toHexString(byte[] array) {
+ return toHexString(ByteBuffer.wrap(array), 0, array.length);
+ }
+
/**
* Convert a byte buffer to a hexadecimal string for display
* @param buffer Buffer to display, starting at offset 0
/**
* @return the byte value converted to an unsigned int value
*/
- public static int toUnsignedInt(byte b) {
+ public static int asUnsignedByte(byte b) {
return b & 0xFF;
}
lvalDefinition.length);
}
- int rowNum = ByteUtil.toUnsignedInt(def.get());
+ int rowNum = ByteUtil.getUnsignedByte(def);
int pageNum = ByteUtil.get3ByteInt(def, def.position());
ByteBuffer lvalPage = getPageChannel().createPageBuffer();
// read next page information
lvalPage.position(rowStart);
- rowNum = ByteUtil.toUnsignedInt(lvalPage.get());
+ rowNum = ByteUtil.getUnsignedByte(lvalPage);
pageNum = ByteUtil.get3ByteInt(lvalPage);
// update rowEnd and remainingLen based on chunkLength
++pos;
}
if(pos < len) {
- return ((ByteUtil.toUnsignedInt(left[pos]) <
- ByteUtil.toUnsignedInt(right[pos])) ? -1 : 1);
+ return ((ByteUtil.asUnsignedByte(left[pos]) <
+ ByteUtil.asUnsignedByte(right[pos])) ? -1 : 1);
}
return ((left.length < right.length) ? -1 :
((left.length > right.length) ? 1 : 0));
{
// note, "header" data is in LITTLE_ENDIAN format, entry data is in
// BIG_ENDIAN format
- int numCompressedBytes = indexPage.get(
- getFormat().OFFSET_INDEX_COMPRESSED_BYTE_COUNT);
+ int numCompressedBytes = ByteUtil.getUnsignedByte(
+ indexPage, getFormat().OFFSET_INDEX_COMPRESSED_BYTE_COUNT);
int entryMaskLength = getFormat().SIZE_INDEX_ENTRY_MASK;
int entryMaskPos = getFormat().OFFSET_INDEX_ENTRY_MASK;
int entryPos = entryMaskPos + getFormat().SIZE_INDEX_ENTRY_MASK;
// read the rowId
int page = ByteUtil.get3ByteInt(buffer, ByteOrder.BIG_ENDIAN);
- int row = ByteUtil.toUnsignedInt(buffer.get());
+ int row = ByteUtil.getUnsignedByte(buffer);
_rowId = new RowId(page, row);
_type = EntryType.NORMAL;
// Overflow page. the "row" data in the current page points to
// another page/row
- int overflowRowNum = ByteUtil.toUnsignedInt(rowBuffer.get(rowStart));
+ int overflowRowNum = ByteUtil.getUnsignedByte(rowBuffer, rowStart);
int overflowPageNum = ByteUtil.get3ByteInt(rowBuffer, rowStart + 1);
rowBuffer = rowState.setOverflowRow(
new RowId(overflowPageNum, overflowRowNum));
_indexSlotCount = tableBuffer.getInt(getFormat().OFFSET_NUM_INDEX_SLOTS);
_indexCount = tableBuffer.getInt(getFormat().OFFSET_NUM_INDEXES);
- int rowNum = ByteUtil.toUnsignedInt(
- tableBuffer.get(getFormat().OFFSET_OWNED_PAGES));
+ int rowNum = ByteUtil.getUnsignedByte(
+ tableBuffer, getFormat().OFFSET_OWNED_PAGES);
int pageNum = ByteUtil.get3ByteInt(tableBuffer, getFormat().OFFSET_OWNED_PAGES + 1);
_ownedPages = UsageMap.read(getDatabase(), pageNum, rowNum, false);
- rowNum = ByteUtil.toUnsignedInt(
- tableBuffer.get(getFormat().OFFSET_FREE_SPACE_PAGES));
+ rowNum = ByteUtil.getUnsignedByte(
+ tableBuffer, getFormat().OFFSET_FREE_SPACE_PAGES);
pageNum = ByteUtil.get3ByteInt(tableBuffer, getFormat().OFFSET_FREE_SPACE_PAGES + 1);
_freeSpacePages = UsageMap.read(getDatabase(), pageNum, rowNum, false);
Object obj = iter.next();
if (obj instanceof byte[]) {
byte[] b = (byte[]) obj;
- rtn.append(ByteUtil.toHexString(ByteBuffer.wrap(b), b.length));
+ rtn.append(ByteUtil.toHexString(b));
//This block can be used to easily dump a binary column to a file
/*java.io.File f = java.io.File.createTempFile("ole", ".bin");
java.io.FileOutputStream out = new java.io.FileOutputStream(f);
byte b4 = (byte)0x80;
byte b5 = (byte)0xFF;
- assertTrue(ByteUtil.toUnsignedInt(b1) < ByteUtil.toUnsignedInt(b2));
- assertTrue(ByteUtil.toUnsignedInt(b2) < ByteUtil.toUnsignedInt(b3));
- assertTrue(ByteUtil.toUnsignedInt(b3) < ByteUtil.toUnsignedInt(b4));
- assertTrue(ByteUtil.toUnsignedInt(b4) < ByteUtil.toUnsignedInt(b5));
+ assertTrue(ByteUtil.asUnsignedByte(b1) < ByteUtil.asUnsignedByte(b2));
+ assertTrue(ByteUtil.asUnsignedByte(b2) < ByteUtil.asUnsignedByte(b3));
+ assertTrue(ByteUtil.asUnsignedByte(b3) < ByteUtil.asUnsignedByte(b4));
+ assertTrue(ByteUtil.asUnsignedByte(b4) < ByteUtil.asUnsignedByte(b5));
}
public void testByteCodeComparator() {