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

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

Introduction

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

Prototype

public static void putInt(byte[] data, int offset, int value) 

Source Link

Document

put an int value into a byte array

Usage

From source file:org.ddt.ByteArrayUtils.java

License:Apache License

public static byte[] addInt(byte[] dest, int i) {
    byte[] result = Arrays.copyOf(dest, dest.length + 4);
    LittleEndian.putInt(result, dest.length, i);
    return result;
}

From source file:org.textmining.extraction.word.model.CHPFormattedDiskPage.java

License:Open Source License

public byte[] toByteArray(int fcMin) {
    byte[] buf = new byte[512];
    int size = _chpxList.size();
    int grpprlOffset = 511;
    int offsetOffset = 0;
    int fcOffset = 0;

    // total size is currently the size of one FC
    int totalSize = FC_SIZE + 2;

    int index = _currentIndex;
    for (; index < size; index++) {
        int grpprlLength = ((CHPX) _chpxList.get(index)).getGrpprl().length;

        // check to see if we have enough room for an FC, the grpprl offset,
        // the grpprl size byte and the grpprl.
        totalSize += (FC_SIZE + 2 + grpprlLength);
        // if size is uneven we will have to add one so the first grpprl falls
        // on a word boundary
        if (totalSize > 511 + (index % 2)) {
            totalSize -= (FC_SIZE + 2 + grpprlLength);
            break;
        }// ww w .j a v  a  2  s .c  o  m

        // grpprls must fall on word boundaries
        if ((1 + grpprlLength) % 2 > 0) {
            totalSize += 1;
        }
    }

    _currentIndex = index;

    // index should equal number of CHPXs that will be in this fkp now.
    buf[511] = (byte) index;

    offsetOffset = (FC_SIZE * index) + FC_SIZE;
    //grpprlOffset =  offsetOffset + index + (grpprlOffset % 2);

    CHPX chpx = null;
    for (int x = 0; x < index; x++) {
        chpx = (CHPX) _chpxList.get(x);
        byte[] grpprl = chpx.getGrpprl();

        LittleEndian.putInt(buf, fcOffset, chpx.getStart() + fcMin);
        grpprlOffset -= (1 + grpprl.length);
        grpprlOffset -= (grpprlOffset % 2);
        buf[offsetOffset] = (byte) (grpprlOffset / 2);
        buf[grpprlOffset] = (byte) grpprl.length;
        System.arraycopy(grpprl, 0, buf, grpprlOffset + 1, grpprl.length);

        offsetOffset += 1;
        fcOffset += FC_SIZE;
    }
    // put the last chpx's end in
    LittleEndian.putInt(buf, fcOffset, chpx.getEnd() + fcMin);
    return buf;
}

From source file:org.textmining.extraction.word.model.PieceDescriptor.java

License:Open Source License

protected byte[] toByteArray() {
    // set up the fc
    int tempFc = fc;
    if (!unicode) {
        tempFc *= 2;/*from   w w w  .ja  v a  2s.  c o m*/
        tempFc |= (0x40000000);
    }

    int offset = 0;
    byte[] buf = new byte[8];
    LittleEndian.putShort(buf, offset, descriptor);
    offset += LittleEndian.SHORT_SIZE;
    LittleEndian.putInt(buf, offset, tempFc);
    offset += LittleEndian.INT_SIZE;
    LittleEndian.putShort(buf, offset, prm);

    return buf;

}

From source file:org.textmining.extraction.word.model.PlexOfCps.java

License:Open Source License

public byte[] toByteArray() {
    int size = _props.size();
    int cpBufSize = ((size + 1) * LittleEndian.INT_SIZE);
    int structBufSize = +(_sizeOfStruct * size);
    int bufSize = cpBufSize + structBufSize;

    byte[] buf = new byte[bufSize];

    GenericPropertyNode node = null;//from  w  w  w . j  a  v a 2 s . c  om
    for (int x = 0; x < size; x++) {
        node = (GenericPropertyNode) _props.get(x);

        // put the starting offset of the property into the plcf.
        LittleEndian.putInt(buf, (LittleEndian.INT_SIZE * x), node.getStart());

        // put the struct into the plcf
        System.arraycopy(node.getBytes(), 0, buf, cpBufSize + (x * _sizeOfStruct), _sizeOfStruct);
    }
    // put the ending offset of the last property into the plcf.
    LittleEndian.putInt(buf, LittleEndian.INT_SIZE * size, node.getEnd());

    return buf;

}