Java Code Examples for org.apache.poi.util.LittleEndian#putInt()
The following examples show how to use
org.apache.poi.util.LittleEndian#putInt() .
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: EscherTextboxRecord.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public int serialize( int offset, byte[] data, EscherSerializationListener listener ) { listener.beforeRecordSerialize( offset, getRecordId(), this ); LittleEndian.putShort(data, offset, getOptions()); LittleEndian.putShort(data, offset+2, getRecordId()); int remainingBytes = thedata.length; LittleEndian.putInt(data, offset+4, remainingBytes); System.arraycopy(thedata, 0, data, offset+8, thedata.length); int pos = offset+8+thedata.length; listener.afterRecordSerialize( pos, getRecordId(), pos - offset, this ); int size = pos - offset; if (size != getRecordSize()) { throw new RecordFormatException(size + " bytes written but getRecordSize() reports " + getRecordSize()); } return size; }
Example 2
Source File: EscherSpgrRecord.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public int serialize( int offset, byte[] data, EscherSerializationListener listener ) { listener.beforeRecordSerialize( offset, getRecordId(), this ); LittleEndian.putShort( data, offset, getOptions() ); LittleEndian.putShort( data, offset + 2, getRecordId() ); int remainingBytes = 16; LittleEndian.putInt( data, offset + 4, remainingBytes ); LittleEndian.putInt( data, offset + 8, field_1_rectX1 ); LittleEndian.putInt( data, offset + 12, field_2_rectY1 ); LittleEndian.putInt( data, offset + 16, field_3_rectX2 ); LittleEndian.putInt( data, offset + 20, field_4_rectY2 ); // System.arraycopy( remainingData, 0, data, offset + 26, remainingData.length ); // int pos = offset + 8 + 18 + remainingData.length; listener.afterRecordSerialize( offset + getRecordSize(), getRecordId(), offset + getRecordSize(), this ); return 8 + 16; }
Example 3
Source File: EscherSpRecord.java From lams with GNU General Public License v2.0 | 6 votes |
/** * This method serializes this escher record into a byte array. * * @param offset The offset into <code>data</code> to start writing the record data to. * @param data The byte array to serialize to. * @param listener A listener to retrieve start and end callbacks. Use a <code>NullEscherSerailizationListener</code> to ignore these events. * @return The number of bytes written. * * @see NullEscherSerializationListener */ @Override public int serialize( int offset, byte[] data, EscherSerializationListener listener ) { listener.beforeRecordSerialize( offset, getRecordId(), this ); LittleEndian.putShort( data, offset, getOptions() ); LittleEndian.putShort( data, offset + 2, getRecordId() ); int remainingBytes = 8; LittleEndian.putInt( data, offset + 4, remainingBytes ); LittleEndian.putInt( data, offset + 8, field_1_shapeId ); LittleEndian.putInt( data, offset + 12, field_2_flags ); // System.arraycopy( remainingData, 0, data, offset + 26, remainingData.length ); // int pos = offset + 8 + 18 + remainingData.length; listener.afterRecordSerialize( offset + getRecordSize(), getRecordId(), getRecordSize(), this ); return 8 + 8; }
Example 4
Source File: EscherClientDataRecord.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public int serialize(int offset, byte[] data, EscherSerializationListener listener) { listener.beforeRecordSerialize( offset, getRecordId(), this ); if (remainingData == null) { remainingData = new byte[0]; } LittleEndian.putShort( data, offset, getOptions() ); LittleEndian.putShort( data, offset + 2, getRecordId() ); LittleEndian.putInt( data, offset + 4, remainingData.length ); System.arraycopy( remainingData, 0, data, offset + 8, remainingData.length ); int pos = offset + 8 + remainingData.length; listener.afterRecordSerialize( pos, getRecordId(), pos - offset, this ); return pos - offset; }
Example 5
Source File: EscherSplitMenuColorsRecord.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public int serialize( int offset, byte[] data, EscherSerializationListener listener ) { // int field_2_numIdClusters = field_5_fileIdClusters.length + 1; listener.beforeRecordSerialize( offset, getRecordId(), this ); int pos = offset; LittleEndian.putShort( data, pos, getOptions() ); pos += 2; LittleEndian.putShort( data, pos, getRecordId() ); pos += 2; int remainingBytes = getRecordSize() - 8; LittleEndian.putInt( data, pos, remainingBytes ); pos += 4; LittleEndian.putInt( data, pos, field_1_color1 ); pos += 4; LittleEndian.putInt( data, pos, field_2_color2 ); pos += 4; LittleEndian.putInt( data, pos, field_3_color3 ); pos += 4; LittleEndian.putInt( data, pos, field_4_color4 ); pos += 4; listener.afterRecordSerialize( pos, getRecordId(), pos - offset, this ); return getRecordSize(); }
Example 6
Source File: EscherDggRecord.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public int serialize(int offset, byte[] data, EscherSerializationListener listener) { listener.beforeRecordSerialize( offset, getRecordId(), this ); int pos = offset; LittleEndian.putShort( data, pos, getOptions() ); pos += 2; LittleEndian.putShort( data, pos, getRecordId() ); pos += 2; int remainingBytes = getRecordSize() - 8; LittleEndian.putInt( data, pos, remainingBytes ); pos += 4; LittleEndian.putInt( data, pos, field_1_shapeIdMax ); pos += 4; LittleEndian.putInt( data, pos, getNumIdClusters() ); pos += 4; LittleEndian.putInt( data, pos, field_3_numShapesSaved ); pos += 4; LittleEndian.putInt( data, pos, field_4_drawingsSaved ); pos += 4; for (FileIdCluster fic : field_5_fileIdClusters) { LittleEndian.putInt( data, pos, fic.getDrawingGroupId() ); pos += 4; LittleEndian.putInt( data, pos, fic.getNumShapeIdsUsed() ); pos += 4; } listener.afterRecordSerialize( pos, getRecordId(), getRecordSize(), this ); return getRecordSize(); }
Example 7
Source File: EscherPictBlip.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public int serialize(int offset, byte[] data, EscherSerializationListener listener) { listener.beforeRecordSerialize(offset, getRecordId(), this); int pos = offset; LittleEndian.putShort( data, pos, getOptions() ); pos += 2; LittleEndian.putShort( data, pos, getRecordId() ); pos += 2; LittleEndian.putInt( data, 0, getRecordSize() - HEADER_SIZE ); pos += 4; System.arraycopy( field_1_UID, 0, data, pos, 16 ); pos += 16; LittleEndian.putInt( data, pos, field_2_cb ); pos += 4; LittleEndian.putInt( data, pos, field_3_rcBounds_x1 ); pos += 4; LittleEndian.putInt( data, pos, field_3_rcBounds_y1 ); pos += 4; LittleEndian.putInt( data, pos, field_3_rcBounds_x2 ); pos += 4; LittleEndian.putInt( data, pos, field_3_rcBounds_y2 ); pos += 4; LittleEndian.putInt( data, pos, field_4_ptSize_w ); pos += 4; LittleEndian.putInt( data, pos, field_4_ptSize_h ); pos += 4; LittleEndian.putInt( data, pos, field_5_cbSave ); pos += 4; data[pos] = field_6_fCompression; pos++; data[pos] = field_7_fFilter; pos++; System.arraycopy( raw_pictureData, 0, data, pos, raw_pictureData.length ); listener.afterRecordSerialize(offset + getRecordSize(), getRecordId(), getRecordSize(), this); return HEADER_SIZE + 16 + 1 + raw_pictureData.length; }
Example 8
Source File: EscherArrayProperty.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Serializes the simple part of this property. ie the first 6 bytes. * * Needs special code to handle the case when the size doesn't * include the size of the header block */ @Override public int serializeSimplePart(byte[] data, int pos) { LittleEndian.putShort(data, pos, getId()); int recordSize = getComplexData().length; if(!sizeIncludesHeaderSize) { recordSize -= 6; } LittleEndian.putInt(data, pos + 2, recordSize); return 6; }
Example 9
Source File: CryptoFunctions.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Generalized method for read and write protection hash generation. * The difference is, read protection uses the order iterator then hash in the hash loop, whereas write protection * uses first the last hash value and then the current iterator value * * @param password * @param hashAlgorithm * @param salt * @param spinCount * @param iteratorFirst if true, the iterator is hashed before the n-1 hash value, * if false the n-1 hash value is applied first * @return the hashed password */ public static byte[] hashPassword(String password, HashAlgorithm hashAlgorithm, byte salt[], int spinCount, boolean iteratorFirst) { // If no password was given, use the default if (password == null) { password = Decryptor.DEFAULT_PASSWORD; } MessageDigest hashAlg = getMessageDigest(hashAlgorithm); hashAlg.update(salt); byte[] hash = hashAlg.digest(StringUtil.getToUnicodeLE(password)); byte[] iterator = new byte[LittleEndianConsts.INT_SIZE]; byte[] first = (iteratorFirst ? iterator : hash); byte[] second = (iteratorFirst ? hash : iterator); try { for (int i = 0; i < spinCount; i++) { LittleEndian.putInt(iterator, 0, i); hashAlg.reset(); hashAlg.update(first); hashAlg.update(second); hashAlg.digest(hash, 0, hash.length); // don't create hash buffer everytime new } } catch (DigestException e) { throw new EncryptedDocumentException("error in password hashing"); } return hash; }
Example 10
Source File: HeaderBlock.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Sets the offsets of the first (up to) 109 * BAT sectors. */ public void setBATArray(int[] bat_array) { int count = Math.min(bat_array.length, _max_bats_in_header); int blank = _max_bats_in_header - count; int offset = _bat_array_offset; for(int i=0; i<count; i++) { LittleEndian.putInt(_data, offset, bat_array[i]); offset += LittleEndianConsts.INT_SIZE; } for(int i=0; i<blank; i++) { LittleEndian.putInt(_data, offset, POIFSConstants.UNUSED_BLOCK); offset += LittleEndianConsts.INT_SIZE; } }
Example 11
Source File: BATBlock.java From lams with GNU General Public License v2.0 | 5 votes |
private byte[] serialize() { // Create the empty array byte[] data = new byte[ bigBlockSize.getBigBlockSize() ]; // Fill in the values int offset = 0; for(int i=0; i<_values.length; i++) { LittleEndian.putInt(data, offset, _values[i]); offset += LittleEndian.INT_SIZE; } // Done return data; }
Example 12
Source File: HSSFShape.java From lams with GNU General Public License v2.0 | 5 votes |
/** * @return the rotation, in degrees, that is applied to a shape. */ public int getRotationDegree(){ ByteArrayOutputStream bos = new ByteArrayOutputStream(); EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.TRANSFORM__ROTATION); if (null == property){ return 0; } try { LittleEndian.putInt(property.getPropertyValue(), bos); return LittleEndian.getShort(bos.toByteArray(), 2); } catch (IOException e) { LOG.log(POILogger.ERROR, "can't determine rotation degree", e); return 0; } }
Example 13
Source File: EscherBSERecord.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int serialize(int offset, byte[] data, EscherSerializationListener listener) { listener.beforeRecordSerialize( offset, getRecordId(), this ); if (_remainingData == null) { _remainingData = new byte[0]; } LittleEndian.putShort( data, offset, getOptions() ); LittleEndian.putShort( data, offset + 2, getRecordId() ); int blipSize = field_12_blipRecord == null ? 0 : field_12_blipRecord.getRecordSize(); int remainingBytes = _remainingData.length + 36 + blipSize; LittleEndian.putInt( data, offset + 4, remainingBytes ); data[offset + 8] = field_1_blipTypeWin32; data[offset + 9] = field_2_blipTypeMacOS; System.arraycopy(field_3_uid, 0, data, offset + 10, 16); LittleEndian.putShort( data, offset + 26, field_4_tag ); LittleEndian.putInt( data, offset + 28, field_5_size ); LittleEndian.putInt( data, offset + 32, field_6_ref ); LittleEndian.putInt( data, offset + 36, field_7_offset ); data[offset + 40] = field_8_usage; data[offset + 41] = field_9_name; data[offset + 42] = field_10_unused2; data[offset + 43] = field_11_unused3; int bytesWritten = 0; if (field_12_blipRecord != null) { bytesWritten = field_12_blipRecord.serialize( offset + 44, data, new NullEscherSerializationListener() ); } System.arraycopy( _remainingData, 0, data, offset + 44 + bytesWritten, _remainingData.length ); int pos = offset + 8 + 36 + _remainingData.length + bytesWritten; listener.afterRecordSerialize(pos, getRecordId(), pos - offset, this); return pos - offset; }
Example 14
Source File: EscherClientAnchorRecord.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int serialize( int offset, byte[] data, EscherSerializationListener listener ) { listener.beforeRecordSerialize( offset, getRecordId(), this ); if (remainingData == null) { remainingData = new byte[0]; } LittleEndian.putShort( data, offset, getOptions() ); LittleEndian.putShort( data, offset + 2, getRecordId() ); int remainingBytes = remainingData.length + (shortRecord ? 8 : 18); LittleEndian.putInt( data, offset + 4, remainingBytes ); LittleEndian.putShort( data, offset + 8, field_1_flag ); LittleEndian.putShort( data, offset + 10, field_2_col1 ); LittleEndian.putShort( data, offset + 12, field_3_dx1 ); LittleEndian.putShort( data, offset + 14, field_4_row1 ); if(!shortRecord) { LittleEndian.putShort( data, offset + 16, field_5_dy1 ); LittleEndian.putShort( data, offset + 18, field_6_col2 ); LittleEndian.putShort( data, offset + 20, field_7_dx2 ); LittleEndian.putShort( data, offset + 22, field_8_row2 ); LittleEndian.putShort( data, offset + 24, field_9_dy2 ); } System.arraycopy( remainingData, 0, data, offset + (shortRecord ? 16 : 26), remainingData.length ); int pos = offset + 8 + (shortRecord ? 8 : 18) + remainingData.length; listener.afterRecordSerialize( pos, getRecordId(), pos - offset, this ); return pos - offset; }
Example 15
Source File: EscherChildAnchorRecord.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int serialize(int offset, byte[] data, EscherSerializationListener listener) { listener.beforeRecordSerialize( offset, getRecordId(), this ); int pos = offset; LittleEndian.putShort( data, pos, getOptions() ); pos += 2; LittleEndian.putShort( data, pos, getRecordId() ); pos += 2; LittleEndian.putInt( data, pos, getRecordSize()-8 ); pos += 4; LittleEndian.putInt( data, pos, field_1_dx1 ); pos += 4; LittleEndian.putInt( data, pos, field_2_dy1 ); pos += 4; LittleEndian.putInt( data, pos, field_3_dx2 ); pos += 4; LittleEndian.putInt( data, pos, field_4_dy2 ); pos += 4; listener.afterRecordSerialize( pos, getRecordId(), pos - offset, this ); return pos - offset; }
Example 16
Source File: FontFormatting.java From lams with GNU General Public License v2.0 | 4 votes |
private void setInt(int offset, int value) { LittleEndian.putInt( _rawData, offset, value); }
Example 17
Source File: BorderFormatting.java From lams with GNU General Public License v2.0 | 4 votes |
public int serialize(int offset, byte [] data) { LittleEndian.putInt(data, offset+0, field_13_border_styles1); LittleEndian.putInt(data, offset+4, field_14_border_styles2); return 8; }
Example 18
Source File: Section.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Writes this section into an output stream.<p> * * Internally this is done by writing into three byte array output * streams: one for the properties, one for the property list and one for * the section as such. The two former are appended to the latter when they * have received all their data. * * @param out The stream to write into. * * @return The number of bytes written, i.e. the section's size. * @exception IOException if an I/O error occurs * @exception WritingNotSupportedException if HPSF does not yet support * writing a property's variant type. */ public int write(final OutputStream out) throws WritingNotSupportedException, IOException { /* Check whether we have already generated the bytes making out the * section. */ if (sectionBytes.size() > 0) { sectionBytes.writeTo(out); return sectionBytes.size(); } /* Writing the section's dictionary it tricky. If there is a dictionary * (property 0) the codepage property (property 1) must be set, too. */ int codepage = getCodepage(); if (codepage == -1) { String msg = "The codepage property is not set although a dictionary is present. "+ "Defaulting to ISO-8859-1."; LOG.log(POILogger.WARN, msg); codepage = Property.DEFAULT_CODEPAGE; } /* The properties are written to this stream. */ final ByteArrayOutputStream propertyStream = new ByteArrayOutputStream(); /* The property list is established here. After each property that has * been written to "propertyStream", a property list entry is written to * "propertyListStream". */ final ByteArrayOutputStream propertyListStream = new ByteArrayOutputStream(); /* Maintain the current position in the list. */ int position = 0; /* Increase the position variable by the size of the property list so * that it points behind the property list and to the beginning of the * properties themselves. */ position += 2 * LittleEndianConsts.INT_SIZE + getPropertyCount() * 2 * LittleEndianConsts.INT_SIZE; /* Write the properties and the property list into their respective * streams: */ for (Property p : properties.values()) { final long id = p.getID(); /* Write the property list entry. */ LittleEndian.putUInt(id, propertyListStream); LittleEndian.putUInt(position, propertyListStream); /* If the property ID is not equal 0 we write the property and all * is fine. However, if it equals 0 we have to write the section's * dictionary which has an implicit type only and an explicit * value. */ if (id != 0) { /* Write the property and update the position to the next * property. */ position += p.write(propertyStream, codepage); } else { if (codepage == -1) { throw new IllegalPropertySetDataException("Codepage (property 1) is undefined."); } position += writeDictionary(propertyStream, codepage); } } /* Write the section: */ int streamLength = LittleEndianConsts.INT_SIZE * 2 + propertyListStream.size() + propertyStream.size(); /* Write the section's length: */ LittleEndian.putInt(streamLength, out); /* Write the section's number of properties: */ LittleEndian.putInt(getPropertyCount(), out); /* Write the property list: */ propertyListStream.writeTo(out); /* Write the properties: */ propertyStream.writeTo(out); return streamLength; }
Example 19
Source File: Filetime.java From lams with GNU General Public License v2.0 | 4 votes |
int write( OutputStream out ) throws IOException { LittleEndian.putInt( _dwLowDateTime, out ); LittleEndian.putInt( _dwHighDateTime, out ); return SIZE; }
Example 20
Source File: Filetime.java From lams with GNU General Public License v2.0 | 4 votes |
byte[] toByteArray() { byte[] result = new byte[SIZE]; LittleEndian.putInt( result, 0 * LittleEndianConsts.INT_SIZE, _dwLowDateTime ); LittleEndian.putInt( result, 1 * LittleEndianConsts.INT_SIZE, _dwHighDateTime ); return result; }