/** * Resets the underlying stream offset; clear {@link #inBuffer} and * {@link #outBuffer}. This Typically happens during {@link #skip(long)}. * * @param offset the offset of the stream. * @throws IOException if an I/O error occurs. */ protected void resetStreamOffset(long offset) throws IOException { streamOffset = offset; inBuffer.clear(); outBuffer.clear(); outBuffer.limit(0); resetCipher(offset); padding = getPadding(offset); inBuffer.position(padding); // Set proper position for input data. }
/** * This method is executed immediately after decryption. Checks whether * cipher should be updated and recalculate padding if needed. * * @param position the given position in the data.. * @return the byte. * @throws IOException if an I/O error occurs. */ protected byte postDecryption(long position) throws IOException { byte padding = 0; if (cipherReset) { /* * This code is generally not executed since the cipher usually * maintains cipher context (e.g. the counter) internally. However, * some implementations can't maintain context so a re-init is * necessary after each decryption call. */ resetCipher(position); padding = getPadding(position); inBuffer.position(padding); } return padding; }