Example usage for org.apache.poi.util LittleEndian getUByte

List of usage examples for org.apache.poi.util LittleEndian getUByte

Introduction

In this page you can find the example usage for org.apache.poi.util LittleEndian getUByte.

Prototype

public static short getUByte(byte[] data, int offset) 

Source Link

Document

get the unsigned value of a byte.

Usage

From source file:org.ddt.listener.dsi.HeadingPairProperty.java

License:Apache License

/**
 * the constructor./*from   w w  w  . jav  a2  s . c o m*/
 *
 *
 * @param data           the data to read from.
 * @param dataOffset     the offset into the
 * <code>data</code> byte array.
 * @param docPartsOffset the offset of the corresponding docparts.
 * @throws IllegalVariantTypeException  if the data is malformed.
 * @throws UnsupportedEncodingException
 */
HeadingPairProperty(byte[] data, int dataOffset, int docPartsOffset)
        throws IllegalVariantTypeException, UnsupportedEncodingException {
    int off = dataOffset;
    name = new StringProperty(data, off);
    off += name.getSize();
    long type = LittleEndian.getUInt(data, off);
    if (type != Variant.VT_I4) {
        log.log(Level.WARNING, "Not a proper VT_I4 type.");
        throw new IllegalVariantTypeException(type, name);
    }
    off += LittleEndian.INT_SIZE;
    //this is a horrible workaround, around the bug in HPSF, that returns
    //cutoff byte arrays from Section.getProperty() (HPFS Bug #52337)
    //It hopes that there aren't too many parts per heading (i.e. worst
    //case it can be store in one byte...)
    int left = data.length - off;
    if (left >= LittleEndian.INT_SIZE) {
        partsCount = (int) LittleEndian.getUInt(data, off);
        off += LittleEndian.INT_SIZE;
    } else if (left >= LittleEndian.SHORT_SIZE) {
        partsCount = LittleEndian.getShort(data, off);
        off += left;
    } else if (left >= LittleEndian.BYTE_SIZE) {
        partsCount = LittleEndian.getUByte(data, off);
        off += left;
    } else {
        partsCount = 1; //default... maybe not a good idea.
    }
    size = off - dataOffset;

    this.docPartsOffset = docPartsOffset;
}

From source file:org.ddt.listener.records.DConRefRecord.java

License:Apache License

/**
 * Read constructor.//from  w w  w. ja  v a2s .  c  o  m
 *
 * @param data byte array containing a DConRef Record, including the header.
 */
public DConRefRecord(byte[] data) {
    int offset = 0;
    if (!(LittleEndian.getShort(data, offset) == DConRefRecord.sid))
        throw new RecordFormatException("incompatible sid.");
    offset += LittleEndian.SHORT_SIZE;

    //length = LittleEndian.getShort(data, offset);
    offset += LittleEndian.SHORT_SIZE;

    firstRow = LittleEndian.getUShort(data, offset);
    offset += LittleEndian.SHORT_SIZE;
    lastRow = LittleEndian.getUShort(data, offset);
    offset += LittleEndian.SHORT_SIZE;
    firstCol = LittleEndian.getUByte(data, offset);
    offset += LittleEndian.BYTE_SIZE;
    lastCol = LittleEndian.getUByte(data, offset);
    offset += LittleEndian.BYTE_SIZE;
    charCount = LittleEndian.getUShort(data, offset);
    offset += LittleEndian.SHORT_SIZE;
    if (charCount < 2)
        throw new org.apache.poi.hssf.record.RecordFormatException("Character count must be >= 2");

    charType = LittleEndian.getUByte(data, offset);
    offset += LittleEndian.BYTE_SIZE; //7 bits reserved + 1 bit type

    /*
     * bytelength is the length of the string in bytes, which depends on whether the string is
     * made of single- or double-byte chars. This is given by charType, which equals 0 if
     * single-byte, 1 if double-byte.
     */
    int byteLength = charCount * ((charType & 1) + 1);

    path = LittleEndian.getByteArray(data, offset, byteLength);
    offset += byteLength;

    /*
     * If it's a self reference, the last one or two bytes (depending on char type) are the
     * unused field. Not sure If i need to bother with this...
     */
    if (path[0] == 0x02)
        _unused = LittleEndian.getByteArray(data, offset, (charType + 1));

}