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;
}
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;
}
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();
}
}
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();
}
}
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--;
}
}
Aggregations