/** * get a short value from the beginning of a byte array * * @param data * the byte array * @return the short (16-bit) value */ public static short getShort( byte[] data ) { return getShort( data, 0 ); }
/** * 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 out * of range */ public void readFromBytes(final byte [] data) throws ArrayIndexOutOfBoundsException { _value = LittleEndian.getShort(data, _offset); }
private short getShort(int offset) { return LittleEndian.getShort( _rawData, offset); } private void setShort(int offset, int value) {
/** * Read short array * * @param data * the original byte array * @param offset * Where to start copying from. * @param size * Number of bytes to copy. * @throws IndexOutOfBoundsException * - if read would cause access of data outside array bounds. */ public static short[] getShortArray( byte[] data, int offset, int size ) { short[] result = new short[size / SHORT_SIZE]; for ( int i = 0; i < result.length; i++ ) { result[i] = getShort( data, offset + i * SHORT_SIZE ); } return result; }
/** * 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 ); }
private void fillNextBuffer() throws IOException { if (_innerHasReachedEOF) { return; } int b0 = _is.read(); if (b0 == -1) { _innerHasReachedEOF = true; return; } _data[0] = (byte) b0; _is.readFully(_data, 1, 3); int len = LittleEndian.getShort(_data, 2); _is.readFully(_data, 4, len); _currentPos = 0; _currentSize = len + 4; _recordCounter++; } private void formatBufferIfAtEndOfRec() {
field_1_flag = LittleEndian.getShort( data, pos + size ); size += 2; field_2_col1 = LittleEndian.getShort( data, pos + size ); size += 2; field_3_dx1 = LittleEndian.getShort( data, pos + size ); size += 2; field_4_row1 = LittleEndian.getShort( data, pos + size ); size += 2; if(bytesRemaining >= 18) { field_5_dy1 = LittleEndian.getShort( data, pos + size ); size += 2; field_6_col2 = LittleEndian.getShort( data, pos + size ); size += 2; field_7_dx2 = LittleEndian.getShort( data, pos + size ); size += 2; field_8_row2 = LittleEndian.getShort( data, pos + size ); size += 2; field_9_dy2 = LittleEndian.getShort( data, pos + size ); size += 2; shortRecord = false; } else {
private void formatBufferIfAtEndOfRec() { if (_currentPos != _currentSize) { return; } int dataSize = _currentSize-4; int sid = LittleEndian.getShort(_data, 0); int globalOffset = _overallStreamPos-_currentSize; _listener.processRecord(globalOffset, _recordCounter, sid, dataSize, _data); } @Override
/** * Read the options field from header and return instance part of it. * @param data the byte array to read from * @param offset the offset to start reading from * @return value of instance part of options field */ protected static short readInstance( byte data[], int offset ) { final short options = LittleEndian.getShort( data, offset ); return fInstance.getShortValue( options ); }
public short getSizeOfElements() { return (emptyComplexPart) ? 0 : LittleEndian.getShort( getComplexData(), 4 ); }
@Override public short readShort() { if (shouldSkipEncryptionOnCurrentRecord) { readPlain(buffer, 0, LittleEndianConsts.SHORT_SIZE); return LittleEndian.getShort(buffer); } else { return ccis.readShort(); } }
@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; }
@Override public short readShort() { final int size = LittleEndianConsts.SHORT_SIZE; checkPosition(size); short le = LittleEndian.getShort(buf, pos); long skipped = super.skip(size); assert skipped == size : "Buffer overrun"; return le; }
@Override public short readShort() { checkAvaliable(SHORT_SIZE); byte[] data = new byte[SHORT_SIZE]; readFully(data, 0, SHORT_SIZE); return LittleEndian.getShort(data); }
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"); } }
/** * @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; } }
/** * We have this method because the way in which arrays in escher works * is screwed for seemly arbitrary reasons. While most properties are * fairly consistent and have a predictable array size, escher arrays * have special cases. * * @param data The data array containing the escher array information * @param offset The offset into the array to start reading from. * @return the number of bytes used by this complex property. */ public int setArrayData(byte[] data, int offset) { if (emptyComplexPart){ setComplexData(new byte[0]); } else { short numElements = LittleEndian.getShort(data, offset); // LittleEndian.getShort(data, offset + 2); // numReserved short sizeOfElements = LittleEndian.getShort(data, offset + 4); // the code here seems to depend on complexData already being // sized correctly via the constructor int arraySize = getActualSizeOfElements(sizeOfElements) * numElements; if (arraySize == getComplexData().length) { // The stored data size in the simple block excludes the header size setComplexData(new byte[arraySize + 6]); sizeIncludesHeaderSize = false; } System.arraycopy(data, offset, getComplexData(), 0, getComplexData().length ); } return getComplexData().length; }
/** * @return array of x coordinates */ public int[] getXPoints() { EscherArrayProperty verticesProp = getOptRecord().lookup(EscherProperties.GEOMETRY__VERTICES); if (null == verticesProp){ return new int[]{}; } int []array = new int[verticesProp.getNumberOfElementsInArray()-1]; for (int i=0; i< verticesProp.getNumberOfElementsInArray()-1; i++){ byte[] property = verticesProp.getElement(i); short x = LittleEndian.getShort(property, 0); array[i] = x; } return array; }
/** * @return array of y coordinates */ public int[] getYPoints() { EscherArrayProperty verticesProp = getOptRecord().lookup(EscherProperties.GEOMETRY__VERTICES); if (null == verticesProp){ return new int[]{}; } int []array = new int[verticesProp.getNumberOfElementsInArray()-1]; for (int i=0; i< verticesProp.getNumberOfElementsInArray()-1; i++){ byte[] property = verticesProp.getElement(i); short x = LittleEndian.getShort(property, 2); array[i] = x; } return array; }
@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 = IOUtils.safelyAllocate(bytesRemaining, MAX_RECORD_LENGTH); System.arraycopy( data, pos, _remainingData, 0, bytesRemaining ); return bytesRemaining + 8 + 36 + (field_12_blipRecord == null ? 0 : field_12_blipRecord.getRecordSize()) ; }