Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.bouncycastle.jcajce.provider.asymmetric.x509;
 
 
 
 class PEMUtil
    private final String _header1;
    private final String _header2;
    private final String _footer1;
    private final String _footer2;
    PEMUtil(
        String type)
    {
         = "-----BEGIN " + type + "-----";
         = "-----BEGIN X509 " + type + "-----";
         = "-----END " + type + "-----";
         = "-----END X509 " + type + "-----";
    }
    private String readLine(
        InputStream in)
        throws IOException
    {
        int             c;
        StringBuffer l = new StringBuffer();
        do
        {
            while (((c = in.read()) != '\r') && c != '\n' && (c >= 0))
            {
                l.append((char)c);
            }
        }
        while (c >= 0 && l.length() == 0);
        if (c < 0)
        {
            return null;
        }
        return l.toString();
    }
        InputStream in)
        throws IOException
    {
        String line;
        StringBuffer pemBuf = new StringBuffer();
        while ((line = readLine(in)) != null)
        {
            if (line.startsWith() || line.startsWith())
            {
                break;
            }
        }
        while ((line = readLine(in)) != null)
        {
            if (line.startsWith() || line.startsWith())
            {
                break;
            }
            pemBuf.append(line);
        }
        if (pemBuf.length() != 0)
        {
            try
            {
                return ASN1Sequence.getInstance(Base64.decode(pemBuf.toString()));
            }
            catch (Exception e)
            {
                throw new IOException("malformed PEM data encountered");
            }
        }
        return null;
    }
New to GrepCode? Check out our FAQ X