|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object iaik.cms.CompressedDataStream
public class CompressedDataStream
This class represents the stream supporting implementation of the CMS
CompressedData
type.
The compressed-data content type is identified by the following object identifier:
id-ct-compressedData OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) ct(1) 9 }
which corresponds to the OID string "1.2.840.113549.1.9.16.1.9".
The CompressedData type provides a syntax for compressing/decompressing the content of a CMS message. An algorithm identifier identifies the compression algorithm to be used ( RFC 3274 refers the ZLIB compression algorithm [RFC1950], [RFC1951]) for compressing the encapsulated content:
CompressedData ::= SEQUENCE { version CMSVersion, compressionAlgorithm CompressionAlgorithmIdentifier, encapContentInfo EncapsulatedContentInfo }
When creating
a CompressedDataStream object an application has to decide whether the
compressed content shall be incldued (IMPLICIT
mode) into
the CompressedData message or shall be transmitted by other means
(EXPLICIT
mode):
int mode = CompressedDataStream.IMPLICIT; // include contentor
int mode = CompressedDataStream.EXPLICIT; // do not include contentHowever, in both cases the content data has to be supplied when creating the
CompressedDataStream
object to perform the compression with some
particular compression algorithm, e.g.:
// transmission mode (EXPLICIT or IMPLICIT) int mode = ...; // the content data supplying input stream InputSrteam[] dataIs = ...; // compression algorithm AlgorithmID compressionAlg = CMSAlgorithmID.zlib_compress; // create the CompressedDataStream object: CompressedDataStream compressedData = new CompressedDataStream(dataIs, compressionAlg, mode);If the content shall not be included in the CompressedData object (
EXPLICIT
mode) now it is time to read away the content to transmit it by other means.
While reading the content from the stream it is compressed by piping it through a InputStreamCompressEngine
, e.g.:
// in explicit mode get and read (and thereby) compress the content if (mode == CompressedDataStream.EXPLICIT) { InputStream contentIs = compressedData.getInputStream(); byte[] buf = new byte[2048]; int r; while ((r = data_is.read(buf)) > 0) { // do something useful } }Finally method
writeTo
has to be called for BER encoding
the CompressedDataStream object and writing it to an output stream. It is recommended
to specify a positive block size value for splitting the data encoding:
int blockSize = ...; compressedData.writeTo(output_stream, blockSize);respectively
compressedData.writeTo(output_stream);It is recommended only to use the
writeTo
method where a particular
block size can be specified, because it is the intended purpose of this stream-supporting
CompressedData implementation to handle large amounts of data. When no block size is
specified the whole content data is encoded as one primitive definite octet string, which
advantageously may be done when using the non-stream supporting CompressedData
implementation.
When a positive block size is specified for encoding the CompressedData to a stream,
the content data is BER encoded as indefinite constructed octet string being composed
of a series of definite primitive encoded octet strings of blockSize
length,
e.g.:
0x24 0x80 0x04 0x02 0x01 0xAB 0x04 0x02 0x23 0x7F 0x04 0x01 0xCA 0x00 0x00instead of:
0x04 0x05 0x01 0xAB 0x23 0x7F 0xCAfor encoding the five bytes
0x01 0xAB 0x23 0x7F 0xCA
.
When receiving an CompressedData message use the CompressedDataStream(InputStream)
constructor for parsing the CompressedData
from its BER encoding:
// the input stream supplying the BER encoded CompressedData InputStream encodedStream = ...; // parse the CompressedData CompressedDataStream compressedData = new CompressedDataStream(encodedStream);If the content has been transmitted by other means (
EXPLICIT
mode) it
now has to be supplied by calling method setInputStream
since it is required for being decompressed:
if (compressedData.getMode() == CompressedDataStream.EXPLICIT) { // in explicit mode explicitly supply the compressed content to be decompressed InputStream contentIs = ...; // the compressed content supplied from an input stream compressedData.setInputStream(contentIs); }Now you may call method
getInputStream
to access the content.
While reading the stream the compressed data is decompressed by piping it through a
InputStreamCompressEngine
, e.g.:
InputStream contentIs = compressedData.getInputStream(); byte[] buf = new byte[2048]; int r; while ((r = data_is.read(buf)) > 0) { // do something useful }
Field Summary | |
---|---|
protected int |
blockSize_
The block size for block oriented stream encoding. |
protected AlgorithmID |
compressionAlgorithm_
The compression algorithm to be used. |
static ObjectID |
contentType
The ContentType oid of the CompressedData type ("1.2.840.113549.1.9.16.1.9"): |
protected ObjectID |
encapContentType_
The content type of the inherent EncapsulatedContentInfo. |
static int |
EXPLICIT
Denotes a mode where the compressed data is not included in the CompressedData message. |
static int |
IMPLICIT
Denotes a mode where the compressed data is included in the CompressedData message. |
protected java.io.InputStream |
inputStream_
An InputStream holding the data. |
protected int |
version_
The CMS version number. |
Constructor Summary | |
---|---|
protected |
CompressedDataStream()
Default constructor for dynamic object creation. |
|
CompressedDataStream(java.io.InputStream is)
Creates a CompressedDataStream object from a BER encoded CompressedData object which is read from the given input stream. |
|
CompressedDataStream(java.io.InputStream dataIs,
AlgorithmID compressionAlgorithm,
int mode)
Creates a new CompressedDataStream object for the given content data. |
|
CompressedDataStream(ObjectID contentType,
java.io.InputStream dataIs,
AlgorithmID compressionAlgorithm,
int mode)
Creates a new CompressedDataStream object for the given content data. |
Method Summary | |
---|---|
void |
decode(java.io.InputStream is)
Reads and decodes a BER encoded CompressedData from an input stream. |
int |
getBlockSize()
Gets the block size defining the length of each definite primitive encoded octet string component. |
AlgorithmID |
getCompressionAlgorithm()
Returns the compression algorithm used for data compression/decompression. |
ObjectID |
getContentType()
Returns the content type this class implements. |
ObjectID |
getEncapsulatedContentType()
Returns the content type the inherent EncapsulatetContentInfo represents. |
java.io.InputStream |
getInputStream()
Returns an input stream from which the compressed/decompressed data may be read. |
int |
getMode()
Returns the mode of this CompressedData. |
SecurityProvider |
getSecurityProvider()
Gets the SecurityProvider installed for this CompressedDataStream. |
int |
getVersion()
Returns the version syntax number (0). |
void |
setBlockSize(int blockSize)
Sets the block size for defining the length of each definite primitive encoded octet string component. |
void |
setInputStream(java.io.InputStream is)
Sets the content suppliyng input stream. |
void |
setSecurityProvider(SecurityProvider securityProvider)
Sets the SecurityProvider for this CompressedDataStream. |
ASN1Object |
toASN1Object()
Returns the CompressedData as ASN1Object. |
protected ASN1Object |
toASN1Object(int blockSize)
Returns the CompressedData as ASN1Object where a constructed OCTET STRING is used for encoding the compressed content. |
java.lang.String |
toString()
Returns a string giving some information about this CompressedData object. |
java.lang.String |
toString(boolean detailed)
Returns a string giving some - if requested - detailed information about this CompressedData object. |
void |
writeTo(java.io.OutputStream os)
Writes the CompressedData BER encoded to the supplied output stream. |
void |
writeTo(java.io.OutputStream os,
int blockSize)
Writes this CompressedData to the supplied output stream where a constructed OCTET STRING is used for encoding the content. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final ObjectID contentType
public static final int IMPLICIT
public static final int EXPLICIT
protected int version_
protected AlgorithmID compressionAlgorithm_
protected ObjectID encapContentType_
protected int blockSize_
protected java.io.InputStream inputStream_
Constructor Detail |
---|
protected CompressedDataStream()
public CompressedDataStream(java.io.InputStream dataIs, AlgorithmID compressionAlgorithm, int mode)
CompressedDataStream
object for the given content data.
The data to be compressed is supplied from an input stream. The mode
parameter
specifies whether to include the compressed data (mode = CompressedDataStream.IMPLICIT) or
not include it (mode = CompressedDataStream.EXPLICIT). The content type of the
inherent EncapsulatedContentInfo automatically is set to CMS Data.
dataIs
- the data to be compressed, supplied from an input streamcompressionAlgorithm
- the compression algorithm to be used for content compressionmode
- either CompressedDataStream.IMPLICIT for including the compressed data, or
CompressedDataStream.EXPLICIT for not including itpublic CompressedDataStream(ObjectID contentType, java.io.InputStream dataIs, AlgorithmID compressionAlgorithm, int mode)
CompressedDataStream
object for the given content data.
The data to be compressed is supplied from an input stream. The mode
parameter
specifies whether to include the compressed data (mode = CompressedDataStream.IMPLICIT) or
not include it (mode = CompressedDataStream.EXPLICIT).
contentType
- the content type (e.g. ObjectID.cms_data) of the data to be compresseddataIs
- the data to be compressed, supplied from an input streamcompressionAlgorithm
- the compression algorithm to be used for content compressionmode
- either CompressedDataStream.IMPLICIT for including the compressed data, or
CompressedDataStream.EXPLICIT for not including itpublic CompressedDataStream(java.io.InputStream is) throws java.io.IOException, CMSParsingException
is
- the InputStream holding the BER encoded CMS CompressedData object
java.io.IOException
- if an error occurs when reading from the stream
CMSParsingException
- if the object can not be parsedMethod Detail |
---|
public void setSecurityProvider(SecurityProvider securityProvider)
This method allows to explicitly set a SecurityProvider for this CompressedDataStream. 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:
getInputStreamCompressEngine()
to get an InputStreamCompressEngine through which the data is to be piped for data compression/decompression
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:
getInputStreamCompressEngine()
to get an InputStreamCompressEngine through which the data is to be piped for data compression/decompression
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 void decode(java.io.InputStream is) throws java.io.IOException, CMSParsingException
decode
in interface ContentStream
is
- the InputStream holding a BER encoded CMS CompressedData object
java.io.IOException
- if an I/O error occurs during reading from the InputStream
CMSParsingException
- if an error occurs while parsing the objectpublic ObjectID getContentType()
getContentType
in interface ContentStream
ObjectID.cms_compressedData
("1.2..840.113549.1.9.16.1.9")public ObjectID getEncapsulatedContentType()
public int getVersion()
public AlgorithmID getCompressionAlgorithm()
public void setBlockSize(int blockSize)
blockSize
is smaller or equal to zero the
whole data is encoded as definite primitive octet string.
This method may be used for enforcing block encoding when wrapping the
CompressedData into a ContentInfo.
setBlockSize
in interface ContentStream
blockSize
- for defining the encoding scheme and setting the octet
string component length, if positivepublic int getBlockSize()
blockSize
is smaller or equal to zero the
whole data is encoded as definite primitive octet string.
getBlockSize
in interface ContentStream
public int getMode()
IMPLICIT
or EXPLICIT
public java.io.InputStream getInputStream() throws java.security.NoSuchAlgorithmException, java.io.IOException
Attention! The stream only may be read once.
When having created a new CompressedDataStream
object to
be encoded to a stream, this method should only be called in EXPLICT
mode to get and read away the compressed content to be transmitted by other means.
In IMPLICT
mode this method shall not be called at all since
the compressed content has to be included in the CompressedData message (and
therefore should not be read "away").
When having decoded and parsed a received CompressedDataStream
object
coming from some stream, this method may be used for obtaining the raw (decompressed)
content.
java.security.NoSuchAlgorithmException
- if the compression algorithm is not supported
java.io.IOException
- if an I/O error occurspublic void setInputStream(java.io.InputStream is) throws java.security.NoSuchAlgorithmException, java.io.IOException
CompressedDataStream
object to
be encoded to a stream, this method may be used to supply the content
to be compressed.
CompressedDataStream
object
coming from some stream, this method may be used for supplying the compressed
content transmitted by other means (EXPLICIT mode).
is
- an input stream supplying the content to be compressed/decompressed
java.security.NoSuchAlgorithmException
- if the compression algorithm is not supported
java.io.IOException
- if an I/O error occurspublic ASN1Object toASN1Object() throws CMSException
toASN1Object
in interface ContentStream
CMSException
- if the ASN1Object could not be createdprotected ASN1Object toASN1Object(int blockSize) throws CMSException
blockSize
- the block size defining the encoding scheme - and specifying the
length of each primitive encoded octet string component, if positive
CMSException
- if the ASN1Object could not be createdpublic void writeTo(java.io.OutputStream os) throws java.io.IOException
os
- the output stream to which this CompressedData shall be written
java.io.IOException
- if an IOException occurs while writing to the streampublic void writeTo(java.io.OutputStream os, int blockSize) throws java.io.IOException
0x24 0x80 0x04 <blocksize> <data> 0x04 <blocksize> <data> 0x04 <blocksize> <data> ... 0x00 0x00If the block size is not positive, the whole inherent data is encoded as one single primitive definite octet string:
0x04 <length> <data>
os
- the output stream to which this CompressedData shall be writtenblockSize
- the block size defining the encoding scheme - and specifying the
length of each primitive encoded octet string component, if positive
java.io.IOException
- if an error occurs during writing the objectpublic java.lang.String toString()
CompressedData
object.
toString
in class java.lang.Object
public java.lang.String toString(boolean detailed)
CompressedData
object.
toString
in interface ContentStream
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 |