java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, CanSetDropBehind, IOStatisticsSource, StreamCapabilities, Syncable@Private @Evolving public class CryptoOutputStream extends java.io.FilterOutputStream implements Syncable, CanSetDropBehind, StreamCapabilities, IOStatisticsSource
counter = base + pos/(algorithm blocksize); padding = pos%(algorithm blocksize);
The underlying stream offset is maintained as state. Note that while some of this class' methods are synchronized, this is just to match the threadsafety behavior of DFSOutputStream. See HADOOP-11710.
StreamCapabilities.StreamCapabilityABORTABLE_STREAM, DROPBEHIND, HFLUSH, HSYNC, IOSTATISTICS, IOSTATISTICS_CONTEXT, PREADBYTEBUFFER, READAHEAD, READBYTEBUFFER, UNBUFFER, VECTOREDIO| Constructor | Description |
|---|---|
CryptoOutputStream(java.io.OutputStream out,
CryptoCodec codec,
byte[] key,
byte[] iv) |
|
CryptoOutputStream(java.io.OutputStream out,
CryptoCodec codec,
byte[] key,
byte[] iv,
long streamOffset) |
|
CryptoOutputStream(java.io.OutputStream out,
CryptoCodec codec,
byte[] key,
byte[] iv,
long streamOffset,
boolean closeOutputStream) |
|
CryptoOutputStream(java.io.OutputStream out,
CryptoCodec codec,
int bufferSize,
byte[] key,
byte[] iv) |
|
CryptoOutputStream(java.io.OutputStream out,
CryptoCodec codec,
int bufferSize,
byte[] key,
byte[] iv,
long streamOffset) |
|
CryptoOutputStream(java.io.OutputStream out,
CryptoCodec codec,
int bufferSize,
byte[] key,
byte[] iv,
long streamOffset,
boolean closeOutputStream) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
|
void |
flush() |
To flush, we need to encrypt the data in the buffer and write to the
underlying stream, then do the flush.
|
IOStatistics |
getIOStatistics() |
Return a statistics instance.
|
java.io.OutputStream |
getWrappedStream() |
|
boolean |
hasCapability(java.lang.String capability) |
Query the stream for a specific capability.
|
void |
hflush() |
Flush out the data in client's user buffer.
|
void |
hsync() |
Similar to posix fsync, flush out the data in client's user buffer
all the way to the disk device (but the disk may have it in its cache).
|
void |
setDropBehind(java.lang.Boolean dropCache) |
Configure whether the stream should drop the cache.
|
void |
sync() |
Deprecated.
|
void |
write(byte[] b,
int off,
int len) |
Encryption is buffer based.
|
void |
write(int b) |
public CryptoOutputStream(java.io.OutputStream out,
CryptoCodec codec,
int bufferSize,
byte[] key,
byte[] iv)
throws java.io.IOException
java.io.IOExceptionpublic CryptoOutputStream(java.io.OutputStream out,
CryptoCodec codec,
int bufferSize,
byte[] key,
byte[] iv,
long streamOffset)
throws java.io.IOException
java.io.IOExceptionpublic CryptoOutputStream(java.io.OutputStream out,
CryptoCodec codec,
int bufferSize,
byte[] key,
byte[] iv,
long streamOffset,
boolean closeOutputStream)
throws java.io.IOException
java.io.IOExceptionpublic CryptoOutputStream(java.io.OutputStream out,
CryptoCodec codec,
byte[] key,
byte[] iv)
throws java.io.IOException
java.io.IOExceptionpublic CryptoOutputStream(java.io.OutputStream out,
CryptoCodec codec,
byte[] key,
byte[] iv,
long streamOffset)
throws java.io.IOException
java.io.IOExceptionpublic CryptoOutputStream(java.io.OutputStream out,
CryptoCodec codec,
byte[] key,
byte[] iv,
long streamOffset,
boolean closeOutputStream)
throws java.io.IOException
java.io.IOExceptionpublic java.io.OutputStream getWrappedStream()
public void write(byte[] b,
int off,
int len)
throws java.io.IOException
inBuffer, then write to this buffer.
If inBuffer is full, then do encryption and write data to the
underlying stream.write in class java.io.FilterOutputStreamb - the data.off - the start offset in the data.len - the number of bytes to write.java.io.IOException - raised on errors performing I/O.public void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.io.Closeableclose in class java.io.FilterOutputStreamjava.io.IOExceptionpublic void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.FilterOutputStreamjava.io.IOExceptionpublic void write(int b)
throws java.io.IOException
write in class java.io.FilterOutputStreamjava.io.IOExceptionpublic void setDropBehind(java.lang.Boolean dropCache)
throws java.io.IOException,
java.lang.UnsupportedOperationException
CanSetDropBehindsetDropBehind in interface CanSetDropBehinddropCache - Whether to drop the cache. null means to use the
default value.java.io.IOException - If there was an error changing the dropBehind
setting.
UnsupportedOperationException If this stream doesn't support
setting the drop-behind.java.lang.UnsupportedOperationExceptionpublic void hflush()
throws java.io.IOException
Syncablepublic void hsync()
throws java.io.IOException
Syncable@Deprecated
public void sync()
throws java.io.IOException
sync in interface Syncablejava.io.IOExceptionSyncable.hflush()public boolean hasCapability(java.lang.String capability)
StreamCapabilitieshasCapability in interface StreamCapabilitiescapability - string to query the stream support for.public IOStatistics getIOStatistics()
IOStatisticsSource
It is not a requirement that the same instance is returned every time.
IOStatisticsSource.
If the object implementing this is Closeable, this method may return null if invoked on a closed object, even if it returns a valid instance when called earlier.
getIOStatistics in interface IOStatisticsSourceCopyright © 2008–2025 Apache Software Foundation. All rights reserved.