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