org.apache.poi.poifs.crypt
Class ChunkedCipherOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by org.apache.poi.poifs.crypt.ChunkedCipherOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable
Direct Known Subclasses:
BinaryRC4Encryptor.BinaryRC4CipherOutputStream, CryptoAPIEncryptor.CryptoAPICipherOutputStream

@Internal
public abstract class ChunkedCipherOutputStream
extends java.io.FilterOutputStream


Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
ChunkedCipherOutputStream(DirectoryNode dir, int chunkSize)
           
ChunkedCipherOutputStream(java.io.OutputStream stream, int chunkSize)
           
 
Method Summary
protected abstract  void calculateChecksum(java.io.File fileOut, int oleStreamSize)
           
 void close()
           
protected abstract  void createEncryptionInfoEntry(DirectoryNode dir, java.io.File tmpFile)
           
protected  byte[] getChunk()
           
protected  int getChunkMask()
           
protected  java.util.BitSet getPlainByteFlags()
           
protected  long getPos()
           
protected  long getTotalPos()
           
protected abstract  javax.crypto.Cipher initCipherForBlock(javax.crypto.Cipher existing, int block, boolean lastChunk)
           
 javax.crypto.Cipher initCipherForBlock(int block, boolean lastChunk)
           
protected  int invokeCipher(int posInChunk, boolean doFinal)
          Helper function for overriding the cipher invocation, i.e.
 void setNextRecordSize(int recordSize, boolean isPlain)
          Some ciphers (actually just XOR) are based on the record size, which needs to be set before encryption
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
protected  void write(byte[] b, int off, int len, boolean writePlain)
           
 void write(int b)
           
protected  void writeChunk(boolean continued)
           
 void writePlain(byte[] b, int off, int len)
           
 
Methods inherited from class java.io.FilterOutputStream
flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChunkedCipherOutputStream

public ChunkedCipherOutputStream(DirectoryNode dir,
                                 int chunkSize)
                          throws java.io.IOException,
                                 java.security.GeneralSecurityException
Throws:
java.io.IOException
java.security.GeneralSecurityException

ChunkedCipherOutputStream

public ChunkedCipherOutputStream(java.io.OutputStream stream,
                                 int chunkSize)
                          throws java.io.IOException,
                                 java.security.GeneralSecurityException
Throws:
java.io.IOException
java.security.GeneralSecurityException
Method Detail

initCipherForBlock

public final javax.crypto.Cipher initCipherForBlock(int block,
                                                    boolean lastChunk)
                                             throws java.io.IOException,
                                                    java.security.GeneralSecurityException
Throws:
java.io.IOException
java.security.GeneralSecurityException

initCipherForBlock

protected abstract javax.crypto.Cipher initCipherForBlock(javax.crypto.Cipher existing,
                                                          int block,
                                                          boolean lastChunk)
                                                   throws java.io.IOException,
                                                          java.security.GeneralSecurityException
Throws:
java.io.IOException
java.security.GeneralSecurityException

calculateChecksum

protected abstract void calculateChecksum(java.io.File fileOut,
                                          int oleStreamSize)
                                   throws java.security.GeneralSecurityException,
                                          java.io.IOException
Throws:
java.security.GeneralSecurityException
java.io.IOException

createEncryptionInfoEntry

protected abstract void createEncryptionInfoEntry(DirectoryNode dir,
                                                  java.io.File tmpFile)
                                           throws java.io.IOException,
                                                  java.security.GeneralSecurityException
Throws:
java.io.IOException
java.security.GeneralSecurityException

write

public void write(int b)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream
Throws:
java.io.IOException

writePlain

public void writePlain(byte[] b,
                       int off,
                       int len)
                throws java.io.IOException
Throws:
java.io.IOException

write

protected void write(byte[] b,
                     int off,
                     int len,
                     boolean writePlain)
              throws java.io.IOException
Throws:
java.io.IOException

getChunkMask

protected int getChunkMask()

writeChunk

protected void writeChunk(boolean continued)
                   throws java.io.IOException
Throws:
java.io.IOException

invokeCipher

protected int invokeCipher(int posInChunk,
                           boolean doFinal)
                    throws java.security.GeneralSecurityException
Helper function for overriding the cipher invocation, i.e. XOR doesn't use a cipher and uses it's own implementation

Throws:
javax.crypto.BadPaddingException
javax.crypto.IllegalBlockSizeException
javax.crypto.ShortBufferException
java.security.GeneralSecurityException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.FilterOutputStream
Throws:
java.io.IOException

getChunk

protected byte[] getChunk()

getPlainByteFlags

protected java.util.BitSet getPlainByteFlags()

getPos

protected long getPos()

getTotalPos

protected long getTotalPos()

setNextRecordSize

public void setNextRecordSize(int recordSize,
                              boolean isPlain)
Some ciphers (actually just XOR) are based on the record size, which needs to be set before encryption

Parameters:
recordSize - the size of the next record
isPlain - true if the record is unencrypted