throws IOException, SAXException, TikaException { int maybeLength = EndianUtils.readUShortLE(stream); if(maybeLength == 0) { int length = EndianUtils.getUShortLE(b2); if(length > 1 && length <= MAX_SANE_TEXT_LENGTH) {
private ResourceBlock(InputStream stream) throws IOException, TikaException { long sig = EndianUtils.readIntBE(stream); if (sig != SIGNATURE) { throw new TikaException("Invalid Image Resource Block Signature Found, got " + id = EndianUtils.readUShortBE(stream); int dataLen = EndianUtils.readIntBE(stream); if (dataLen % 2 == 1) {
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; }
/** * Get a LE short value from an InputStream * * @param stream the InputStream from which the short is to be read * @return the short (16-bit) value * @throws IOException will be propagated back to the caller * @throws BufferUnderrunException if the stream cannot provide enough bytes */ public static short readShortLE(InputStream stream) throws IOException, BufferUnderrunException { return (short) readUShortLE(stream); }
type = EndianUtils.readUShortLE(stream); } else { type = EndianUtils.readUShortBE(stream); machine = EndianUtils.readUShortLE(stream); } else { machine = EndianUtils.readUShortBE(stream);
/** * Get a LE unsigned short value from the beginning of a byte array * * @param data the byte array * @return the unsigned short (16-bit) value in an int */ public static int getUShortLE(byte[] data) { return getUShortLE(data, 0); }
/** * Get a BE short value from an InputStream * * @param stream the InputStream from which the short is to be read * @return the short (16-bit) value * @throws IOException will be propagated back to the caller * @throws BufferUnderrunException if the stream cannot provide enough bytes */ public static short readShortBE(InputStream stream) throws IOException, BufferUnderrunException { return (short) readUShortBE(stream); }
@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 long readUInt(InputStream is) throws IOException { try { return EndianUtils.readUIntLE(is); } catch (EndianUtils.BufferUnderrunException e) { throw new IOException(e); } }
@Test public void testReadUE7() throws Exception { byte[] data; data = new byte[] { 0x08 }; assertEquals((long)8, EndianUtils.readUE7(new ByteArrayInputStream(data))); data = new byte[] { (byte)0x84, 0x1e }; assertEquals((long)542, EndianUtils.readUE7(new ByteArrayInputStream(data))); data = new byte[] { (byte)0xac, (byte)0xbe, 0x17 }; assertEquals((long)728855, EndianUtils.readUE7(new ByteArrayInputStream(data))); }
/** * Get a BE unsigned int value from a byte array * * @param data the byte array * @param offset a starting offset into the byte array * @return the unsigned int (32-bit) value in a long */ public static long getUIntBE(byte[] data, int offset) { long retNum = getIntBE(data, offset); return retNum & 0x00FFFFFFFFl; }
/** * Get a LE unsigned int value from a byte array * * @param data the byte array * @param offset a starting offset into the byte array * @return the unsigned int (32-bit) value in a long */ public static long getUIntLE(byte[] data, int offset) { long retNum = getIntLE(data, offset); return retNum & 0x00FFFFFFFFl; }
/** * Get a BE short value from the beginning of a byte array * * @param data the byte array * @return the short (16-bit) value */ public static short getShortBE(byte[] data) { return getShortBE(data, 0); }
/** * Grab the offset, then skip there */ private boolean skipToPropertyInfoSection(InputStream stream, byte[] header) throws IOException, TikaException { // The offset is stored in the header from 0x20 onwards long offsetToSection = EndianUtils.getLongLE(header, 0x20); // Sanity check the offset. Some files seem to use a different format, // and the offset isn't available at 0x20. Until we can work out how // to find the offset in those files, skip them if detected if (offsetToSection > 0xa00000l) { // Header should never be more than 10mb into the file, something is wrong offsetToSection = 0; } // Work out how far to skip, and sanity check long toSkip = offsetToSection - header.length; if(offsetToSection == 0){ return false; } while (toSkip > 0) { byte[] skip = new byte[Math.min((int) toSkip, 0x4000)]; IOUtils.readFully(stream, skip); toSkip -= skip.length; } return true; }
private int readUShort(InputStream is) throws IOException { try { return EndianUtils.readUShortLE(is); } catch (EndianUtils.BufferUnderrunException e) { throw new IOException(e); } }
type = EndianUtils.readUShortLE(stream); } else { type = EndianUtils.readUShortBE(stream); machine = EndianUtils.readUShortLE(stream); } else { machine = EndianUtils.readUShortBE(stream);
/** * Get a LE short value from a byte array * * @param data the byte array * @param offset a starting offset into the byte array * @return the short (16-bit) value */ public static short getShortLE(byte[] data, int offset) { return (short) getUShortLE(data, offset); }
EndianUtils.readUShortBE(is); } catch (EndianUtils.BufferUnderrunException e) { throw new IOException(e);
@Test public void testReadUIntLE() throws Exception { byte[] data = new byte[] {(byte)0x08, (byte)0x00, (byte)0x00, (byte)0x00 }; assertEquals((long) 8, EndianUtils.readUIntLE(new ByteArrayInputStream(data))); data = new byte[] {(byte)0xF0, (byte)0xFF, (byte)0xFF, (byte)0xFF }; assertEquals(4294967280L, EndianUtils.readUIntLE(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) { } }
int width = (int) EndianUtils.readUE7(stream); int height = (int) EndianUtils.readUE7(stream); metadata.set(TIFF.IMAGE_LENGTH, height); metadata.set(TIFF.IMAGE_WIDTH, width); EndianUtils.readUE7(stream); extensionDataLength = EndianUtils.readUE7(stream); alphaDataLength = EndianUtils.readUE7(stream); int extensionType = (int) EndianUtils.readUE7(stream); int extensionLength = (int) EndianUtils.readUE7(stream); switch (extensionType) { case EXTENSION_TAG_EXIF: