protected void write(byte[] b, int off, int len, boolean writePlain) throws IOException { if (len == 0) { return; } if (len < 0 || b.length < off+len) { throw new IOException("not enough bytes in your input buffer"); } final int chunkMask = getChunkMask(); while (len > 0) { int posInChunk = (int)(pos & chunkMask); int nextLen = Math.min(chunk.length-posInChunk, len); System.arraycopy(b, off, chunk, posInChunk, nextLen); if (writePlain) { plainByteFlags.set(posInChunk, posInChunk+nextLen); } pos += nextLen; totalPos += nextLen; off += nextLen; len -= nextLen; if ((pos & chunkMask) == 0) { writeChunk(len > 0); } } }
@Override public void close() throws IOException { if (isClosed) { LOG.log(POILogger.DEBUG, "ChunkedCipherOutputStream was already closed - ignoring"); return; } isClosed = true; try { writeChunk(false); super.close(); if (fileOut != null) { int oleStreamSize = (int)(fileOut.length()+LittleEndianConsts.LONG_SIZE); calculateChecksum(fileOut, (int)pos); dir.createDocument(DEFAULT_POIFS_ENTRY, oleStreamSize, new EncryptedPackageWriter()); createEncryptionInfoEntry(dir, fileOut); } } catch (GeneralSecurityException e) { throw new IOException(e); } }
protected void write(byte[] b, int off, int len, boolean writePlain) throws IOException { if (len == 0) { return; } if (len < 0 || b.length < off+len) { throw new IOException("not enough bytes in your input buffer"); } final int chunkMask = getChunkMask(); while (len > 0) { int posInChunk = (int)(pos & chunkMask); int nextLen = Math.min(chunk.length-posInChunk, len); System.arraycopy(b, off, chunk, posInChunk, nextLen); if (writePlain) { plainByteFlags.set(posInChunk, posInChunk+nextLen); } pos += nextLen; totalPos += nextLen; off += nextLen; len -= nextLen; if ((pos & chunkMask) == 0) { writeChunk(len > 0); } } }
@Override public void close() throws IOException { if (isClosed) { LOG.log(POILogger.DEBUG, "ChunkedCipherOutputStream was already closed - ignoring"); return; } isClosed = true; try { writeChunk(false); super.close(); if (fileOut != null) { int oleStreamSize = (int)(fileOut.length()+LittleEndianConsts.LONG_SIZE); calculateChecksum(fileOut, (int)pos); dir.createDocument(DEFAULT_POIFS_ENTRY, oleStreamSize, new EncryptedPackageWriter()); createEncryptionInfoEntry(dir, fileOut); } } catch (GeneralSecurityException e) { throw new IOException(e); } }