private List<FieldInfo> getSortedFieldInfoList(InputStream stream, short numEntries) throws IOException, TikaException { //this is probably overkill. I'd hope that these were already //in order. This ensures it. List<FieldInfo> fieldInfoList = new ArrayList<>(numEntries); for (int i = 0; i < numEntries; i++) { //convert 32-bit unsigned ints to longs fieldInfoList.add( new FieldInfo( EndianUtils.readUIntBE(stream), //entry id EndianUtils.readUIntBE(stream), //offset EndianUtils.readUIntBE(stream) //length ) ); } if (fieldInfoList.size() == 0) { throw new TikaException("AppleSingleFile missing field info"); } //make absolutely sure these are in order! Collections.sort(fieldInfoList, new FieldInfoComparator()); return fieldInfoList; }
@Test public void testReadUIntBE() throws Exception { byte[] data = new byte[] {(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x08 }; assertEquals((long) 8, EndianUtils.readUIntBE(new ByteArrayInputStream(data))); data = new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xF0 }; assertEquals(4294967280L, EndianUtils.readUIntBE(new ByteArrayInputStream(data))); data = new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF }; try { EndianUtils.readUIntLE(new ByteArrayInputStream(data)); fail("Should have thrown exception"); } catch (EndianUtils.BufferUnderrunException e) { } } }
private List<FieldInfo> getSortedFieldInfoList(InputStream stream, short numEntries) throws IOException, TikaException { //this is probably overkill. I'd hope that these were already //in order. This ensures it. List<FieldInfo> fieldInfoList = new ArrayList<>(numEntries); for (int i = 0; i < numEntries; i++) { //convert 32-bit unsigned ints to longs fieldInfoList.add( new FieldInfo( EndianUtils.readUIntBE(stream), //entry id EndianUtils.readUIntBE(stream), //offset EndianUtils.readUIntBE(stream) //length ) ); } if (fieldInfoList.size() == 0) { throw new TikaException("AppleSingleFile missing field info"); } //make absolutely sure these are in order! Collections.sort(fieldInfoList, new FieldInfoComparator()); return fieldInfoList; }
private List<FieldInfo> getSortedFieldInfoList(InputStream stream, short numEntries) throws IOException, TikaException { //this is probably overkill. I'd hope that these were already //in order. This ensures it. List<FieldInfo> fieldInfoList = new ArrayList<>(numEntries); for (int i = 0; i < numEntries; i++) { //convert 32-bit unsigned ints to longs fieldInfoList.add( new FieldInfo( EndianUtils.readUIntBE(stream), //entry id EndianUtils.readUIntBE(stream), //offset EndianUtils.readUIntBE(stream) //length ) ); } if (fieldInfoList.size() == 0) { throw new TikaException("AppleSingleFile missing field info"); } //make absolutely sure these are in order! Collections.sort(fieldInfoList, new FieldInfoComparator()); return fieldInfoList; }