Search in sources :

Example 86 with LineNumberReader

use of java.io.LineNumberReader in project JikesRVM by JikesRVM.

the class GenerateFromTemplate method buildIncludeRegion.

void buildIncludeRegion(Vector<Object> region) throws IOException {
    QuotedStringTokenizer pst = new QuotedStringTokenizer(params);
    if (!pst.hasMoreTokens())
        throw new IOException("Missing filename in INCLUDE");
    String file_name = pst.nextToken();
    LineNumberReader old_in = in;
    try {
        in = new LineNumberReader(new FileReader(file_name));
    } catch (java.io.FileNotFoundException e) {
        in = new LineNumberReader(new FileReader(inDir + file_name));
    }
    String inLine;
    // loop over strings in the file
    for (inLine = readLine(); inLine != null; inLine = readLine()) {
        if (isTemplateLine(inLine)) {
            region.addElement(buildTemplateRegion(inLine));
        } else {
            if (DEBUG)
                System.out.println("adding line to region :" + inLine);
            region.addElement(inLine);
        }
    }
    in = old_in;
}
Also used : FileReader(java.io.FileReader) IOException(java.io.IOException) LineNumberReader(java.io.LineNumberReader)

Example 87 with LineNumberReader

use of java.io.LineNumberReader in project keystore-explorer by kaikramer.

the class Pkcs10Util method loadCsr.

/**
 * Load a PKCS #10 CSR from the specified stream. The encoding of the CSR
 * may be PEM or DER.
 *
 * @param is
 *            Stream to load CSR from
 * @return The CSR
 * @throws IOException
 *             An I/O error occurred
 */
public static PKCS10CertificationRequest loadCsr(InputStream is) throws IOException {
    byte[] streamContents = ReadUtil.readFully(is);
    byte[] csrBytes = null;
    // Assume file is PEM until we find out otherwise
    try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(streamContents);
        InputStreamReader inputStreamReader = new InputStreamReader(byteArrayInputStream);
        LineNumberReader lnr = new LineNumberReader(inputStreamReader)) {
        String line = lnr.readLine();
        StringBuffer sbPem = new StringBuffer();
        if ((line != null) && ((line.equals(BEGIN_CSR_FORM_1) || line.equals(BEGIN_CSR_FORM_2)))) {
            while ((line = lnr.readLine()) != null) {
                if (line.equals(END_CSR_FORM_1) || line.equals(END_CSR_FORM_2)) {
                    csrBytes = Base64.decode(sbPem.toString());
                    break;
                }
                sbPem.append(line);
            }
        }
    }
    // Not PEM - must be DER encoded
    if (csrBytes == null) {
        csrBytes = streamContents;
    }
    PKCS10CertificationRequest csr = new PKCS10CertificationRequest(csrBytes);
    return csr;
}
Also used : PKCS10CertificationRequest(org.bouncycastle.pkcs.PKCS10CertificationRequest) JcaPKCS10CertificationRequest(org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) LineNumberReader(java.io.LineNumberReader)

Example 88 with LineNumberReader

use of java.io.LineNumberReader in project keystore-explorer by kaikramer.

the class JarSigner method getManifestMainAttrs.

/*
	 *  Get JAR file manifest's main attributes manifest as a string
	 */
private static String getManifestMainAttrs(JarFile jar) throws IOException {
    // Get full manifest content
    String manifestContent = getManifest(jar);
    try (StringReader stringReader = new StringReader(manifestContent);
        LineNumberReader lnr = new LineNumberReader(stringReader)) {
        StringBuilder sb = new StringBuilder();
        String line = null;
        // attributes
        while ((line = lnr.readLine()) != null) {
            if (line.trim().length() == 0) {
                break;
            }
            // Append attribute line
            sb.append(line);
            sb.append(CRLF);
        }
        return sb.toString();
    }
}
Also used : StringReader(java.io.StringReader) LineNumberReader(java.io.LineNumberReader)

Example 89 with LineNumberReader

use of java.io.LineNumberReader in project keystore-explorer by kaikramer.

the class JarSigner method getManifestEntryAttrs.

/*
	 *  Get JAR file manifest's attributes for a specified entry as a string
	 */
private static String getManifestEntryAttrs(JarFile jar, String entryName) throws IOException {
    // Get full manifest content
    String manifestContent = getManifest(jar);
    try (StringReader in = new StringReader(manifestContent);
        LineNumberReader lnr = new LineNumberReader(in)) {
        StringBuilder sb = new StringBuilder();
        String line = null;
        // First entry name attribute to match
        String entryNameAttr = createAttributeText(NAME_ATTR, entryName);
        // Only match on first 70 characters (max line length)
        if (entryNameAttr.length() > 70) {
            entryNameAttr = entryNameAttr.substring(0, 70);
        }
        // Keep reading and ignoring lines until entry is found - the end of the entry's attributes
        while ((line = lnr.readLine()) != null) {
            if (line.equals(entryNameAttr)) {
                // Found entry name attribute - append it
                sb.append(line);
                sb.append(CRLF);
                break;
            }
        }
        // attributes
        while ((line = lnr.readLine()) != null) {
            if (line.trim().length() == 0) {
                break;
            }
            // Append another entry attribute line
            sb.append(line);
            sb.append(CRLF);
        }
        return sb.toString();
    }
}
Also used : StringReader(java.io.StringReader) LineNumberReader(java.io.LineNumberReader)

Example 90 with LineNumberReader

use of java.io.LineNumberReader in project keystore-explorer by kaikramer.

the class Asn1Dump method dumpHexClear.

private String dumpHexClear(byte[] der) throws IOException {
    try {
        indentLevel++;
        // Get hex/clear dump of value
        String hexClearDump = HexUtil.getHexClearDump(der);
        // Put indent at the start of each line of the dump
        LineNumberReader lnr = new LineNumberReader(new StringReader(hexClearDump));
        StringBuilder sb = new StringBuilder();
        String line = null;
        boolean firstLine = true;
        while ((line = lnr.readLine()) != null) {
            if (firstLine) {
                firstLine = false;
            } else {
                sb.append(NEWLINE);
            }
            sb.append(indentSequence.toString(indentLevel));
            sb.append(line);
        }
        lnr.close();
        return sb.toString();
    } finally {
        indentLevel--;
    }
}
Also used : StringReader(java.io.StringReader) DERNumericString(org.bouncycastle.asn1.DERNumericString) DERBitString(org.bouncycastle.asn1.DERBitString) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DERBMPString(org.bouncycastle.asn1.DERBMPString) DERGeneralString(org.bouncycastle.asn1.DERGeneralString) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DERT61String(org.bouncycastle.asn1.DERT61String) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERVisibleString(org.bouncycastle.asn1.DERVisibleString) ASN1String(org.bouncycastle.asn1.ASN1String) DERUniversalString(org.bouncycastle.asn1.DERUniversalString) LineNumberReader(java.io.LineNumberReader)

Aggregations

LineNumberReader (java.io.LineNumberReader)401 IOException (java.io.IOException)203 InputStreamReader (java.io.InputStreamReader)167 FileReader (java.io.FileReader)102 File (java.io.File)79 InputStream (java.io.InputStream)64 StringReader (java.io.StringReader)64 ArrayList (java.util.ArrayList)54 FileInputStream (java.io.FileInputStream)33 BufferedReader (java.io.BufferedReader)27 PrintWriter (java.io.PrintWriter)25 HashMap (java.util.HashMap)22 FileNotFoundException (java.io.FileNotFoundException)20 BufferedWriter (java.io.BufferedWriter)16 FileWriter (java.io.FileWriter)16 Pattern (java.util.regex.Pattern)16 Test (org.junit.jupiter.api.Test)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 Reader (java.io.Reader)14