Package com.aoindustries.io
Class PaddingOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- com.aoindustries.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 ofSecureRandomas the source of random bytes for padding.PaddingOutputStream(OutputStream out, int blockSize, byte padding)Deprecated.Please use random paddingPaddingOutputStream(OutputStream out, int blockSize, Random random)Uses the given source of random bytes for padding.
-
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
-
-
-
-
Constructor Detail
-
PaddingOutputStream
public PaddingOutputStream(OutputStream out, int blockSize, Random random)
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 ofSecureRandomas 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
-
-