Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/pkix/src
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2013-11-30 10:21:02 +0400
committerDavid Hook <dgh@cryptoworkshop.com>2013-11-30 10:21:02 +0400
commit94e33603384de6baab9694fc11be7bfc1851569b (patch)
tree0786a67f5e3ee8d83623deb9ede2383cb11d1602 /pkix/src
parentb5b42f18bfd96c672c6eed15189bb9059fe091ee (diff)
compatibility files
Diffstat (limited to 'pkix/src')
-rw-r--r--pkix/src/main/j2me/org/bouncycastle/cms/CMSTypedStream.java85
1 files changed, 85 insertions, 0 deletions
diff --git a/pkix/src/main/j2me/org/bouncycastle/cms/CMSTypedStream.java b/pkix/src/main/j2me/org/bouncycastle/cms/CMSTypedStream.java
new file mode 100644
index 00000000..c05c5952
--- /dev/null
+++ b/pkix/src/main/j2me/org/bouncycastle/cms/CMSTypedStream.java
@@ -0,0 +1,85 @@
+package org.bouncycastle.cms;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.bouncycastle.asn1.ASN1ObjectIdentifier;
+import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
+import org.bouncycastle.util.io.Streams;
+
+public class CMSTypedStream
+{
+ private static final int BUF_SIZ = 32 * 1024;
+
+ private final ASN1ObjectIdentifier _oid;
+ private final InputStream _in;
+
+ public CMSTypedStream(
+ InputStream in)
+ {
+ this(PKCSObjectIdentifiers.data.getId(), in, BUF_SIZ);
+ }
+
+ public CMSTypedStream(
+ String oid,
+ InputStream in)
+ {
+ this(new ASN1ObjectIdentifier(oid), in, BUF_SIZ);
+ }
+
+ public CMSTypedStream(
+ String oid,
+ InputStream in,
+ int bufSize)
+ {
+ this(new ASN1ObjectIdentifier(oid), in, bufSize);
+ }
+
+ public CMSTypedStream(
+ ASN1ObjectIdentifier oid,
+ InputStream in)
+ {
+ this(oid, in, BUF_SIZ);
+ }
+
+ public CMSTypedStream(
+ ASN1ObjectIdentifier oid,
+ InputStream in,
+ int bufSize)
+ {
+ _oid = oid;
+ _in = new FullReaderStream(in);
+ }
+
+ public ASN1ObjectIdentifier getContentType()
+ {
+ return _oid;
+ }
+
+ public InputStream getContentStream()
+ {
+ return _in;
+ }
+
+ public void drain()
+ throws IOException
+ {
+ Streams.drain(_in);
+ _in.close();
+ }
+
+ private static class FullReaderStream extends FilterInputStream
+ {
+ FullReaderStream(InputStream in)
+ {
+ super(in);
+ }
+
+ public int read(byte[] buf, int off, int len) throws IOException
+ {
+ int totalRead = Streams.readFully(super.in, buf, off, len);
+ return totalRead > 0 ? totalRead : -1;
+ }
+ }
+}