Example usage for org.apache.poi.poifs.filesystem DocumentInputStream readShort

List of usage examples for org.apache.poi.poifs.filesystem DocumentInputStream readShort

Introduction

In this page you can find the example usage for org.apache.poi.poifs.filesystem DocumentInputStream readShort.

Prototype

@Override
    public short readShort() 

Source Link

Usage

From source file:org.ddt.listener.ole.FileMoniker.java

License:Apache License

/**
 * Helper function that populates the fields of this moniker from the given stream
 *
 * @param inStream the stream to read from
 * @throws IOException// www .  j a va  2s  . co m
 * @  throws
 *                                                                                                                                                                                        BadOleStreamException
 */
private void populate(DocumentInputStream inStream) throws IOException, BadOleStreamException {

    cAnti = inStream.readShort();

    ansiLength = inStream.readInt();
    ansiPath = new byte[ansiLength - 1]; //don't get the last char (\0)
    if (inStream.read(ansiPath) != ansiLength - 1) {
        throw new BadOleStreamException("Couldn't read Path.");
    }
    inStream.skip(1); //skip the string terminating null char

    endServer = inStream.readShort();

    versionNumber = inStream.readShort();
    if (versionNumber != VERSION_NUMBER) {
        throw new BadOleStreamException("wrong version number: " + this.getVersionNumberHexString());
    }

    inStream.skip(20); //skip the two reserved fields. should check that they are both 0.

    unicodePathSize = inStream.readInt();

    //the rest of the fields only exist if unicodePathSize > 0
    if (unicodePathSize <= 0) {
        return;
    }

    unicodePathBytes = inStream.readInt();
    usKeyValue = inStream.readShort();

    //should really make this a char array or a string.
    unicodePath = new byte[unicodePathBytes];
    for (int i = 0; i < (unicodePathBytes); i++) {
        unicodePath[i] = inStream.readByte();
    }
}