public void write(int b) throws IOException { write(new byte[] { (byte)b }, 0, 1); }
@Override public void write(byte[] b, int off, int len) throws IOException { if (_closed) { throw new IOException("cannot perform requested operation on a closed stream"); } if (_limit > -1 && (size() + len) > _limit) { throw new IOException("tried to write too much data"); } if (_buffer != null) { _buffer.write(b, off, len); checkBufferSize(); } else { if (_stream == null) { _stream = new POIFSStream(_document.getFileSystem()); _stream_output = _stream.getOutputStream(); } _stream_output.write(b, off, len); _document_size += len; } }
/** * Create an OutputStream to create the specified new Entry * * @param parent Where to create the Entry * @param name Name of the new entry */ public DocumentOutputStream(DirectoryEntry parent, String name) throws IOException { this(createDocument(parent, name), -1); }
public POIFSDocument(String name, final int size, POIFSFileSystem filesystem, POIFSWriterListener writer) throws IOException { this._filesystem = filesystem; if (size < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE) { _stream = new POIFSStream(filesystem.getMiniStore()); _block_size = _filesystem.getMiniStore().getBlockStoreBlockSize(); } else { _stream = new POIFSStream(filesystem); _block_size = _filesystem.getBlockStoreBlockSize(); } this._property = new DocumentProperty(name, size); _property.setStartBlock(_stream.getStartBlock()); _property.setDocument(this); try (DocumentOutputStream os = new DocumentOutputStream(this, size)) { POIFSDocumentPath path = new POIFSDocumentPath(name.split("\\\\")); String docName = path.getComponent(path.length() - 1); POIFSWriterEvent event = new POIFSWriterEvent(os, path, docName, size); writer.processPOIFSWriterEvent(event); } }
/** * write the blocks to a stream * * @param stream the stream to which the data is to be written */ void writeBlocks(OutputStream stream) throws IOException { if (isValid()) { if (_writer != null) { DocumentOutputStream dstream = new DocumentOutputStream(stream, _size); _writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, _path, _name, _size)); dstream.writeFiller(countBlocks() * _bigBlockSize.getBigBlockSize(), DocumentBlock.getFillByte()); } else { for (int k = 0; k < bigBlocks.length; k++) { bigBlocks[k].writeBlocks(stream); } } } }
/** * Writes the specified byte to this output stream. The general * contract for write is that one byte is written to the output * stream. The byte to be written is the eight low-order bits of * the argument b. The 24 high-order bits of b are ignored. * * @param b the byte. * @exception IOException if an I/O error occurs. In particular, * an IOException may be thrown if the * output stream has been closed, or if the * writer tries to write too much data. */ public void write(int b) throws IOException { limitCheck(1); _stream.write(b); }
/** * Create a DocumentOutputStream * * @param document the DocumentEntry to which the data is actually written * @param limit the maximum number of bytes that can be written */ DocumentOutputStream(DocumentEntry document, long limit) throws IOException { this(getDocument(document), limit); }
/** * @return the DocumentBlocks */ DocumentBlock[] getBlocks() { if (isValid() && _writer != null) { ByteArrayOutputStream stream = new ByteArrayOutputStream(_size); DocumentOutputStream dstream = new DocumentOutputStream(stream, _size); _writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, _path, _name, _size)); bigBlocks = DocumentBlock.convert(_bigBlockSize, stream.toByteArray(), _size); } return bigBlocks; }
/** * write the blocks to a stream * * @param stream the stream to which the data is to be written */ void writeBlocks(OutputStream stream) throws IOException { if (isValid()) { if (_writer != null) { DocumentOutputStream dstream = new DocumentOutputStream(stream, _size); _writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, _path, _name, _size)); dstream.writeFiller(countBlocks() * _bigBlockSize.getBigBlockSize(), DocumentBlock.getFillByte()); } else { for (int k = 0; k < bigBlocks.length; k++) { bigBlocks[k].writeBlocks(stream); } } } }
/** * Writes the specified byte to this output stream. The general * contract for write is that one byte is written to the output * stream. The byte to be written is the eight low-order bits of * the argument b. The 24 high-order bits of b are ignored. * * @param b the byte. * @exception IOException if an I/O error occurs. In particular, * an IOException may be thrown if the * output stream has been closed, or if the * writer tries to write too much data. */ public void write(int b) throws IOException { limitCheck(1); _stream.write(b); }
/** * Create a DocumentOutputStream * * @param document the DocumentEntry to which the data is actually written * @param limit the maximum number of bytes that can be written */ DocumentOutputStream(DocumentEntry document, long limit) throws IOException { this(getDocument(document), limit); }
private void checkBufferSize() throws IOException { // Have we gone over the mini stream limit yet? if (_buffer.size() > POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE) { // Will need to be in the main stream byte[] data = _buffer.toByteArray(); _buffer = null; write(data, 0, data.length); } else { // So far, mini stream will work, keep going } }
/** * @return the DocumentBlocks */ DocumentBlock[] getBlocks() { if (isValid() && _writer != null) { ByteArrayOutputStream stream = new ByteArrayOutputStream(_size); DocumentOutputStream dstream = new DocumentOutputStream(stream, _size); _writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, _path, _name, _size)); bigBlocks = DocumentBlock.convert(_bigBlockSize, stream.toByteArray(), _size); } return bigBlocks; }
@Override public void write(byte[] b, int off, int len) throws IOException { if (_closed) { throw new IOException("cannot perform requested operation on a closed stream"); } if (_limit > -1 && (size() + len) > _limit) { throw new IOException("tried to write too much data"); } if (_buffer != null) { _buffer.write(b, off, len); checkBufferSize(); } else { if (_stream == null) { _stream = new POIFSStream(_document.getFileSystem()); _stream_output = _stream.getOutputStream(); } _stream_output.write(b, off, len); _document_size += len; } }
/** * Writes len bytes from the specified byte array starting at * offset off to this output stream. The general contract for * write(b, off, len) is that some of the bytes in the array b are * written to the output stream in order; element b[off] is the * first byte written and b[off+len-1] is the last byte written by * this operation.<p> * If b is null, a NullPointerException is thrown.<p> * If off is negative, or len is negative, or off+len is greater * than the length of the array b, then an * IndexOutOfBoundsException is thrown. * * @param b the data. * @param off the start offset in the data. * @param len the number of bytes to write. * @exception IOException if an I/O error occurs. In particular, * an IOException</code> is thrown if the * output stream is closed or if the writer * tries to write too many bytes. */ public void write(byte b[], int off, int len) throws IOException { limitCheck(len); _stream.write(b, off, len); }
/** * Create an OutputStream to create the specified new Entry * * @param parent Where to create the Entry * @param name Name of the new entry */ public DocumentOutputStream(DirectoryEntry parent, String name) throws IOException { this(createDocument(parent, name), -1); }
public void processPOIFSWriterEvent(POIFSWriterEvent event) { try { event.getStream().write(buf, 0, event.getLimit()); } catch (IOException e) { throw new EncryptedDocumentException(e); } } });
/** * @return the SmallDocumentBlocks */ SmallDocumentBlock[] getBlocks() { if (isValid() && _writer != null) { ByteArrayOutputStream stream = new ByteArrayOutputStream(_size); DocumentOutputStream dstream = new DocumentOutputStream(stream, _size); _writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, _path, _name, _size)); _smallBlocks = SmallDocumentBlock.convert(_bigBlockSize, stream.toByteArray(), _size); } return _smallBlocks; } } // end private class SmallBlockStore
/** * Writes len bytes from the specified byte array starting at * offset off to this output stream. The general contract for * write(b, off, len) is that some of the bytes in the array b are * written to the output stream in order; element b[off] is the * first byte written and b[off+len-1] is the last byte written by * this operation.<p> * If b is null, a NullPointerException is thrown.<p> * If off is negative, or len is negative, or off+len is greater * than the length of the array b, then an * IndexOutOfBoundsException is thrown. * * @param b the data. * @param off the start offset in the data. * @param len the number of bytes to write. * @exception IOException if an I/O error occurs. In particular, * an IOException</code> is thrown if the * output stream is closed or if the writer * tries to write too many bytes. */ public void write(byte b[], int off, int len) throws IOException { limitCheck(len); _stream.write(b, off, len); }
/** * Writes b.length bytes from the specified byte array * to this output stream. * * @param b the data. * @exception IOException if an I/O error occurs. */ public void write(byte b[]) throws IOException { write(b, 0, b.length); }