Search in sources :

Example 51 with BufferedReader

use of java.io.BufferedReader in project bazel by bazelbuild.

the class ResourceUsageAnalyzer method parseResourceTxtFile.

private void parseResourceTxtFile(Path rTxt, Set<String> resourcePackages) throws IOException {
    BufferedReader reader = java.nio.file.Files.newBufferedReader(rTxt, UTF_8);
    String line;
    while ((line = reader.readLine()) != null) {
        String[] tokens = line.split(" ");
        ResourceType type = ResourceType.getEnum(tokens[1]);
        for (String resourcePackage : resourcePackages) {
            String owner = resourcePackage.replace('.', '/') + "/R$" + type.getName();
            Pair<ResourceType, Map<String, String>> pair = resourceObfuscation.get(owner);
            if (pair == null) {
                Map<String, String> nameMap = Maps.newHashMap();
                pair = Pair.of(type, nameMap);
            }
            resourceObfuscation.put(owner, pair);
        }
        if (type == ResourceType.STYLEABLE) {
            if (tokens[0].equals("int[]")) {
                model.addResource(ResourceType.DECLARE_STYLEABLE, tokens[2], null);
            } else {
            // TODO(jongerrish): Implement stripping of styleables.
            }
        } else {
            model.addResource(type, tokens[2], tokens[3]);
        }
    }
}
Also used : BufferedReader(java.io.BufferedReader) ResourceType(com.android.resources.ResourceType) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 52 with BufferedReader

use of java.io.BufferedReader in project bigbluebutton by bigbluebutton.

the class PEMReader method readFile.

/**
     * Read the PEM file and save the DER encoded octet
     * stream and begin marker.
     * 
     * @throws IOException
     */
protected void readFile() throws IOException {
    String line;
    BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
    try {
        while ((line = reader.readLine()) != null) {
            if (line.indexOf(BEGIN_MARKER) != -1) {
                beginMarker = line.trim();
                String endMarker = beginMarker.replace("BEGIN", "END");
                derBytes = readBytes(reader, endMarker);
                return;
            }
        }
        throw new IOException("Invalid PEM file: no begin marker");
    } finally {
        reader.close();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 53 with BufferedReader

use of java.io.BufferedReader in project Japid by branaway.

the class BranLayoutCompilerTest method testHop.

@Test
public void testHop() throws IOException {
    FileInputStream fis = new FileInputStream("JapidSample/app/japidviews/_layouts/Layout.html");
    InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
    BufferedReader br = new BufferedReader(isr);
    String src = "";
    for (String line = br.readLine(); line != null; line = br.readLine()) {
        src += line + "\n";
    }
    JapidTemplate bt = new JapidTemplate("tag/Layout.html", src);
    JapidAbstractCompiler cp = new JapidLayoutCompiler();
    cp.compile(bt);
    System.out.println(bt.javaSource);
}
Also used : JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) JapidLayoutCompiler(cn.bran.japid.compiler.JapidLayoutCompiler) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 54 with BufferedReader

use of java.io.BufferedReader in project jvm-tools by aragozin.

the class TraceLoader method parseFrames.

public static StackFrame[] parseFrames(String trace) {
    try {
        List<StackFrame> frames = new ArrayList<StackFrame>();
        BufferedReader br = new BufferedReader(new StringReader(trace));
        while (true) {
            String line = br.readLine();
            if (line == null) {
                break;
            }
            if (line.trim().length() > 0)
                frames.add(StackFrame.parseTrace(line.trim()));
        }
        return frames.toArray(new StackFrame[frames.size()]);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) IOException(java.io.IOException)

Example 55 with BufferedReader

use of java.io.BufferedReader in project CoreNLP by stanfordnlp.

the class LinearClassifierFactory method loadFromFilename.

/**
   * Given the path to a file representing the text based serialization of a
   * Linear Classifier, reconstitutes and returns that LinearClassifier.
   *
   * TODO: Leverage Index
   */
public static LinearClassifier<String, String> loadFromFilename(String file) {
    try {
        BufferedReader in = IOUtils.readerFromString(file);
        // Format: read indices first, weights, then thresholds
        Index<String> labelIndex = HashIndex.loadFromReader(in);
        Index<String> featureIndex = HashIndex.loadFromReader(in);
        double[][] weights = new double[featureIndex.size()][labelIndex.size()];
        int currLine = 1;
        String line = in.readLine();
        while (line != null && line.length() > 0) {
            String[] tuples = line.split(LinearClassifier.TEXT_SERIALIZATION_DELIMITER);
            if (tuples.length != 3) {
                throw new Exception("Error: incorrect number of tokens in weight specifier, line=" + currLine + " in file " + file);
            }
            currLine++;
            int feature = Integer.parseInt(tuples[0]);
            int label = Integer.parseInt(tuples[1]);
            double value = Double.parseDouble(tuples[2]);
            weights[feature][label] = value;
            line = in.readLine();
        }
        // First line in thresholds is the number of thresholds
        int numThresholds = Integer.parseInt(in.readLine());
        double[] thresholds = new double[numThresholds];
        int curr = 0;
        while ((line = in.readLine()) != null) {
            double tval = Double.parseDouble(line.trim());
            thresholds[curr++] = tval;
        }
        in.close();
        LinearClassifier<String, String> classifier = new LinearClassifier<>(weights, featureIndex, labelIndex);
        return classifier;
    } catch (Exception e) {
        throw new RuntimeIOException("Error in LinearClassifierFactory, loading from file=" + file, e);
    }
}
Also used : RuntimeIOException(edu.stanford.nlp.io.RuntimeIOException) BufferedReader(java.io.BufferedReader) RuntimeIOException(edu.stanford.nlp.io.RuntimeIOException)

Aggregations

BufferedReader (java.io.BufferedReader)5548 InputStreamReader (java.io.InputStreamReader)3430 IOException (java.io.IOException)2601 FileReader (java.io.FileReader)1283 File (java.io.File)942 InputStream (java.io.InputStream)845 ArrayList (java.util.ArrayList)766 FileInputStream (java.io.FileInputStream)694 URL (java.net.URL)526 Test (org.junit.Test)447 FileNotFoundException (java.io.FileNotFoundException)380 StringReader (java.io.StringReader)340 BufferedWriter (java.io.BufferedWriter)242 HashMap (java.util.HashMap)232 HttpURLConnection (java.net.HttpURLConnection)231 Matcher (java.util.regex.Matcher)223 OutputStreamWriter (java.io.OutputStreamWriter)212 PrintWriter (java.io.PrintWriter)208 URLConnection (java.net.URLConnection)208 Reader (java.io.Reader)201