|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.OutputStream iaik.cms.DataOutputStream
public class DataOutputStream
This class represents an output stream based implementation of the CMS content
type Data
.
The Cryptographic Message Syntax (CMS) (RFC 5652)
specifies the Data
content type as base type without any cryptographic enhancements. Please note
that in difference to PKCS#7, CMS specifies the Data
as arbitrary octet strings, such
as ASCII text files; the interpretation is left to the application. From this
point of view the CMS type Data
itself does not have an ASN.1
respresentation in contrast to its PKCS#7 equivalent where Data
is defined as ASN.1 OCTET STRING:
Data ::= OCTET STRING
This class may be used for compatibility to PKCS#7 for allowing to
wrap Data objects into ContentInfo(Stream)s
. The data that is written (e.g. write(byte[])
)
to this stream is encoded as indefinite constructed OCTET STRING.
Each write operation creates an OCTET STRING block. If you want to encode the
OCTET STRING in blocks of equal size, you must feed in the data in blocks of this
size. For instance, the following program sample
// the stream to which to write the OCTET_STRING encoded data OutputStream resultStream = ...; // create a DataOutputStream DataOutputStream dataOut = new DataOutputStream(resultStream); byte[] data1 = { (byte)0x02, (byte)0x01, (byte)0xAB }; byte[] data2 = { (byte)0x02, (byte)0x23, (byte)0x7F }; byte[] data3 = { (byte)0x01, (byte)0xCA }; dataOut.write(data1); dataOut.write(data2); dataOut.write(data3); // finish indefinite length encoding and close stream dataOut.close();will give the following encoding:
0x24 0x80 0x04 0x02 0x01 0xAB 0x04 0x02 0x23 0x7F 0x04 0x01 0xCA 0x00 0x00To, for instance, encode data read from an input stream in OCTET STRING blocks of size 2048 do something like, e.g.:
// the input stream from which to read the data to be encoded as OCTET STRING InputStream is = ...; // the stream to which to write the OCTET_STRING encoded data OutputStream resultStream = ...; // create a DataOutputStream DataOutputStream dataOut = new DataOutputStream(resultStream); // the size of each OCTET STRING block int blockSize = 2048; // copy data byte[] buffer = new byte[blockSize]; int bytesRead; while ((bytesRead = is.read(buffer)) != -1) { dataOut.write(buffer, 0, bytesRead); } // finish indefinite length encoding and close stream dataOut.close();This class is not thread-safe. Use a separate DataOutputStream for each data you want to encode as OCTET STRING.
ContentInfoOutputStream
Constructor Summary | |
---|---|
DataOutputStream(java.io.OutputStream out)
Creates a new DataOutputStream for writing data encoded as OCTET STRING to the specified output stream. |
|
DataOutputStream(java.io.OutputStream out,
boolean passThroughClose)
Creates a new DataOutputStream for writing data encoded as OCTET STRING to the specified output stream. |
Method Summary | |
---|---|
void |
close()
Closes the OCTET STRING, i.e. write the trailing 0x00,0x00 end-mark of the constructed OCTET STRING. |
void |
flush()
Flushes any internal data and calls flush of the underlying stream. |
void |
write(byte[] b)
Writes one OCTET STRING block of the constructed OCTET STRING. |
void |
write(byte[] b,
int off,
int len)
Writes one OCTET STRING block of the constructed OCTET STRING. |
void |
write(int b)
Writes one OCTET STRING block of the constructed OCTET STRING. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DataOutputStream(java.io.OutputStream out)
write(byte[])
) to this stream is encoded as indefinite constructed
OCTET STRING. Each write operation creates an OCTET STRING block. If you
want to encode the OCTET STRING in blocks of equal size, you must feed in
the data in blocks of this size.
This stream will pass through close
calls.
out
- The stream for writing the encoded data.public DataOutputStream(java.io.OutputStream out, boolean passThroughClose)
write(byte[])
) to this stream is encoded as indefinite constructed
OCTET STRING. Each write operation creates an OCTET STRING block. If you
want to encode the OCTET STRING in blocks of equal size, you must feed in
the data in blocks of this size.
out
- The stream for writing the encoded data.passThroughClose
- if true
, calls to close()
will be passed through to out
.Method Detail |
---|
public void write(byte[] b, int off, int len) throws java.io.IOException
write
in class java.io.OutputStream
b
- The data.off
- The start offset in the data.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.
java.io.IOException
- If an I/O error occurs.public void write(int b) throws java.io.IOException
write
in class java.io.OutputStream
b
- The data.
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
|
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 |