List of usage examples for org.apache.poi.poifs.filesystem DocumentInputStream skip
@Override
public long skip(long n) throws IOException
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//from ww w . j a va 2s .c o 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(); } }
From source file:org.ddt.listener.ole.OleStreamListener.java
License:Apache License
/** * Reads a "\1Ole" stream and stores the links found in it. * <p/>// ww w .j av a2 s . c o m * 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:org.ddt.listener.ole.URLMoniker.java
License:Apache License
/** * Constructor./* w w w.jav a2 s .co m*/ * <p/> * @param is an opened DocumentInputStream, positioned at the beginning of * the moniker structure. * @throws IOException if something goes wrong with the DocumentInputStream. */ URLMoniker(DocumentInputStream is) throws IOException { length = is.readInt(); byte[] b = new byte[length]; is.read(b); String tempUrl = new String(b); //check what 'length' means. int termPos = tempUrl.indexOf("\0"); if (termPos < (tempUrl.length() - 1)) //it means structure length { URL = tempUrl.substring(0, termPos); } else //it means string length { URL = tempUrl; is.skip(24); //it didn't read to the end of the struct. } }
From source file:tv.amwa.maj.io.aaf.AAFStream.java
License:Apache License
public ByteBuffer read(int noOfBytes) throws EndOfDataException, IOException, IllegalArgumentException { DocumentInputStream dis = getDocumentInputStream(); long actualSkip = dis.skip(position); if (actualSkip < position) throw new EndOfDataException("Position plus length is longer than the AAF stream."); byte[] bytes = new byte[noOfBytes]; position += dis.read(bytes);/*ww w.j a va 2s .c o m*/ return ByteBuffer.wrap(bytes); }