/** * get an int value from the beginning of a byte array * * @param data * the byte array * @return the int (32-bit) value */ public static int getInt( byte[] data ) { return getInt( data, 0 ); }
private int getInt(int offset) { return LittleEndian.getInt( _rawData, offset); } private void setInt(int offset, int value) {
/** * set the value from its offset into an array of bytes * * @param data the byte array from which the value is to be read * * @exception ArrayIndexOutOfBoundsException if the offset is too * large */ public void readFromBytes(final byte [] data) throws ArrayIndexOutOfBoundsException { _value = LittleEndian.getInt(data, _offset); }
/** * get an 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 getUInt( byte[] data, int offset ) { long retNum = getInt( data, offset ); return retNum & 0x00FFFFFFFFl; }
/** * get a float value from a byte array, reads it in little endian format * then converts the resulting revolting IEEE 754 (curse them) floating * point number to a happy java float * * @param data * the byte array * @param offset * a starting offset into the byte array * @return the double (64-bit) value */ public static float getFloat( byte[] data, int offset ) { return Float.intBitsToFloat( getInt( data, offset ) ); }
/** * Returns the offsets to the first (up to) 109 * BAT sectors. * Any additional BAT sectors are held in the XBAT (DIFAT) * sectors in a chain. * @return BAT offset array */ public int[] getBATArray() { // Read them in int[] result = new int[ Math.min(_bat_count,_max_bats_in_header) ]; int offset = _bat_array_offset; for (int j = 0; j < result.length; j++) { result[ j ] = LittleEndian.getInt(_data, offset); offset += LittleEndianConsts.INT_SIZE; } return result; } /**
@Override public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { int bytesRemaining = readHeader( data, offset ); int pos = offset + 8; int size = 0; field_1_color1 = LittleEndian.getInt( data, pos + size );size+=4; field_2_color2 = LittleEndian.getInt( data, pos + size );size+=4; field_3_color3 = LittleEndian.getInt( data, pos + size );size+=4; field_4_color4 = LittleEndian.getInt( data, pos + size );size+=4; bytesRemaining -= size; if (bytesRemaining != 0) { throw new RecordFormatException("Expecting no remaining data but got " + bytesRemaining + " byte(s)."); } return 8 + size + bytesRemaining; }
@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; }
@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(); }
@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(); }
public EscherColorRef(byte[] source, int start, int len) { assert(len == 4 || len == 6); int offset = start; if (len == 6) { opid = LittleEndian.getUShort(source, offset); offset += 2; } colorRef = LittleEndian.getInt(source, offset); }
public ImageHeaderEMF(final byte data[], final int off) { int offset = off; int type = (int)LittleEndian.getUInt(data, offset); offset += 4; if (type != 1) { LOG.log(POILogger.WARN, "Invalid EMF picture - invalid type"); deviceBounds = new Rectangle(0,0,200,200); return; } // ignore header size offset += 4; int left = LittleEndian.getInt(data, offset); offset += 4; int top = LittleEndian.getInt(data, offset); offset += 4; int right = LittleEndian.getInt(data, offset); offset += 4; int bottom = LittleEndian.getInt(data, offset); offset += 4; deviceBounds = new Rectangle(left, top, right-left, bottom-top); // ignore frame bounds offset += 16; String signature = new String(data, offset, EMF_SIGNATURE.length(), LocaleUtil.CHARSET_1252); if (!EMF_SIGNATURE.equals(signature)) { LOG.log(POILogger.WARN, "Invalid EMF picture - invalid signature"); } }
/** * <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() { return (long) LittleEndian.getInt(getThumbnail(), OFFSET_CFTAG); }
private double rkNumber(byte[] data, int offset) { //see 2.5.122 byte b0 = data[offset]; boolean numDivBy100 = ((b0 & 1) == 1); // else as is boolean floatingPoint = ((b0 >> 1 & 1) == 0); // else signed integer //unset highest 2 bits b0 &= ~1; b0 &= ~(1<<1); rkBuffer[4] = b0; for (int i = 1; i < 4; i++) { rkBuffer[i+4] = data[offset+i]; } double d = 0.0; if (floatingPoint) { d = LittleEndian.getDouble(rkBuffer); } else { int rawInt = LittleEndian.getInt(rkBuffer, 4); d = rawInt >> 2;//divide by 4/shift bits coz 30 bit int, not 32 } d = (numDivBy100) ? d/100 : d; return d; }
@Override public int readInt() { byte buf[] = new byte[LittleEndianConsts.INT_SIZE]; try { checkEOF(read(buf), buf.length); } catch (IOException e) { throw new RuntimeException(e); } return LittleEndian.getInt(buf); }
@Override public int readInt() { if (shouldSkipEncryptionOnCurrentRecord) { readPlain(buffer, 0, LittleEndianConsts.INT_SIZE); return LittleEndian.getInt(buffer); } else { return ccis.readInt(); } }
@Override public int readInt() { checkAvaliable(INT_SIZE); byte[] data = new byte[INT_SIZE]; readFully(data, 0, INT_SIZE); return LittleEndian.getInt(data); }
@Override public int readInt() { final int size = LittleEndianConsts.INT_SIZE; checkPosition(size); int le = LittleEndian.getInt(buf, pos); long skipped = super.skip(size); assert skipped == size : "Buffer overrun"; return le; }
/** * 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 ); }
/** * 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; }