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

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

Introduction

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

Prototype

@Override
public void reset() 

Source Link

Document

Repositions this stream to the position at the time the mark() method was last called on this input stream.

Usage

From source file:poi.poifs.poibrowser.DocumentDescriptor.java

License:Apache License

/**
 * <p>Creates a {@link DocumentDescriptor}.</p>
 *
 * @param name The stream's name./*from  w w w . j  av a 2 s.  co  m*/
 *
 * @param path The stream's path in the POI filesystem hierarchy.
 *
 * @param stream The stream.
 *
 * @param nrOfBytes The maximum number of bytes to display in a
 * dump starting at the beginning of the stream.
 */
public DocumentDescriptor(final String name, final POIFSDocumentPath path, final DocumentInputStream stream,
        final int nrOfBytes) {
    this.name = name;
    this.path = path;
    this.stream = stream;
    try {
        size = stream.available();
        if (stream.markSupported()) {
            stream.mark(nrOfBytes);
            final byte[] b = new byte[nrOfBytes];
            final int read = stream.read(b, 0, Math.min(size, b.length));
            bytes = new byte[read];
            System.arraycopy(b, 0, bytes, 0, read);
            stream.reset();
        }
    } catch (IOException ex) {
        System.out.println(ex);
    }
}