Top Fields Constructors Methods
org.apache.poi.poifs.crypt

public abstract Class ChunkedCipherInputStream

extends LittleEndianInputStream
Class Inheritance
Known Direct Subclasses
org.apache.poi.poifs.crypt.agile.AgileDecryptor.AgileCipherInputStream, org.apache.poi.poifs.crypt.binaryrc4.BinaryRC4Decryptor.BinaryRC4CipherInputStream, org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIDecryptor.CryptoAPICipherInputStream, org.apache.poi.poifs.crypt.xor.XORDecryptor.XORCipherInputStream
Annotations
@Internal
Imports
java.io.EOFException, .IOException, .InputStream, java.security.GeneralSecurityException, javax.crypto.Cipher, org.apache.poi.EncryptedDocumentException, org.apache.poi.util.IOUtils, .Internal, .LittleEndianInputStream

Field Summary

Modifier and TypeField and Description
private final byte[]
private final int
private boolean
private final int
private final Cipher
private int
private final byte[]
private long
private final long

Constructor Summary

AccessConstructor and Description
public
ChunkedCipherInputStream(InputStream stream, long size, int chunkSize)

public
ChunkedCipherInputStream(InputStream stream, long size, int chunkSize, int initialPos)

Method Summary

Modifier and TypeMethod and Description
public int
available()

Overrides org.apache.poi.util.LittleEndianInputStream.available.

Implements org.apache.poi.util.LittleEndianInput.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.

protected byte[]

Returns:

the chunk bytes
getChunk
()

protected int
protected byte[]

Returns:

the plain bytes
getPlain
()

public long

Returns:

the absolute position in the stream
getPos
()

public final Cipher
initCipherForBlock(int block)

protected abstract Cipher
initCipherForBlock(Cipher existing, int block)

protected int
invokeCipher(int totalBytes, boolean doFinal)

Helper function for overriding the cipher invocation, i.e. XOR doesn't use a cipher and uses its own implementation

public synchronized void
mark(int
the maximum limit of bytes that can be read before the mark position becomes invalid.
readlimit
)

Overrides org.apache.poi.util.LittleEndianInputStream.mark.

Marks the current position in this input stream.

public boolean
markSupported()

Overrides java.io.FilterInputStream.markSupported.

Tests if this input stream supports the mark and reset methods.

private void
public int
read()

Overrides java.io.FilterInputStream.read.

Reads the next byte of data from the input stream.

public int
read(byte[]
the buffer into which the data is read.
b
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides org.apache.poi.util.LittleEndianInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes.

private int
read(byte[] b, int off, int len, boolean readPlain)

public void
readPlain(byte[]
the byte array to receive the bytes
b
,
int
the start offset into the byte array
off
,
int
the amount of bytes to fill
len
)

Overrides org.apache.poi.util.LittleEndianInputStream.readPlain.

Implements org.apache.poi.util.LittleEndianInput.readPlain.

Used when BIFF header fields (sid, size) are being read.

private int

Returns:

the remaining byte until EOF
remainingBytes
()

Helper method for forbidden available call - we know the size beforehand, so it's ok ...

public synchronized void
reset()

Overrides org.apache.poi.util.LittleEndianInputStream.reset.

Repositions this stream to the position at the time the mark method was last called on this input stream.

public void
setNextRecordSize(int
the size of the next record
recordSize
)

Some ciphers (actually just XOR) are based on the record size, which needs to be set before decryption

public long
skip(final long
the number of bytes to be skipped.
n
)

Overrides java.io.FilterInputStream.skip.

Skips over and discards n bytes of data from the input stream.

Inherited from org.apache.poi.util.LittleEndianInputStream:
getReadIndexreadBytereadDoublereadFloatreadFullyreadFullyreadIntreadLongreadShortreadUBytereadUIntreadUShortskipFully

Field Detail

chunkback to summary
private final byte[] chunk
chunkBitsback to summary
private final int chunkBits
chunkIsValidback to summary
private boolean chunkIsValid
chunkSizeback to summary
private final int chunkSize
cipherback to summary
private final Cipher cipher
lastIndexback to summary
private int lastIndex
plainback to summary
private final byte[] plain
posback to summary
private long pos
sizeback to summary
private final long size

Constructor Detail

ChunkedCipherInputStreamback to summary
public ChunkedCipherInputStream(InputStream stream, long size, int chunkSize) throws GeneralSecurityException
ChunkedCipherInputStreamback to summary
public ChunkedCipherInputStream(InputStream stream, long size, int chunkSize, int initialPos) throws GeneralSecurityException

Method Detail

availableback to summary
public int available()

Overrides org.apache.poi.util.LittleEndianInputStream.available.

Implements org.apache.poi.util.LittleEndianInput.available.

Doc from java.io.FilterInputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. The next caller might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Returns:int

an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking.

Annotations
@Override
getChunkback to summary
protected byte[] getChunk()
Returns:byte[]

the chunk bytes

getChunkMaskback to summary
protected int getChunkMask()
getPlainback to summary
protected byte[] getPlain()
Returns:byte[]

the plain bytes

getPosback to summary
public long getPos()
Returns:long

the absolute position in the stream

initCipherForBlockback to summary
public final Cipher initCipherForBlock(int block) throws IOException, GeneralSecurityException
initCipherForBlockback to summary
protected abstract Cipher initCipherForBlock(Cipher existing, int block) throws GeneralSecurityException
invokeCipherback to summary
protected int invokeCipher(int totalBytes, boolean doFinal) throws GeneralSecurityException

Helper function for overriding the cipher invocation, i.e. XOR doesn't use a cipher and uses its own implementation

markback to summary
public synchronized void mark(int readlimit)

Overrides org.apache.poi.util.LittleEndianInputStream.mark.

Doc from java.io.FilterInputStream.mark.

Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

The readlimit argument tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

Parameters
readlimit:int

the maximum limit of bytes that can be read before the mark position becomes invalid.

Annotations
@Override
markSupportedback to summary
public boolean markSupported()

Overrides java.io.FilterInputStream.markSupported.

Doc from java.io.FilterInputStream.markSupported.

Tests if this input stream supports the mark and reset methods.

Returns:boolean

true if this stream type supports the mark and reset method; false otherwise.

Annotations
@Override
nextChunkback to summary
private void nextChunk() throws GeneralSecurityException, IOException
readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides org.apache.poi.util.LittleEndianInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes. If len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
private int read(byte[] b, int off, int len, boolean readPlain) throws IOException
readPlainback to summary
public void readPlain(byte[] b, int off, int len)

Overrides org.apache.poi.util.LittleEndianInputStream.readPlain.

Implements org.apache.poi.util.LittleEndianInput.readPlain.

Used when BIFF header fields (sid, size) are being read. The internal Cipher instance must step even when unencrypted bytes are read

Parameters
b:byte[]

Doc from org.apache.poi.util.LittleEndianInput.readPlain.

the byte array to receive the bytes

off:int

Doc from org.apache.poi.util.LittleEndianInput.readPlain.

the start offset into the byte array

len:int

Doc from org.apache.poi.util.LittleEndianInput.readPlain.

the amount of bytes to fill

Annotations
@Override
remainingBytesback to summary
private int remainingBytes()

Helper method for forbidden available call - we know the size beforehand, so it's ok ...

Returns:int

the remaining byte until EOF

resetback to summary
public synchronized void reset()

Overrides org.apache.poi.util.LittleEndianInputStream.reset.

Doc from java.io.FilterInputStream.reset.

Repositions this stream to the position at the time the mark method was last called on this input stream.

Stream marks are intended to be used in situations where you need to read ahead a little to see what's in the stream. Often this is most easily done by invoking some general parser. If the stream is of the type handled by the parse, it just chugs along happily. If the stream is not of that type, the parser should toss an exception when it fails. If this happens within readlimit bytes, it allows the outer code to reset the stream and try another parser.

Annotations
@Override
setNextRecordSizeback to summary
public void setNextRecordSize(int recordSize)

Some ciphers (actually just XOR) are based on the record size, which needs to be set before decryption

Parameters
recordSize:int

the size of the next record

skipback to summary
public long skip(final long n)

Overrides java.io.FilterInputStream.skip.

Doc from java.io.FilterInputStream.skip.

Skips over and discards n bytes of data from the input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned.

Parameters
n:long

the number of bytes to be skipped.

Returns:long

the actual number of bytes skipped.

Annotations
@Override