List of usage examples for org.apache.poi.poifs.filesystem DocumentInputStream markSupported
@Override public boolean markSupported()
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 a v a 2s. 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); } }
From source file:poi.poifs.poibrowser.TreeReaderListener.java
License:Apache License
/** * <p>A document in the POI filesystem has been opened for * reading. This method retrieves properties of the document and * adds them to a tree model.</p>/*from w w w.j a va 2 s . c o m*/ */ public void processPOIFSReaderEvent(final POIFSReaderEvent event) { DocumentDescriptor d; final DocumentInputStream is = event.getStream(); if (!is.markSupported()) throw new UnsupportedOperationException(is.getClass().getName() + " does not support mark()."); /* Try do handle this document as a property set. We receive * an exception if is no property set and handle it as a * document of some other format. We are not concerned about * that document's details. */ try { d = new PropertySetDescriptor(event.getName(), event.getPath(), is, nrOfBytes); } catch (HPSFException ex) { d = new DocumentDescriptor(event.getName(), event.getPath(), is, nrOfBytes); } catch (Throwable t) { System.err.println("Unexpected exception while processing " + event.getName() + " in " + event.getPath().toString()); t.printStackTrace(System.err); throw new RuntimeException(t.getMessage()); } is.close(); final MutableTreeNode parentNode = getNode(d.path, filename, rootNode); final MutableTreeNode nameNode = new DefaultMutableTreeNode(d.name); parentNode.insert(nameNode, 0); final MutableTreeNode dNode = new DefaultMutableTreeNode(d); nameNode.insert(dNode, 0); }