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

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

Introduction

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

Prototype

public static int getInt(byte[] data) 

Source Link

Document

get an int value from the beginning of a byte array

Usage

From source file:Coop.argo.hwp.v5.HwpTextExtractorV5.java

License:Apache License

private static Key readKey(InputStream input) throws IOException {
    byte[] data = new byte[260];

    input.read(data, 0, 4); // TAG,
    // HWPTAG_DISTRIBUTE_DOC_DATA ?
    // long recordHeader = LittleEndian.getUInt(data);
    // log.debug("TAG:   {}", recordHeader & 0x3FF);
    // log.debug("LEVEL: {}", (recordHeader >> 10) & 0x3FF);
    // log.debug("SIZE:  {}", (recordHeader >> 20) & 0xFFF);

    // https://groups.google.com/forum/#!msg/hwp-foss/d2KL2ypR89Q/lCTkebPcIYYJ

    input.read(data, 0, 256);/* ww w. j  a  v  a  2 s.c  o m*/

    SRand srand = new SRand(LittleEndian.getInt(data));
    byte xor = 0;
    for (int i = 0, n = 0; i < 256; i++, n--) {
        if (n == 0) {
            xor = (byte) (srand.rand() & 0xFF);
            n = (int) ((srand.rand() & 0xF) + 1);
        }
        if (i >= 4) {
            data[i] = (byte) ((data[i]) ^ (xor));
        }
    }

    int offset = 4 + (data[0] & 0xF);
    byte[] key = Arrays.copyOfRange(data, offset, offset + 16);

    SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
    return secretKey;
}

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

License:Open Source License

/**
 * Constructor used to read a binTable in from a Word document.
 * @param documentStream/*  w w w .j a  va2s.  c om*/
 * @param tableStream
 * @param offset
 * @param size
 * @param fcMin
 * @param fc2Cp TODO
 * @param textPieces TODO
 */
public CHPBinTable(byte[] documentStream, byte[] tableStream, int offset, int size, int fcMin,
        NodeHelper fc2Cp) {
    PlexOfCps binTable = new PlexOfCps(tableStream, offset, size, 4);

    int length = binTable.length();
    for (int x = 0; x < length; x++) {
        GenericPropertyNode node = binTable.getProperty(x);

        int pageNum = LittleEndian.getInt(node.getBytes());
        int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE * pageNum;

        CHPFormattedDiskPage cfkp = new CHPFormattedDiskPage(documentStream, pageOffset, fcMin, fc2Cp);

        int fkpSize = cfkp.size();

        for (int y = 0; y < fkpSize; y++) {
            _textRuns.add(cfkp.getCHPX(y));
        }
    }
    fc2Cp.sortNodes(_textRuns, false);
}