/** test the getShort() method */ public void testGetShort() { byte[] testdata = new byte[LittleEndian.SHORT_SIZE + 1]; testdata[0] = 0x01; testdata[1] = (byte) 0xFF; testdata[2] = 0x02; short expected[] = new short[2]; expected[0] = (short) 0xFF01; expected[1] = 0x02FF; assertEquals(expected[0], LittleEndian.getShort(testdata)); assertEquals(expected[1], LittleEndian.getShort(testdata, 1)); }
public FIBFieldHandler( byte mainStream[], int startOffset, byte tableStream[], HashSet offsetList, boolean areKnown) { _unknownMap = new HashMap(); int numFields = LittleEndian.getShort(mainStream, startOffset); int offset = startOffset + 2; _fields = new int[numFields * 2]; for (int x = 0; x < numFields; x++) { int fieldOffset = x * 8 + offset; int dsOffset = LittleEndian.getInt(mainStream, fieldOffset); fieldOffset += 4; int dsSize = LittleEndian.getInt(mainStream, fieldOffset); if (offsetList.contains(Integer.valueOf(x)) ^ areKnown && dsSize > 0) if (dsOffset + dsSize > tableStream.length) { log.log( POILogger.WARN, (new StringBuilder()) .append("Unhandled data structure points to outside the buffer. offset = ") .append(dsOffset) .append(", length = ") .append(dsSize) .append(", buffer length = ") .append(tableStream.length) .toString()); } else { UnhandledDataStructure unhandled = new UnhandledDataStructure(tableStream, dsOffset, dsSize); _unknownMap.put(Integer.valueOf(x), unhandled); } _fields[x * 2] = dsOffset; _fields[x * 2 + 1] = dsSize; } }
/** * Read the options field from header and return instance part of it. * * @param data the byte array to read from * @param offset the offset to start reading from * @return value of instance part of options field */ protected static short readInstance(byte data[], int offset) { final short options = LittleEndian.getShort(data, offset); return fInstance.getShortValue(options); }
/** * Reads the 8 byte header information and populates the <code>options</code> and <code>recordId * </code> records. * * @param data the byte array to read from * @param offset the offset to start reading from * @return the number of bytes remaining in this record. This may include the children if this is * a container. */ protected int readHeader(byte[] data, int offset) { _options = LittleEndian.getShort(data, offset); _recordId = LittleEndian.getShort(data, offset + 2); int remainingBytes = LittleEndian.getInt(data, offset + 4); return remainingBytes; }
@Test public void testGetShort() { Binary binary = BinaryFactory.wrap(new byte[] {0x01, 0x02, (byte) 0xC1, (byte) 0xC2}); assertEquals("Wrong value", (short) 0x0201, LittleEndian.getShort(binary, 0)); assertEquals("Wrong value", (short) 0xC2C1, LittleEndian.getShort(binary, 2)); }