Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright 2013-2015, Inc. or its affiliates. All Rights Reserved.
  * Portions copyright 2006-2009 James Murty. Please see LICENSE.txt
  * for applicable license terms and NOTICE.txt for applicable notices.
  * Licensed under the Apache License, Version 2.0 (the "License").
  * You may not use this file except in compliance with the License.
  * A copy of the License is located at
 * or in the "license" file accompanying this file. This file is distributed
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.

this class is no longer used and will be removed in the future

Wraps an InputStream with a CipherInputStream to encrypt it, and handles resets by attempting to reset on the original, unencrypted data InputStream, and recreate an identical Cipher and identical CipherInputStream on the original data.

It's repeatable if and only if the underlying unencryptedDataStream is repeatable - if the underlying input stream is not repeatable and you're going to buffer to make it repeatable anyways, it makes more sense to do so after wrapping in this object, so we buffer the encrypted data and don't have to bother re-encrypting on retry.

This stream only supports being marked before the first call to read or skip, since it's not possible to rewind the encryption state of a CipherInputStream to an arbitrary point. If you call mark after calling read or skip, it will throw an UnsupportedOperationException.

public class RepeatableCipherInputStream extends
Constructs a new repeatable cipher input stream using the specified InputStream as the source data, and the CipherFactory for building Cipher objects.

input The original, unencrypted data stream. This stream should be markable/resetable in order for this class to work correctly.
cipherFactory The factory used for creating identical cipher objects when this stream is reset and a new CipherInputStream is needed.
    public RepeatableCipherInputStream(final InputStream input,
                                       final CipherFactory cipherFactory) {
            InputStream unencryptedDataStreamCipherFactory cipherFactory) {
        return newCipherInputStream(unencryptedDataStreamcipherFactory);
    private static FilterInputStream newCipherInputStream(
            InputStream unencryptedDataStreamCipherFactory cipherFactory) {
        return new CipherInputStream(unencryptedDataStream,
New to GrepCode? Check out our FAQ X