Java Code Examples for org.apache.poi.util.LittleEndian#getInt()
The following examples show how to use
org.apache.poi.util.LittleEndian#getInt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EscherSpgrRecord.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { int bytesRemaining = readHeader( data, offset ); int pos = offset + 8; int size = 0; field_1_rectX1 = LittleEndian.getInt( data, pos + size );size+=4; field_2_rectY1 = LittleEndian.getInt( data, pos + size );size+=4; field_3_rectX2 = LittleEndian.getInt( data, pos + size );size+=4; field_4_rectY2 = LittleEndian.getInt( data, pos + size );size+=4; bytesRemaining -= size; if (bytesRemaining != 0) { throw new RecordFormatException("Expected no remaining bytes but got " + bytesRemaining); } // remainingData = new byte[bytesRemaining]; // System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining ); return 8 + size + bytesRemaining; }
Example 2
Source File: EscherChildAnchorRecord.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { int bytesRemaining = readHeader( data, offset ); int pos = offset + 8; int size = 0; switch (bytesRemaining) { case 16: // RectStruct field_1_dx1 = LittleEndian.getInt( data, pos + size );size+=4; field_2_dy1 = LittleEndian.getInt( data, pos + size );size+=4; field_3_dx2 = LittleEndian.getInt( data, pos + size );size+=4; field_4_dy2 = LittleEndian.getInt( data, pos + size );size+=4; break; case 8: // SmallRectStruct field_1_dx1 = LittleEndian.getShort( data, pos + size );size+=2; field_2_dy1 = LittleEndian.getShort( data, pos + size );size+=2; field_3_dx2 = LittleEndian.getShort( data, pos + size );size+=2; field_4_dy2 = LittleEndian.getShort( data, pos + size );size+=2; break; default: throw new RuntimeException("Invalid EscherChildAnchorRecord - neither 8 nor 16 bytes."); } return 8 + size; }
Example 3
Source File: BATBlock.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Create a single BATBlock from the byte buffer, which must hold at least * one big block of data to be read. */ public static BATBlock createBATBlock(final POIFSBigBlockSize bigBlockSize, ByteBuffer data) { // Create an empty block BATBlock block = new BATBlock(bigBlockSize); // Fill it byte[] buffer = new byte[LittleEndian.INT_SIZE]; for(int i=0; i<block._values.length; i++) { data.get(buffer); block._values[i] = LittleEndian.getInt(buffer); } block.recomputeFree(); // All done return block; }
Example 4
Source File: EscherDgRecord.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { /*int bytesRemaining =*/ readHeader( data, offset ); int pos = offset + 8; int size = 0; field_1_numShapes = LittleEndian.getInt( data, pos + size ); size += 4; field_2_lastMSOSPID = LittleEndian.getInt( data, pos + size ); size += 4; // bytesRemaining -= size; // remainingData = new byte[bytesRemaining]; // System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining ); return getRecordSize(); }
Example 5
Source File: EscherSpRecord.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { /*int bytesRemaining =*/ readHeader( data, offset ); int pos = offset + 8; int size = 0; field_1_shapeId = LittleEndian.getInt( data, pos + size ); size += 4; field_2_flags = LittleEndian.getInt( data, pos + size ); size += 4; // bytesRemaining -= size; // remainingData = new byte[bytesRemaining]; // System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining ); return getRecordSize(); }
Example 6
Source File: ImageHeaderWMF.java From lams with GNU General Public License v2.0 | 5 votes |
public ImageHeaderWMF(byte[] data, final int off) { int offset = off; int key = LittleEndian.getInt(data, offset); offset += LittleEndian.INT_SIZE; //header key if (key != APMHEADER_KEY) { LOG.log(POILogger.WARN, "WMF file doesn't contain a placeable header - ignore parsing"); handle = 0; left = 0; top = 0; right = 200; bottom = 200; inch = Units.POINT_DPI; //default resolution is 72 dpi reserved = 0; return; } handle = LittleEndian.getUShort(data, offset); offset += LittleEndian.SHORT_SIZE; left = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; top = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; right = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; bottom = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; inch = LittleEndian.getUShort(data, offset); offset += LittleEndian.SHORT_SIZE; reserved = LittleEndian.getInt(data, offset); offset += LittleEndian.INT_SIZE; checksum = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; if (checksum != getChecksum()){ LOG.log(POILogger.WARN, "WMF checksum does not match the header data"); } }
Example 7
Source File: NDocumentInputStream.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int readInt() { checkAvaliable(SIZE_INT); byte[] data = new byte[SIZE_INT]; readFully(data, 0, SIZE_INT); return LittleEndian.getInt(data); }
Example 8
Source File: EscherMetafileBlip.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { int bytesAfterHeader = readHeader( data, offset ); int pos = offset + HEADER_SIZE; System.arraycopy( data, pos, field_1_UID, 0, 16 ); pos += 16; if((getOptions() ^ getSignature()) == 0x10){ System.arraycopy( data, pos, field_2_UID, 0, 16 ); pos += 16; } field_2_cb = LittleEndian.getInt( data, pos ); pos += 4; field_3_rcBounds_x1 = LittleEndian.getInt( data, pos ); pos += 4; field_3_rcBounds_y1 = LittleEndian.getInt( data, pos ); pos += 4; field_3_rcBounds_x2 = LittleEndian.getInt( data, pos ); pos += 4; field_3_rcBounds_y2 = LittleEndian.getInt( data, pos ); pos += 4; field_4_ptSize_w = LittleEndian.getInt( data, pos ); pos += 4; field_4_ptSize_h = LittleEndian.getInt( data, pos ); pos += 4; field_5_cbSave = LittleEndian.getInt( data, pos ); pos += 4; field_6_fCompression = data[pos]; pos++; field_7_fFilter = data[pos]; pos++; raw_pictureData = new byte[field_5_cbSave]; System.arraycopy( data, pos, raw_pictureData, 0, field_5_cbSave ); pos += field_5_cbSave; // 0 means DEFLATE compression // 0xFE means no compression if (field_6_fCompression == 0) { super.setPictureData(inflatePictureData(raw_pictureData)); } else { super.setPictureData(raw_pictureData); } int remaining = bytesAfterHeader - pos + offset + HEADER_SIZE; if(remaining > 0) { remainingData = new byte[remaining]; System.arraycopy( data, pos, remainingData, 0, remaining ); } return bytesAfterHeader + HEADER_SIZE; }
Example 9
Source File: EscherBSERecord.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { int bytesRemaining = readHeader( data, offset ); int pos = offset + 8; field_1_blipTypeWin32 = data[pos]; field_2_blipTypeMacOS = data[pos + 1]; System.arraycopy( data, pos + 2, field_3_uid, 0, 16 ); field_4_tag = LittleEndian.getShort( data, pos + 18 ); field_5_size = LittleEndian.getInt( data, pos + 20 ); field_6_ref = LittleEndian.getInt( data, pos + 24 ); field_7_offset = LittleEndian.getInt( data, pos + 28 ); field_8_usage = data[pos + 32]; field_9_name = data[pos + 33]; field_10_unused2 = data[pos + 34]; field_11_unused3 = data[pos + 35]; bytesRemaining -= 36; int bytesRead = 0; if (bytesRemaining > 0) { // Some older escher formats skip this last record field_12_blipRecord = (EscherBlipRecord) recordFactory.createRecord( data, pos + 36 ); bytesRead = field_12_blipRecord.fillFields( data, pos + 36, recordFactory ); } pos += 36 + bytesRead; bytesRemaining -= bytesRead; _remainingData = new byte[bytesRemaining]; System.arraycopy( data, pos, _remainingData, 0, bytesRemaining ); return bytesRemaining + 8 + 36 + (field_12_blipRecord == null ? 0 : field_12_blipRecord.getRecordSize()) ; }
Example 10
Source File: EscherPictBlip.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { int bytesAfterHeader = readHeader(data, offset); int pos = offset + HEADER_SIZE; System.arraycopy( data, pos, field_1_UID, 0, 16 ); pos += 16; field_2_cb = LittleEndian.getInt( data, pos ); pos += 4; field_3_rcBounds_x1 = LittleEndian.getInt( data, pos ); pos += 4; field_3_rcBounds_y1 = LittleEndian.getInt( data, pos ); pos += 4; field_3_rcBounds_x2 = LittleEndian.getInt( data, pos ); pos += 4; field_3_rcBounds_y2 = LittleEndian.getInt( data, pos ); pos += 4; field_4_ptSize_w = LittleEndian.getInt( data, pos ); pos += 4; field_4_ptSize_h = LittleEndian.getInt( data, pos ); pos += 4; field_5_cbSave = LittleEndian.getInt( data, pos ); pos += 4; field_6_fCompression = data[pos]; pos++; field_7_fFilter = data[pos]; pos++; raw_pictureData = new byte[field_5_cbSave]; System.arraycopy( data, pos, raw_pictureData, 0, field_5_cbSave ); // 0 means DEFLATE compression // 0xFE means no compression if (field_6_fCompression == 0) { super.setPictureData(inflatePictureData(raw_pictureData)); } else { super.setPictureData(raw_pictureData); } return bytesAfterHeader + HEADER_SIZE; }
Example 11
Source File: Biff8DecryptingStream.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int readInt() { if (shouldSkipEncryptionOnCurrentRecord) { readPlain(buffer, 0, LittleEndianConsts.INT_SIZE); return LittleEndian.getInt(buffer); } else { return ccis.readInt(); } }
Example 12
Source File: BoundSheetRecord.java From lams with GNU General Public License v2.0 | 5 votes |
/** * UTF8: sid + len + bof + flags + len(str) + unicode + str 2 + 2 + 4 + 2 + * 1 + 1 + len(str) * * UNICODE: sid + len + bof + flags + len(str) + unicode + str 2 + 2 + 4 + 2 + * 1 + 1 + 2 * len(str) * * @param in the record stream to read from */ public BoundSheetRecord(RecordInputStream in) { byte buf[] = new byte[LittleEndianConsts.INT_SIZE]; in.readPlain(buf, 0, buf.length); field_1_position_of_BOF = LittleEndian.getInt(buf); field_2_option_flags = in.readUShort(); int field_3_sheetname_length = in.readUByte(); field_4_isMultibyteUnicode = in.readByte(); if (isMultibyte()) { field_5_sheetname = in.readUnicodeLEString(field_3_sheetname_length); } else { field_5_sheetname = in.readCompressedUnicode(field_3_sheetname_length); } }
Example 13
Source File: EscherDggRecord.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { int bytesRemaining = readHeader( data, offset ); int pos = offset + 8; int size = 0; field_1_shapeIdMax = LittleEndian.getInt( data, pos + size );size+=4; // field_2_numIdClusters = LittleEndian.getInt( data, pos + size ); size+=4; field_3_numShapesSaved = LittleEndian.getInt( data, pos + size );size+=4; field_4_drawingsSaved = LittleEndian.getInt( data, pos + size );size+=4; field_5_fileIdClusters.clear(); // Can't rely on field_2_numIdClusters int numIdClusters = (bytesRemaining-size) / 8; for (int i = 0; i < numIdClusters; i++) { int drawingGroupId = LittleEndian.getInt( data, pos + size ); int numShapeIdsUsed = LittleEndian.getInt( data, pos + size + 4 ); FileIdCluster fic = new FileIdCluster(drawingGroupId, numShapeIdsUsed); field_5_fileIdClusters.add(fic); maxDgId = Math.max(maxDgId, drawingGroupId); size += 8; } bytesRemaining -= size; if (bytesRemaining != 0) { throw new RecordFormatException("Expecting no remaining data but got " + bytesRemaining + " byte(s)."); } return 8 + size; }
Example 14
Source File: FontFormatting.java From lams with GNU General Public License v2.0 | 4 votes |
private int getInt(int offset) { return LittleEndian.getInt( _rawData, offset); }
Example 15
Source File: HSSFWorkbook.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Adds a picture to the workbook. * * @param pictureData The bytes of the picture * @param format The format of the picture. One of <code>PICTURE_TYPE_*</code> * * @return the index to this picture (1 based). * @see #PICTURE_TYPE_WMF * @see #PICTURE_TYPE_EMF * @see #PICTURE_TYPE_PICT * @see #PICTURE_TYPE_PNG * @see #PICTURE_TYPE_JPEG * @see #PICTURE_TYPE_DIB */ @SuppressWarnings("fallthrough") @Override public int addPicture(byte[] pictureData, int format) { initDrawings(); byte[] uid = DigestUtils.md5(pictureData); EscherBlipRecord blipRecord; int blipSize; short escherTag; switch (format) { case PICTURE_TYPE_WMF: // remove first 22 bytes if file starts with magic bytes D7-CD-C6-9A // see also http://de.wikipedia.org/wiki/Windows_Metafile#Hinweise_zur_WMF-Spezifikation if (LittleEndian.getInt(pictureData) == 0x9AC6CDD7) { byte picDataNoHeader[] = new byte[pictureData.length-22]; System.arraycopy(pictureData, 22, picDataNoHeader, 0, pictureData.length-22); pictureData = picDataNoHeader; } // fall through case PICTURE_TYPE_EMF: EscherMetafileBlip blipRecordMeta = new EscherMetafileBlip(); blipRecord = blipRecordMeta; blipRecordMeta.setUID(uid); blipRecordMeta.setPictureData(pictureData); // taken from libre office export, it won't open, if this is left to 0 blipRecordMeta.setFilter((byte)-2); blipSize = blipRecordMeta.getCompressedSize() + 58; escherTag = 0; break; default: EscherBitmapBlip blipRecordBitmap = new EscherBitmapBlip(); blipRecord = blipRecordBitmap; blipRecordBitmap.setUID( uid ); blipRecordBitmap.setMarker( (byte) 0xFF ); blipRecordBitmap.setPictureData( pictureData ); blipSize = pictureData.length + 25; escherTag = (short) 0xFF; break; } blipRecord.setRecordId((short) (EscherBlipRecord.RECORD_ID_START + format)); switch (format) { case PICTURE_TYPE_EMF: blipRecord.setOptions(HSSFPictureData.MSOBI_EMF); break; case PICTURE_TYPE_WMF: blipRecord.setOptions(HSSFPictureData.MSOBI_WMF); break; case PICTURE_TYPE_PICT: blipRecord.setOptions(HSSFPictureData.MSOBI_PICT); break; case PICTURE_TYPE_PNG: blipRecord.setOptions(HSSFPictureData.MSOBI_PNG); break; case PICTURE_TYPE_JPEG: blipRecord.setOptions(HSSFPictureData.MSOBI_JPEG); break; case PICTURE_TYPE_DIB: blipRecord.setOptions(HSSFPictureData.MSOBI_DIB); break; default: throw new IllegalStateException("Unexpected picture format: " + format); } EscherBSERecord r = new EscherBSERecord(); r.setRecordId( EscherBSERecord.RECORD_ID ); r.setOptions( (short) ( 0x0002 | ( format << 4 ) ) ); r.setBlipTypeMacOS( (byte) format ); r.setBlipTypeWin32( (byte) format ); r.setUid( uid ); r.setTag( escherTag ); r.setSize( blipSize ); r.setRef( 0 ); r.setOffset( 0 ); r.setBlipRecord( blipRecord ); return workbook.addBSERecord( r ); }
Example 16
Source File: CryptoFunctions.java From lams with GNU General Public License v2.0 | 4 votes |
/** * This method generates the xor verifier for word documents < 2007 (method 2). * Its output will be used as password input for the newer word generations which * utilize a real hashing algorithm like sha1. * * @param password the password * @return the hashed password * * @see <a href="http://msdn.microsoft.com/en-us/library/dd905229.aspx">2.3.7.4 Binary Document Password Verifier Derivation Method 2</a> * @see <a href="http://blogs.msdn.com/b/vsod/archive/2010/04/05/how-to-set-the-editing-restrictions-in-word-using-open-xml-sdk-2-0.aspx">How to set the editing restrictions in Word using Open XML SDK 2.0</a> * @see <a href="http://www.aspose.com/blogs/aspose-blogs/vladimir-averkin/archive/2007/08/20/funny-how-the-new-powerful-cryptography-implemented-in-word-2007-turns-it-into-a-perfect-tool-for-document-password-removal.html">Funny: How the new powerful cryptography implemented in Word 2007 turns it into a perfect tool for document password removal.</a> */ public static int createXorVerifier2(String password) { //Array to hold Key Values byte[] generatedKey = new byte[4]; //Maximum length of the password is 15 chars. final int maxPasswordLength = 15; if (!"".equals(password)) { // Truncate the password to 15 characters password = password.substring(0, Math.min(password.length(), maxPasswordLength)); byte[] arrByteChars = toAnsiPassword(password); // Compute the high-order word of the new key: // --> Initialize from the initial code array (see below), depending on the passwords length. int highOrderWord = INITIAL_CODE_ARRAY[arrByteChars.length - 1]; // --> For each character in the password: // --> For every bit in the character, starting with the least significant and progressing to (but excluding) // the most significant, if the bit is set, XOR the keys high-order word with the corresponding word from // the Encryption Matrix for (int i = 0; i < arrByteChars.length; i++) { int tmp = maxPasswordLength - arrByteChars.length + i; for (int intBit = 0; intBit < 7; intBit++) { if ((arrByteChars[i] & (0x0001 << intBit)) != 0) { highOrderWord ^= ENCRYPTION_MATRIX[tmp][intBit]; } } } // Compute the low-order word of the new key: int verifier = createXorVerifier1(password); // The byte order of the result shall be reversed [password "Example": 0x64CEED7E becomes 7EEDCE64], // and that value shall be hashed as defined by the attribute values. LittleEndian.putShort(generatedKey, 0, (short)verifier); LittleEndian.putShort(generatedKey, 2, (short)highOrderWord); } return LittleEndian.getInt(generatedKey); }
Example 17
Source File: PropertySet.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Initializes this {@link PropertySet} instance from a byte * array. The method assumes that it has been checked already that * the byte array indeed represents a property set stream. It does * no more checks on its own. * * @param src Byte array containing the property set stream * @param offset The property set stream starts at this offset * from the beginning of {@code src} * @param length Length of the property set stream. * @throws UnsupportedEncodingException if HPSF does not (yet) support the * property set's character encoding. */ private void init(final byte[] src, final int offset, final int length) throws UnsupportedEncodingException { /* FIXME (3): Ensure that at most "length" bytes are read. */ /* * Read the stream's header fields. */ int o = offset; byteOrder = LittleEndian.getUShort(src, o); o += LittleEndianConsts.SHORT_SIZE; format = LittleEndian.getUShort(src, o); o += LittleEndianConsts.SHORT_SIZE; osVersion = (int) LittleEndian.getUInt(src, o); o += LittleEndianConsts.INT_SIZE; classID = new ClassID(src, o); o += ClassID.LENGTH; final int sectionCount = LittleEndian.getInt(src, o); o += LittleEndianConsts.INT_SIZE; if (sectionCount < 0) { throw new HPSFRuntimeException("Section count " + sectionCount + " is negative."); } /* * Read the sections, which are following the header. They * start with an array of section descriptions. Each one * consists of a format ID telling what the section contains * and an offset telling how many bytes from the start of the * stream the section begins. * * Most property sets have only one section. The Document * Summary Information stream has 2. Everything else is a rare * exception and is no longer fostered by Microsoft. */ /* * Loop over the section descriptor array. Each descriptor * consists of a ClassID and a DWord, and we have to increment * "offset" accordingly. */ for (int i = 0; i < sectionCount; i++) { final Section s = new MutableSection(src, o); o += ClassID.LENGTH + LittleEndianConsts.INT_SIZE; sections.add(s); } }
Example 18
Source File: Thumbnail.java From lams with GNU General Public License v2.0 | 3 votes |
/** * <p>Returns an <code>int</code> representing the Clipboard * Format Tag</p> * * <p>Possible return values are:</p> * <ul> * <li>{@link #CFTAG_WINDOWS CFTAG_WINDOWS}</li> * <li>{@link #CFTAG_MACINTOSH CFTAG_MACINTOSH}</li> * <li>{@link #CFTAG_FMTID CFTAG_FMTID}</li> * <li>{@link #CFTAG_NODATA CFTAG_NODATA}</li> * </ul> * * @return A flag indicating the Clipboard Format Tag */ public long getClipboardFormatTag() { long clipboardFormatTag = LittleEndian.getInt(getThumbnail(), OFFSET_CFTAG); return clipboardFormatTag; }
Example 19
Source File: Thumbnail.java From lams with GNU General Public License v2.0 | 3 votes |
/** * <p>Returns an <code>int</code> representing the Clipboard * Format</p> * * <p>Will throw an exception if the Thumbnail's Clipboard Format * Tag is not {@link Thumbnail#CFTAG_WINDOWS CFTAG_WINDOWS}.</p> * * <p>Possible return values are:</p> * * <ul> * <li>{@link #CF_METAFILEPICT CF_METAFILEPICT}</li> * <li>{@link #CF_DIB CF_DIB}</li> * <li>{@link #CF_ENHMETAFILE CF_ENHMETAFILE}</li> * <li>{@link #CF_BITMAP CF_BITMAP}</li> * </ul> * * @return a flag indicating the Clipboard Format * @throws HPSFException if the Thumbnail isn't CFTAG_WINDOWS */ public long getClipboardFormat() throws HPSFException { if (!(getClipboardFormatTag() == CFTAG_WINDOWS)) throw new HPSFException("Clipboard Format Tag of Thumbnail must " + "be CFTAG_WINDOWS."); return LittleEndian.getInt(getThumbnail(), OFFSET_CF); }
Example 20
Source File: EscherRecord.java From lams with GNU General Public License v2.0 | 2 votes |
/** * 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 ); return LittleEndian.getInt( data, offset + 4 ); }