List of usage examples for org.apache.poi.poifs.filesystem DocumentInputStream readInt
@Override
public int readInt()
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 va 2 s . co 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.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 www . j a v a2 s . c om*/ * @ 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.ItemMoniker.java
License:Apache License
/** * * @param is DocumentINputStream opened at the start of the Moniker struct. * @throws IOException/* w ww . j ava 2s .c o m*/ */ ItemMoniker(DocumentInputStream is) throws IOException { delimLength = is.readInt(); byte[] delim = new byte[delimLength]; is.read(delim); delimAnsi = new String(delim); itemLength = is.readInt(); byte[] item = new byte[itemLength]; is.read(item); itemAnsi = new String(item); }
From source file:org.ddt.listener.ole.OleStreamListener.java
License:Apache License
/** * Reads a "\1Ole" stream and stores the links found in it. * <p/>/*www .j ava 2s . 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.//from w w w . j av a2s . c o 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. } }