Example usage for org.apache.poi.hpsf ClassID ClassID

List of usage examples for org.apache.poi.hpsf ClassID ClassID

Introduction

In this page you can find the example usage for org.apache.poi.hpsf ClassID ClassID.

Prototype

public ClassID(final byte[] src, final int offset) 

Source Link

Document

Creates a ClassID and reads its value from a byte array.

Usage

From source file:com.pnf.plugin.ole.parser.MonikerStream.java

License:Apache License

public MonikerStream(int len, ByteBuffer src, String name) {
    // first read the class id
    byte[] idData = new byte[CLASS_ID_SIZE];
    int arraySize = len - CLASS_ID_SIZE;
    int start = src.position();

    src.get(idData);//from   w  w w  .  j  a  va 2 s  .c om
    clsId = new ClassID(idData, start);

    streamData = new byte[arraySize];
    src.get(streamData);

    entry = new StreamEntry(name, "MonikerStream", "", StreamEntry.toHex(start), String.valueOf(len));
    entry.addChild(new StreamEntry("clsId", "ClassID", clsId.toString(), StreamEntry.toHex(start),
            String.valueOf(CLASS_ID_SIZE)));
    entry.addChild(new StreamEntry("streamData", "byte array", StreamReader.toHex(streamData),
            StreamEntry.toHex(start + CLASS_ID_SIZE), String.valueOf(arraySize)));
}

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

License:Apache License

/**
 * Creates this moniker and then all of the submonikers as well.
 *
 * @param inStream DocumentInputStream opened at the start of this Moniker.
 * @throws IOException//w  w  w.j  a v a  2  s.c  o  m
 * @throws BadOleStreamException
 */
CompositeMoniker(DocumentInputStream inStream) throws IOException, BadOleStreamException {

    monikerCount = inStream.readInt();
    monikerArray = new ArrayList<Moniker>(monikerCount);
    for (int i = 0; i < monikerCount; i++) {
        byte[] classID = new byte[16];
        inStream.read(classID);
        ClassID cid = new ClassID(classID, 0);
        Moniker m = MonikerFactory.getMoniker(cid, inStream);
        if (m != null) {
            monikerArray.add(m);
        }
    }
}

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

License:Apache License

/**
 * Reads a "\1Ole" stream and stores the links found in it.
 * <p/>//  w w w  .j a  va  2  s. c om
 * This method returns (fairly) quietly if the stream fails (it doesn't throw exceptions)
 * There are a number of ways that this can fail, not all of which are bad.
 * For instance, POIFSReaderEvent doesn't contain an OLE stream, this is not
 * a disaster, we just need to return quickly.
 *
 * @param event document to process
 */
public void processPOIFSReaderEvent(POIFSReaderEvent event) {
    log.log(Level.FINEST, "Processing Document: {0}/{1}", new Object[] { event.getPath(), event.getName() });
    DocumentInputStream docInStream = event.getStream();

    if (docInStream.available() < LittleEndian.INT_SIZE)
        return;

    if (docInStream.readInt() != VALID_VERSION) {
        log.log(Level.INFO, "Invalid signature - not an OLE Stream.");
        docInStream.close();
        return;
    }
    try {
        docInStream.skip(LittleEndian.INT_SIZE); //ignore what I think might be LinkUpdateOptions
        //check it's a linked object, not embedded
        if (docInStream.readInt() != 1) {
            log.log(Level.FINER, "Not a link");
            docInStream.close();
            return;
        }

        //check reserved field = 0
        if (docInStream.readInt() != 0x000000) {
            docInStream.close();
            return;
        }

        Moniker m;
        String relPath = null;
        String absPath = null;
        byte[] clsid = new byte[16];
        //source moniker, not really interesting.
        if ((docInStream.readInt()) > 0) {
            docInStream.read(clsid);
            ClassID cid = new ClassID(clsid, 0);
            MonikerFactory.getMoniker(cid, docInStream);
        }
        if ((docInStream.readInt()) > 0) {
            docInStream.read(clsid);
            ClassID cid = new ClassID(clsid, 0);
            m = MonikerFactory.getMoniker(cid, docInStream);
            if (m != null)
                relPath = m.getLink();
        }
        if ((docInStream.readInt()) > 0) {
            docInStream.read(clsid);
            ClassID cid = new ClassID(clsid, 0);
            m = MonikerFactory.getMoniker(cid, docInStream);
            if (m != null)
                absPath = m.getLink();
        }

        Link l = new Link(1);
        l.addRelativePath(cleanURLString(relPath));
        l.addAbsolutePath(absPath);
        this.add(l);
    } catch (IOException ex) {
        log.log(Level.FINE, ex.getLocalizedMessage());
    } catch (BadOleStreamException ex) {
        log.log(Level.INFO, ex.getMessage());
    } finally {
        docInStream.close();
    }
}

From source file:tv.amwa.maj.io.aaf.AAFBuilder.java

License:Apache License

/**
 * @param args/*from w w  w  .j  ava  2 s. com*/
 */
public static void main(String[] args) throws IOException {

    if (args.length != 2)
        System.exit(1);

    final String inputFilename = args[0];
    final String outputFilename = args[1];

    POIFSReader r = new AAFReader();

    LocalAAFEventReader eventReader = new LocalAAFEventReader();
    r.registerListener(eventReader);

    AvidFactory.registerAvidExtensions();

    FileInputStream fis = null;

    long startTime = System.nanoTime();
    try {
        fis = new FileInputStream(inputFilename);
        r.read(new FileInputStream(inputFilename));
        eventReader.resolveEntries();
    } finally {
        if (fis != null)
            try {
                fis.close();
            } catch (Exception e) {
            }
    }
    long endTime = System.nanoTime();

    System.out.println("AAF file read in " + (endTime - startTime) + "ns.");

    ((PrefaceImpl) eventReader.getPreface()).setByteOrder(tv.amwa.maj.enumeration.ByteOrder.Big);
    System.out.println(eventReader.getPreface().getByteOrder());

    POIFSFileSystem outputFileSystem = new POIFSFileSystem();

    DirectoryEntry rootDir = outputFileSystem.getRoot();

    AAFWriterListener aafWriter = makeAAFWriterListener();
    DirectoryEntry metaDictionaryDir = rootDir.createDirectory(META_DICTIONARY_DIRNAME);
    DirectoryEntry prefaceDir = rootDir.createDirectory(PREFACE_DIRNAME);

    generateAAFStructure(prefaceDir, aafWriter, eventReader.getPreface());
    generateMetaDictionary(metaDictionaryDir, aafWriter, eventReader.getPreface());
    rootDir.createDocument(PROPERTIES_STREAMNAME, 70, aafWriter);
    rootDir.createDocument(REFERENCED_PROPERTIES_STREAMNAME, aafWriter.getReferencedPropertiesSize(),
            aafWriter);

    //       rootDir.setStorageClsid(
    //             (outputFileSystem.getBigBlockSize() == 4096) ?
    //                   new AAFClassID(AAFSignatureSSBin4K) :
    //                      new AAFClassID(AAFSignatureSSBinary));

    rootDir.setStorageClsid(new ClassID(rootEntryClassID, 0));

    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(outputFilename);
        outputFileSystem.writeFilesystem(fos);
    } finally {
        if (fos != null)
            try {
                fos.close();
            } catch (Exception e) {
            }
    }

    // AAF puts a signature in bytes 8-23 of the file
    // POIFS cannot write this

    RandomAccessFile fixFile = null;
    FileChannel fixChannel = null;
    try {
        fixFile = new RandomAccessFile(outputFilename, "rw");
        fixChannel = fixFile.getChannel();

        fixChannel.position(8);
        if (outputFileSystem.getBigBlockSize() == 4096)
            fixChannel.write(ByteBuffer.wrap(AAFSignatureSSBin4KBytes));
        else
            fixChannel.write(ByteBuffer.wrap(AAFSignatureSSBinaryBytes));
    } finally {
        if (fixChannel != null)
            fixChannel.close();
    }
}

From source file:tv.amwa.maj.io.aaf.AAFFactory.java

License:Apache License

/**
 * <p>Write an AAF file with the given filename that is constructed from the given {@linkplain Preface preface}.<p>
 * //from  w  w  w.  j  a  v  a2  s  .  c o  m
 * <p>Note that this version of MAJ only supports writing metadata-only files.</p>
 * 
 * @param preface Preface to use to construct an AAF file from.
 * @param outputFilename File path specification for the file to write the preface to.
 * 
 * @throws IOException An error occurred when writing the AAF file.
 * 
 * @see #readPreface(String)
 */
public final static void writePreface(Preface preface, String outputFilename) throws IOException {

    POIFSFileSystem outputFileSystem = new POIFSFileSystem();

    DirectoryEntry rootDir = outputFileSystem.getRoot();

    preface.updateDictionaries();
    //       System.out.println(preface);

    AAFWriterListener aafWriter = AAFBuilder.makeAAFWriterListener();
    DirectoryEntry metaDictionaryDir = rootDir.createDirectory(META_DICTIONARY_DIRNAME);
    DirectoryEntry prefaceDir = rootDir.createDirectory(PREFACE_DIRNAME);

    AAFBuilder.generateAAFStructure(prefaceDir, aafWriter, preface);
    AAFBuilder.generateMetaDictionary(metaDictionaryDir, aafWriter, preface);
    rootDir.createDocument(PROPERTIES_STREAMNAME, 70, aafWriter);
    rootDir.createDocument(REFERENCED_PROPERTIES_STREAMNAME, aafWriter.getReferencedPropertiesSize(),
            aafWriter);

    //       rootDir.setStorageClsid(
    //             (outputFileSystem.getBigBlockSize() == 4096) ?
    //                   new AAFClassID(AAFSignatureSSBin4K) :
    //                      new AAFClassID(AAFSignatureSSBinary));

    rootDir.setStorageClsid(new ClassID(rootEntryClassID, 0));

    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(outputFilename);
        outputFileSystem.writeFilesystem(fos);
    } finally {
        if (fos != null)
            try {
                fos.close();
            } catch (Exception e) {
            }
    }

    // AAF puts a signature in bytes 8-23 of the file
    // POIFS cannot write this

    RandomAccessFile fixFile = null;
    FileChannel fixChannel = null;
    try {
        fixFile = new RandomAccessFile(outputFilename, "rw");
        fixChannel = fixFile.getChannel();

        fixChannel.position(8);
        if (outputFileSystem.getBigBlockSize() == 4096)
            fixChannel.write(ByteBuffer.wrap(AAFSignatureSSBin4KBytes));
        else
            fixChannel.write(ByteBuffer.wrap(AAFSignatureSSBinaryBytes));
    } finally {
        if (fixChannel != null)
            fixChannel.close();
    }
}