Search in sources :

Example 46 with InputStreamReader

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

the class HashInputStreamTest method badChecksum_throwsIOException.

@Test
public void badChecksum_throwsIOException() throws Exception {
    thrown.expect(IOException.class);
    thrown.expectMessage("Checksum");
    assertThat(CharStreams.toString(new InputStreamReader(new HashInputStream(new ByteArrayInputStream("hello".getBytes(UTF_8)), Hashing.sha1(), HashCode.fromString("0000000000000000000000000000000000000000")), UTF_8))).isNull();
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 47 with InputStreamReader

use of java.io.InputStreamReader 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 48 with InputStreamReader

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

the class Loader method loadProperties.

/**
     * Loads from resources the default {@link Properties} of the specified platform name.
     * The resource must be at {@code "org/bytedeco/javacpp/properties/" + name + ".properties"}.
     *
     * @param name the platform name
     * @param defaults the fallback platform name (null == "generic")
     * @return the Properties from resources
     */
public static Properties loadProperties(String name, String defaults) {
    Properties p = new Properties();
    p.put("platform", name);
    p.put("platform.path.separator", File.pathSeparator);
    String s = System.mapLibraryName("/");
    int i = s.indexOf('/');
    p.put("platform.library.prefix", s.substring(0, i));
    p.put("platform.library.suffix", s.substring(i + 1));
    name = "properties/" + name + ".properties";
    InputStream is = Loader.class.getResourceAsStream(name);
    try {
        try {
            p.load(new InputStreamReader(is));
        } catch (NoSuchMethodError e) {
            p.load(is);
        }
    } catch (Exception e) {
        name = "properties/" + defaults + ".properties";
        InputStream is2 = Loader.class.getResourceAsStream(name);
        try {
            try {
                p.load(new InputStreamReader(is2));
            } catch (NoSuchMethodError e2) {
                p.load(is2);
            }
        } catch (Exception e2) {
        // give up and return defaults
        } finally {
            try {
                if (is2 != null) {
                    is2.close();
                }
            } catch (IOException ex) {
                logger.error("Unable to close resource : " + ex.getMessage());
            }
        }
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (IOException ex) {
            logger.error("Unable to close resource : " + ex.getMessage());
        }
    }
    return p;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 49 with InputStreamReader

use of java.io.InputStreamReader 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 50 with InputStreamReader

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

the class FrenchTokenizer method main.

/**
   * A fast, rule-based tokenizer for Modern Standard French.
   * Performs punctuation splitting and light tokenization by default.
   * <p>
   * Currently, this tokenizer does not do line splitting. It assumes that the input
   * file is delimited by the system line separator. The output will be equivalently
   * delimited.
   * </p>
   *
   * @param args
   */
public static void main(String[] args) {
    final Properties options = StringUtils.argsToProperties(args, argOptionDefs());
    if (options.containsKey("help")) {
        log.info(usage());
        return;
    }
    // Lexer options
    final TokenizerFactory<CoreLabel> tf = options.containsKey("ftb") ? FrenchTokenizer.ftbFactory() : FrenchTokenizer.factory();
    String orthoOptions = options.getProperty("options", "");
    // When called from this main method, split on newline. No options for
    // more granular sentence splitting.
    orthoOptions = orthoOptions.length() == 0 ? "tokenizeNLs" : orthoOptions + ",tokenizeNLs";
    tf.setOptions(orthoOptions);
    // Other options
    final String encoding = options.getProperty("encoding", "UTF-8");
    final boolean toLower = PropertiesUtils.getBool(options, "lowerCase", false);
    // Read the file from stdin
    int nLines = 0;
    int nTokens = 0;
    final long startTime = System.nanoTime();
    try {
        Tokenizer<CoreLabel> tokenizer = tf.getTokenizer(new InputStreamReader(System.in, encoding));
        boolean printSpace = false;
        while (tokenizer.hasNext()) {
            ++nTokens;
            String word = tokenizer.next().word();
            if (word.equals(FrenchLexer.NEWLINE_TOKEN)) {
                ++nLines;
                printSpace = false;
                System.out.println();
            } else {
                if (printSpace)
                    System.out.print(" ");
                String outputToken = toLower ? word.toLowerCase(Locale.FRENCH) : word;
                System.out.print(outputToken);
                printSpace = true;
            }
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    long elapsedTime = System.nanoTime() - startTime;
    double linesPerSec = (double) nLines / (elapsedTime / 1e9);
    System.err.printf("Done! Tokenized %d lines (%d tokens) at %.2f lines/sec%n", nLines, nTokens, linesPerSec);
}
Also used : CoreLabel(edu.stanford.nlp.ling.CoreLabel) InputStreamReader(java.io.InputStreamReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Properties(java.util.Properties)

Aggregations

InputStreamReader (java.io.InputStreamReader)4861 BufferedReader (java.io.BufferedReader)3402 IOException (java.io.IOException)2108 InputStream (java.io.InputStream)1272 FileInputStream (java.io.FileInputStream)857 URL (java.net.URL)605 ArrayList (java.util.ArrayList)559 Reader (java.io.Reader)518 File (java.io.File)514 Test (org.junit.Test)451 HttpURLConnection (java.net.HttpURLConnection)290 ByteArrayInputStream (java.io.ByteArrayInputStream)282 OutputStreamWriter (java.io.OutputStreamWriter)241 FileNotFoundException (java.io.FileNotFoundException)240 URLConnection (java.net.URLConnection)227 HashMap (java.util.HashMap)192 Socket (java.net.Socket)178 OutputStream (java.io.OutputStream)175 StringWriter (java.io.StringWriter)148 BufferedWriter (java.io.BufferedWriter)138