|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.OutputStream iaik.cms.CompressedDataOutputStream
public class CompressedDataOutputStream
This is an OutputStream
implementation of the CMS CompressedData
structure (see RFC 3274).
It allows creating a compressed object by writing the content to be
compressed to this stream.
It only supports implicit (where the content is included in the CompressedData object) CompressedData objects.
This stream version will encode the content of the CompressedData as a constructed OCTET STRING. Each write operation to this stream will result in a OCTET STRING block within this constructed OCTET STRING.
The final call to close()
will finish the encoding.
The typical usage of this class looks like this example for creating a CMS CompressedData structure with the compressed content included.
// the input stream from which to read the data to be compressed InputStream dataInputStream = ... // the output stream to which to write the compressed data OutputStream resultStream = ... // the compression algorithm to be used AlgorithmID compressionAlg = (AlgorithmID)CMSAlgorithmID.zlib_compress.clone(); // create CompressedDataOutputStream CompressedDataOutputStream compressedData = new CompressedDataOutputStream(resultStream, compressionAlg); // write in the data to be compressed byte[] buffer = new byte[2048]; int bytesRead; while ((bytesRead = dataInputStream.read(buffer)) != -1) { compressedData.write(buffer, 0, bytesRead); } // closing the stream finishes compression and encoding and closes the underlying stream compressedData.close();
If you want to encapsulate the CompressedData into a ContentInfo you first must
wrap a ContentInfoOutputStream
around the final
output stream (the ContentInfoOutputStream has to write its headers to the
stream at first, thus it must be created at the "lowest" level):
ContentInfoOutputStream contentInfoStream = new ContentInfoOutputStream(ObjectID.cms_compressedData, resultStream); // now create CompressedDataOutputStream for the ContentInfoStream: CompressedDataOutputStream compressedData = new CompressedDataOutputStream(contentInfoStream, compressionAlg); // the further proceeding is same as above // write in the data to be compressed byte[] buffer = new byte[2048]; int bytesRead; while ((bytesRead = dataInputStream.read(buffer)) != -1) { compressedData.write(buffer, 0, bytesRead); } // closing the stream finishes compression and encoding and closes the underlying stream compressedData.close();Use class
CompressedDataStream
to read in and parse
the encoded CompressedData and decompress the content.
ContentInfoOutputStream
,
CompressedDataStream
Constructor Summary | |
---|---|
CompressedDataOutputStream(ObjectID contentType,
java.io.OutputStream out,
AlgorithmID compressionAlgorithm)
Creates a new CompressedDataOutputStream object which later writes the complete encoded CompressedData structure to the given output stream (e.g. |
|
CompressedDataOutputStream(java.io.OutputStream out,
AlgorithmID compressionAlgorithm)
Creates a new CompressedDataOutputStream object which later writes the complete encoded CompressedData structure to the given output stream (e.g. |
Method Summary | |
---|---|
void |
close()
Finishes compression and encoding and closes the underlying stream. |
void |
flush()
Flushes any internal data and calls flush of the underlying stream. |
SecurityProvider |
getSecurityProvider()
Gets the SecurityProvider installed for this CompressedDataOutputStream. |
int |
getVersion()
Returns the version syntax number (0). |
void |
setSecurityProvider(SecurityProvider securityProvider)
Sets the SecurityProvider for this CompressedDataOutputStream. |
java.lang.String |
toString()
Returns a string giving some information about this CompressedDataOutputStream object. |
java.lang.String |
toString(boolean detailed)
Returns a string giving some - if requested - detailed information about this CompressedDataOutputStream object. |
void |
write(byte[] b)
Processes the given content data to be compressed. |
void |
write(byte[] b,
int off,
int len)
Processes the given content data to be compressed. |
void |
write(int b)
Processes the given content byte to be compressed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CompressedDataOutputStream(java.io.OutputStream out, AlgorithmID compressionAlgorithm)
write(byte[])
).
The content type of the inherent content data is set to ObjectID.cms_data
.
out
- The output stream to which to write the encoded CompressedData
structure.compressionAlgorithm
- the compression algorithm to be used for content compressionpublic CompressedDataOutputStream(ObjectID contentType, java.io.OutputStream out, AlgorithmID compressionAlgorithm)
write(byte[])
).
contentType
- the content type (e.g. ObjectID.cms_data) of the data to be compressedout
- The output stream to which to write the encoded CompressedData
structure.compressionAlgorithm
- the compression algorithm to be used for content compressionMethod Detail |
---|
public void write(byte[] b, int off, int len) throws java.io.IOException
write
in class java.io.OutputStream
b
- The data to be compressed as byte array.off
- The start offset in the data array b
.len
- The number of bytes to write.
java.io.IOException
- If an I/O error occurs.public void write(byte[] b) throws java.io.IOException
write
in class java.io.OutputStream
b
- The data to be compressed as byte array.
java.io.IOException
- If an I/O error occurs.public void write(int b) throws java.io.IOException
Note that when repeatedly calling this method to write single data bytes
the encoding may consist of many single-byte OCTET STRINGs. Thus it may be more
appropriate to use a byte array expcting
method.
write
write
in class java.io.OutputStream
b
- The content data byte to be compressed
java.io.IOException
- If an I/O error occurs.public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
java.io.IOException
- If flushing the stream fails.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in class java.io.OutputStream
java.io.IOException
- if an I/O error occurs while writing to the streampublic void setSecurityProvider(SecurityProvider securityProvider)
This method allows to explicitly set a SecurityProvider for this CompressedDataOutputStream. If no explicit SecurityProvider is set, the default system wide installed SecurityProvider will be used for the required cryptographic operations.
This class may use the following method of the SecurityProvider
, which may be overriden by an application, if required:
getOutputStreamCompressEngine()
to get an OutputStreamCompressEngine through which the data is to be piped for compression.
securityProvider
- the SecurityProvider to be setpublic SecurityProvider getSecurityProvider()
This class uses the following method of the SecurityProvider
, which may be overriden by an application, if required:
getOutputStreamCompressEngine()
to get an OutputStreamCompressEngine through which the data is to be piped for compression.
set
for this object,
the default system wide installed SecurityProvider will be used for the required cryptographic
operations. However, this method will return null
if it does not have its own
SecurityProvider.
null
if
this object does not have its own SecurityProviderpublic int getVersion()
public java.lang.String toString()
CompressedDataOutputStream
object.
toString
in class java.lang.Object
public java.lang.String toString(boolean detailed)
CompressedDataOutputStream
object.
detailed
- - whether or not to give detailed information
|
This Javadoc may contain text parts from text parts from IETF Internet Standard specifications (see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |