@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
protected void findProjectProperties(DirectoryNode node, Map<String, String> moduleNameMap, ModuleMap modules) throws IOException { for (Entry entry : node) { if ("project".equalsIgnoreCase(entry.getName())) { DocumentNode document = (DocumentNode)entry; try(DocumentInputStream dis = new DocumentInputStream(document)) { readProjectProperties(dis, moduleNameMap, modules); return; } } else if (entry instanceof DirectoryNode) { findProjectProperties((DirectoryNode)entry, moduleNameMap, modules); } } }
public static void dump(DirectoryEntry root, File parent) throws IOException { for(Iterator<Entry> it = root.getEntries(); it.hasNext();){ Entry entry = it.next(); if(entry instanceof DocumentNode){ DocumentNode node = (DocumentNode)entry; DocumentInputStream is = new DocumentInputStream(node); byte[] bytes = IOUtils.toByteArray(is); is.close(); try (OutputStream out = new FileOutputStream(new File(parent, node.getName().trim()))) { out.write(bytes); } } else if (entry instanceof DirectoryEntry){ DirectoryEntry dir = (DirectoryEntry)entry; File file = new File(parent, entry.getName()); if(!file.exists() && !file.mkdirs()) { throw new IOException("Could not create directory " + file); } dump(dir, file); } else { System.err.println("Skipping unsupported POIFS entry: " + entry); } } } public static void dump(POIFSFileSystem fs, int startBlock, String name, File parent) throws IOException {
@Override public int readUByte() { checkAvaliable(1); byte[] data = new byte[1]; readFully(data, 0, 1); if (data[0] >= 0) return data[0]; return data[0] + 256; } }
@Override public int read() throws IOException { dieIfClosed(); if (atEOD()) { return EOF; } byte[] b = new byte[1]; int result = read(b, 0, 1); if(result >= 0) { if(b[0] < 0) { return b[0]+256; } return b[0]; } return result; }
private static boolean isEqual(DocumentInputStream i1, DocumentInputStream i2) throws IOException { final byte[] buf1 = new byte[4*1024]; final byte[] buf2 = new byte[4*1024]; try { int len; while ((len = i1.read(buf1)) > 0) { i2.readFully(buf2,0,len); for(int i=0;i<len;i++) { if (buf1[i] != buf2[i]) { return false; } } } // is the end of the second file also. return i2.read() < 0; } catch(EOFException | RuntimeException ioe) { return false; } } }
protected void initWordHeader(InputStream in) throws IOException, PasswordProtectedException { _fsys = new POIFSFileSystem(in); // load our POIFS document streams. DocumentEntry headerProps = (DocumentEntry)_fsys.getRoot().getEntry("WordDocument"); DocumentInputStream din = _fsys.createDocumentInputStream("WordDocument"); _header = new byte[headerProps.getSize()]; din.read(_header); din.close(); }
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();
public void processPOIFSReaderEvent(POIFSReaderEvent event) { try { if (!event.getName().equalsIgnoreCase("PowerPoint Document")) return; DocumentInputStream input = event.getStream(); byte[] buffer = new byte[input.available()]; input.read(buffer, 0, input.available()); for (int i = 0; i < buffer.length - 20; i++) { long type = LittleEndian.getUShort(buffer, i + 2); long size = LittleEndian.getUInt(buffer, i + 4); if (type == 4008) { os.write(buffer, i + 4 + 1, (int) size + 3); i = i + 4 + 1 + (int) size - 1; } } } catch (Exception e) { } } }
public EncryptionInfo(DirectoryNode dir) throws IOException { DocumentInputStream dis = dir.createDocumentInputStream("EncryptionInfo"); versionMajor = dis.readShort(); versionMinor = dis.readShort(); encryptionFlags = dis.readInt(); if (versionMajor == 4 && versionMinor == 4 && encryptionFlags == 0x40) { StringBuilder builder = new StringBuilder(); byte[] xmlDescriptor = new byte[dis.available()]; dis.read(xmlDescriptor); for (byte b : xmlDescriptor) builder.append((char)b); String descriptor = builder.toString(); header = new EncryptionHeader(descriptor); verifier = new EncryptionVerifier(descriptor); } else { int hSize = dis.readInt(); header = new EncryptionHeader(dis); if (header.getAlgorithm()==EncryptionHeader.ALGORITHM_RC4) { verifier = new EncryptionVerifier(dis, 20); } else { verifier = new EncryptionVerifier(dis, 32); } } }
@Override public EmbeddedData extract(DirectoryNode dn) throws IOException { ClassIDPredefined clsId = ClassIDPredefined.lookup(dn.getStorageClsid()); String contentType = null; String ext = null; if (clsId != null) { contentType = clsId.getContentType(); ext = clsId.getFileExtension(); } if (contentType == null || ext == null) { contentType = "application/zip"; ext = ".zip"; } DocumentInputStream dis = dn.createDocumentInputStream("package"); byte data[] = IOUtils.toByteArray(dis); dis.close(); return new EmbeddedData(dn.getName()+ext, data, contentType); } }
/** * {@inheritDoc} */ @Override protected String extractText(POIFSFileSystem poiFs, long filesize, ContentParserOptions options) throws Exception { // PowerPointExtractor pptExtractor = new PowerPointExtractor(poiFs); // return pptExtractor.getText(); DocumentInputStream docStream = poiFs.createDocumentInputStream(POIFS_POWERPOINT_DOC); int length = docStream.available(); int maximumBufferSize = options.getMaximumBufferSize(); if (maximumBufferSize < length) { length = maximumBufferSize; } int capacity = length / 10; StringBuffer textBuffer = new StringBuffer(capacity); byte[] buffer = new byte[length]; docStream.read(buffer); docStream.close(); extractRecursive(buffer, 0, length, textBuffer); return textBuffer.toString(); }
TikaInputStream stream = TikaInputStream.get(new DocumentInputStream((DocumentEntry) ooxml)); try (DocumentInputStream inp = new DocumentInputStream(contentsEntry)) { ret = new byte[contentsEntry.getSize()]; inp.readFully(ret);
private byte[] nextChunk() throws GeneralSecurityException, IOException { int index = (int)(_pos >> 12); byte[] blockKey = new byte[4]; LittleEndian.putInt(blockKey, 0, index); byte[] iv = generateIv(_info.getHeader().getAlgorithm(), _info.getHeader().getKeySalt(), blockKey); _cipher.init(Cipher.DECRYPT_MODE, _secretKey, new IvParameterSpec(iv)); if (_lastIndex != index) _stream.skip((index - _lastIndex) << 12); byte[] block = new byte[Math.min(_stream.available(), 4096)]; _stream.readFully(block); _lastIndex = index + 1; return _cipher.doFinal(block); } }
/** * {@inheritDoc} */ @Override public int available() { return m_dis.available(); }
@Override public double readDouble() { return Double.longBitsToDouble(readLong()); }
@Override public int read(byte[] b, int off, int len) throws IOException { dieIfClosed(); if (b == null) { throw new IllegalArgumentException("buffer must not be null"); } if (off < 0 || len < 0 || b.length < off + len) { throw new IndexOutOfBoundsException("can't read past buffer boundaries"); } if (len == 0) { return 0; } if (atEOD()) { return EOF; } int limit = Math.min(remainingBytes(), len); readFully(b, off, limit); return limit; }
public EncryptionHeader(DocumentInputStream is) throws IOException { flags = is.readInt(); sizeExtra = is.readInt(); algorithm = is.readInt(); hashAlgorithm = is.readInt(); keySize = is.readInt(); providerType = is.readInt(); is.readLong(); // skip reserved StringBuilder builder = new StringBuilder(); while (true) { char c = (char) is.readShort(); if (c == 0) { break; } builder.append(c); } cspName = builder.toString(); cipherMode = MODE_ECB; keySalt = null; }
/** * Repositions this stream to the position at the time the mark() method was * last called on this input stream. If mark() has not been called this * method repositions the stream to its beginning. */ public void reset() { delegate.reset(); }
/** * {@inheritDoc} */ @Override public synchronized void mark(int readlimit) { m_dis.mark(readlimit); }