Search in sources :

Example 11 with PushbackInputStream

use of java.io.PushbackInputStream in project robovm by robovm.

the class CertificateFactory method engineGenerateCertificate.

/**
     * Generates a certificate object and initializes it with the data
     * read from the input stream inStream.
     */
public java.security.cert.Certificate engineGenerateCertificate(InputStream in) throws CertificateException {
    if (currentStream == null) {
        currentStream = in;
        sData = null;
        sDataObjectCount = 0;
    } else if (// reset if input stream has changed
    currentStream != in) {
        currentStream = in;
        sData = null;
        sDataObjectCount = 0;
    }
    try {
        if (sData != null) {
            if (sDataObjectCount != sData.size()) {
                return getCertificate();
            } else {
                sData = null;
                sDataObjectCount = 0;
                return null;
            }
        }
        PushbackInputStream pis = new PushbackInputStream(in);
        int tag = pis.read();
        if (tag == -1) {
            return null;
        }
        pis.unread(tag);
        if (// assume ascii PEM encoded.
        tag != 0x30) {
            return readPEMCertificate(pis);
        } else {
            return readDERCertificate(new ASN1InputStream(pis));
        }
    } catch (Exception e) {
        throw new ExCertificateException(e);
    }
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) PushbackInputStream(java.io.PushbackInputStream) CertificateParsingException(java.security.cert.CertificateParsingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CRLException(java.security.cert.CRLException)

Example 12 with PushbackInputStream

use of java.io.PushbackInputStream in project robovm by robovm.

the class CertificateFactory method engineGenerateCRL.

/**
     * Generates a certificate revocation list (CRL) object and initializes
     * it with the data read from the input stream inStream.
     */
public CRL engineGenerateCRL(InputStream inStream) throws CRLException {
    if (currentCrlStream == null) {
        currentCrlStream = inStream;
        sCrlData = null;
        sCrlDataObjectCount = 0;
    } else if (// reset if input stream has changed
    currentCrlStream != inStream) {
        currentCrlStream = inStream;
        sCrlData = null;
        sCrlDataObjectCount = 0;
    }
    try {
        if (sCrlData != null) {
            if (sCrlDataObjectCount != sCrlData.size()) {
                return getCRL();
            } else {
                sCrlData = null;
                sCrlDataObjectCount = 0;
                return null;
            }
        }
        PushbackInputStream pis = new PushbackInputStream(inStream);
        int tag = pis.read();
        if (tag == -1) {
            return null;
        }
        pis.unread(tag);
        if (// assume ascii PEM encoded.
        tag != 0x30) {
            return readPEMCRL(pis);
        } else {
            // lazy evaluate to help processing of large CRLs
            return readDERCRL(new ASN1InputStream(pis, true));
        }
    } catch (CRLException e) {
        throw e;
    } catch (Exception e) {
        throw new CRLException(e.toString());
    }
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) PushbackInputStream(java.io.PushbackInputStream) CRLException(java.security.cert.CRLException) CertificateParsingException(java.security.cert.CertificateParsingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CRLException(java.security.cert.CRLException)

Example 13 with PushbackInputStream

use of java.io.PushbackInputStream in project robovm by robovm.

the class OpenSSLX509CertPath method fromPkcs7Encoding.

private static CertPath fromPkcs7Encoding(InputStream inStream) throws CertificateException {
    try {
        if (inStream == null || inStream.available() == 0) {
            return new OpenSSLX509CertPath(Collections.<X509Certificate>emptyList());
        }
    } catch (IOException e) {
        throw new CertificateException("Problem reading input stream", e);
    }
    final boolean markable = inStream.markSupported();
    if (markable) {
        inStream.mark(PUSHBACK_SIZE);
    }
    /* Attempt to see if this is a PKCS#7 bag. */
    final PushbackInputStream pbis = new PushbackInputStream(inStream, PUSHBACK_SIZE);
    try {
        final byte[] buffer = new byte[PKCS7_MARKER.length];
        final int len = pbis.read(buffer);
        if (len < 0) {
            /* No need to reset here. The stream was empty or EOF. */
            throw new ParsingException("inStream is empty");
        }
        pbis.unread(buffer, 0, len);
        if (len == PKCS7_MARKER.length && Arrays.equals(PKCS7_MARKER, buffer)) {
            return new OpenSSLX509CertPath(OpenSSLX509Certificate.fromPkcs7PemInputStream(pbis));
        }
        return new OpenSSLX509CertPath(OpenSSLX509Certificate.fromPkcs7DerInputStream(pbis));
    } catch (Exception e) {
        if (markable) {
            try {
                inStream.reset();
            } catch (IOException ignored) {
            }
        }
        throw new CertificateException(e);
    }
}
Also used : PushbackInputStream(java.io.PushbackInputStream) ParsingException(org.conscrypt.OpenSSLX509CertificateFactory.ParsingException) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) ParsingException(org.conscrypt.OpenSSLX509CertificateFactory.ParsingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 14 with PushbackInputStream

use of java.io.PushbackInputStream in project commons by twitter.

the class CompatibilityCodec method deserialize.

@Override
public T deserialize(InputStream source) throws IOException {
    final PushbackInputStream in = new PushbackInputStream(source, prefixLength);
    final byte[] prefix = readAtMostPrefix(in);
    in.unread(prefix);
    return (discriminator.apply(prefix) ? primaryCodec : secondaryCodec).deserialize(in);
}
Also used : PushbackInputStream(java.io.PushbackInputStream)

Example 15 with PushbackInputStream

use of java.io.PushbackInputStream in project reversehttp by tonyg.

the class HttpMessage method readFrom.

public boolean readFrom(InputStream s) {
    PushbackInputStream r = new PushbackInputStream(s);
    try {
        readFirstLine(r);
        readHeaders(r);
        return readBody(s);
    } catch (NumberFormatException nfe) {
        return false;
    } catch (IOException ioe) {
        return false;
    }
}
Also used : PushbackInputStream(java.io.PushbackInputStream) IOException(java.io.IOException)

Aggregations

PushbackInputStream (java.io.PushbackInputStream)72 IOException (java.io.IOException)40 ByteArrayInputStream (java.io.ByteArrayInputStream)12 InputStream (java.io.InputStream)12 FileInputStream (java.io.FileInputStream)6 CertificateException (java.security.cert.CertificateException)5 File (java.io.File)4 CRLException (java.security.cert.CRLException)4 CertificateParsingException (java.security.cert.CertificateParsingException)4 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)4 InputStreamReader (java.io.InputStreamReader)3 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)3 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Charset (java.nio.charset.Charset)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Attributes (java.util.jar.Attributes)2 JarEntry (java.util.jar.JarEntry)2