- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- com.aoapps.hodgepodge.io.PaddingOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public class PaddingOutputStream extends FilterOutputStream
Pads the last block with the necessary number of bytes before closing the stream. If padding is necessary without closing, usefinish.
-
-
Field Summary
-
Fields inherited from class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Constructor Description PaddingOutputStream(OutputStream out, int blockSize)Uses a default instance ofSecureRandom, which is not a strong instance to avoid blocking, as the source of random bytes for padding.PaddingOutputStream(OutputStream out, int blockSize, byte padding)Deprecated.Please use random paddingPaddingOutputStream(OutputStream out, int blockSize, SecureRandom secureRandom)Uses the given source of random bytes for padding.PaddingOutputStream(OutputStream out, int blockSize, Random random)Deprecated.Please useSecureRandom.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Pads, flushes, and closes the underlying stream.voidfinish()Pads and flushes without closing the underlying stream.voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)-
Methods inherited from class java.io.FilterOutputStream
flush
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Constructor Detail
-
PaddingOutputStream
@Deprecated public PaddingOutputStream(OutputStream out, int blockSize, Random random)
Deprecated.Please useSecureRandom. This method will stay, but will remain deprecated since it should only be used after careful consideration.Uses the given source of random bytes for padding.- Parameters:
blockSize- When<= 0, no padding will be performed. This is consistent with zero returned fromCipher.getBlockSize()when not a block cipher.
-
PaddingOutputStream
public PaddingOutputStream(OutputStream out, int blockSize, SecureRandom secureRandom)
Uses the given source of random bytes for padding.- Parameters:
blockSize- When<= 0, no padding will be performed. This is consistent with zero returned fromCipher.getBlockSize()when not a block cipher.
-
PaddingOutputStream
public PaddingOutputStream(OutputStream out, int blockSize)
Uses a default instance ofSecureRandom, which is not a strong instance to avoid blocking, as the source of random bytes for padding.- Parameters:
blockSize- When<= 0, no padding will be performed. This is consistent with zero returned fromCipher.getBlockSize()when not a block cipher.
-
PaddingOutputStream
@Deprecated public PaddingOutputStream(OutputStream out, int blockSize, byte padding)
Deprecated.Please use random padding
-
-
Method Detail
-
write
public void write(int b) throws IOException- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
write
public void write(byte[] b) throws IOException- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
finish
public void finish() throws IOExceptionPads and flushes without closing the underlying stream.- Throws:
IOException
-
close
public void close() throws IOExceptionPads, flushes, and closes the underlying stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException
-
-