private void setInt(int offset, int value) { LittleEndian.putInt( _rawData, offset, value); }
/** * write the value out to an array of bytes at the appropriate * offset * * @param data the array of bytes to which the value is to be * written * * @exception ArrayIndexOutOfBoundsException if the offset is too * large */ public void writeToBytes(final byte [] data) throws ArrayIndexOutOfBoundsException { LittleEndian.putInt(data, _offset, _value); }
/** * 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; } }
/** * put a float value into a byte array * * @param data * the byte array * @param offset * a starting offset into the byte array * @param value * the float (32-bit) value */ public static void putFloat( byte[] data, int offset, float value ) { putInt( data, offset, Float.floatToIntBits( value ) ); }
/** * put a float value into a byte array * * @param value * the float (32-bit) value * @param outputStream * output stream * @throws IOException * if an I/O error occurs */ public static void putFloat( float value, OutputStream outputStream ) throws IOException { putInt( Float.floatToIntBits( value ), outputStream ); }
private byte[] serialize() { // Create the empty array byte[] data = new byte[ bigBlockSize.getBigBlockSize() ]; // Fill in the values int offset = 0; for (int _value : _values) { LittleEndian.putInt(data, offset, _value); offset += LittleEndian.INT_SIZE; } // Done return data; }
/** * Serialize the simple part of the escher record. * * @return the number of bytes serialized. */ @Override public int serializeSimplePart( byte[] data, int offset ) { LittleEndian.putShort(data, offset, getId()); LittleEndian.putInt(data, offset + 2, propertyValue); return 6; }
/** * Serializes the simple part of this property. i.e. the first 6 bytes. */ @Override public int serializeSimplePart(byte[] data, int pos) { LittleEndian.putShort(data, pos, getId()); LittleEndian.putInt(data, pos + 2, _complexData.length); return 6; }
@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; }
@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(); }
@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; }
/** * 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; }
@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() ); LittleEndian.putInt( data, offset + 4, 8 ); LittleEndian.putInt( data, offset + 8, field_1_numShapes ); LittleEndian.putInt( data, offset + 12, field_2_lastMSOSPID ); // System.arraycopy( remainingData, 0, data, offset + 26, remainingData.length ); // int pos = offset + 8 + 18 + remainingData.length; listener.afterRecordSerialize( offset + 16, getRecordId(), getRecordSize(), this ); return getRecordSize(); }
protected static SecretKey generateSecretKey(String password, EncryptionVerifier ver, int keySize) { HashAlgorithm hashAlgo = ver.getHashAlgorithm(); byte pwHash[] = hashPassword(password, hashAlgo, ver.getSalt(), ver.getSpinCount()); byte[] blockKey = new byte[4]; LittleEndian.putInt(blockKey, 0, 0); byte[] finalHash = CryptoFunctions.generateKey(pwHash, hashAlgo, blockKey, hashAlgo.hashSize); byte x1[] = fillAndXor(finalHash, (byte) 0x36); byte x2[] = fillAndXor(finalHash, (byte) 0x5c); byte[] x3 = new byte[x1.length + x2.length]; System.arraycopy(x1, 0, x3, 0, x1.length); System.arraycopy(x2, 0, x3, x1.length, x2.length); byte[] key = Arrays.copyOf(x3, keySize); return new SecretKeySpec(key, ver.getCipherAlgorithm().jceId); }
/** * @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; } }
public void write(OutputStream out) throws IOException { byte[] header = new byte[22]; int pos = 0; LittleEndian.putInt(header, pos, APMHEADER_KEY); pos += LittleEndian.INT_SIZE; //header key LittleEndian.putUShort(header, pos, 0); pos += LittleEndian.SHORT_SIZE; //hmf LittleEndian.putUShort(header, pos, left); pos += LittleEndian.SHORT_SIZE; //left LittleEndian.putUShort(header, pos, top); pos += LittleEndian.SHORT_SIZE; //top LittleEndian.putUShort(header, pos, right); pos += LittleEndian.SHORT_SIZE; //right LittleEndian.putUShort(header, pos, bottom); pos += LittleEndian.SHORT_SIZE; //bottom LittleEndian.putUShort(header, pos, inch); pos += LittleEndian.SHORT_SIZE; //inch LittleEndian.putInt(header, pos, 0); pos += LittleEndian.INT_SIZE; //reserved checksum = getChecksum(); LittleEndian.putUShort(header, pos, checksum); out.write(header); }
@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; }
@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() ); LittleEndian.putInt( data, offset + 4, getRecordSize() - HEADER_SIZE ); int pos = offset + HEADER_SIZE; System.arraycopy( field_1_UID, 0, data, pos, 16 ); data[pos + 16] = field_2_marker; byte pd[] = getPicturedata(); System.arraycopy( pd, 0, data, pos + 17, pd.length ); listener.afterRecordSerialize(offset + getRecordSize(), getRecordId(), getRecordSize(), this); return HEADER_SIZE + 16 + 1 + pd.length; }
@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; }