use of java.io.InputStreamReader in project watson by totemo.
the class LiteModWatson method getVersion.
// --------------------------------------------------------------------------
/**
* Read the mod version from the metadata.
*
* Also works in the Eclipse run configuration if the Ant build runs at least
* once to update res/litemod.json from build/litemod.template.json.
*
* @see com.mumfrey.liteloader.LiteMod#getVersion()
*/
@Override
public String getVersion() {
InputStream is = null;
try {
Gson gson = new Gson();
is = getLiteModJsonStream();
@SuppressWarnings("unchecked") Map<String, String> meta = gson.fromJson(new InputStreamReader(is), HashMap.class);
String version = meta.get("version");
if (version == null) {
version = "(missing version info)";
}
return version;
} catch (Exception ex) {
return "(error loading version)";
} finally {
if (is != null) {
try {
is.close();
} catch (Exception ex) {
}
}
}
}
use of java.io.InputStreamReader in project CoreNLP by stanfordnlp.
the class CtbDict method readCtbDict.
private void readCtbDict(String filename) throws IOException {
BufferedReader ctbDetectorReader = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "GB18030"));
String ctbDetectorLine;
ctb_pre_dict = Generics.newHashMap();
ctb_suf_dict = Generics.newHashMap();
while ((ctbDetectorLine = ctbDetectorReader.readLine()) != null) {
String[] fields = ctbDetectorLine.split(" ");
String tag = fields[0];
Set<String> pres = ctb_pre_dict.get(tag);
Set<String> sufs = ctb_suf_dict.get(tag);
if (pres == null) {
pres = Generics.newHashSet();
ctb_pre_dict.put(tag, pres);
}
pres.add(fields[1]);
if (sufs == null) {
sufs = Generics.newHashSet();
ctb_suf_dict.put(tag, sufs);
}
sufs.add(fields[2]);
}
}
use of java.io.InputStreamReader in project trie4j by takawitter.
the class GenHtml method main.
public static void main(String[] args) throws Exception {
String templ = null;
InputStream temps = GenHtml.class.getResourceAsStream("template.txt");
try {
templ = StreamUtil.readAsString(temps, "UTF-8");
} finally {
temps.close();
}
InputStream res = GenHtml.class.getResourceAsStream("result.txt");
try {
BufferedReader r = new BufferedReader(new InputStreamReader(res, "UTF-8"));
String line = null;
while ((line = r.readLine()) != null) {
String[] vals = line.split("[ ]+");
String name = vals[0].substring(0, vals[0].length() - 1).replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)").trim();
templ = templ.replaceAll("\\$\\{" + name + "\\.build\\}", String.format("%,d", Integer.valueOf(vals[1].replace(',', ' ').trim()))).replaceAll("\\$\\{" + name + "\\.contains\\}", String.format("%,d", Integer.valueOf(vals[2].replace(',', ' ').trim()))).replaceAll("\\$\\{" + name + "\\.mem\\}", String.format("%.1f", Integer.valueOf(vals[3].replace(',', ' ').trim()) / 1000000.0));
}
System.out.println(templ);
} finally {
res.close();
}
}
use of java.io.InputStreamReader in project trie4j by takawitter.
the class TestWikipedia method investigate.
private static void investigate(PatriciaTrie trie, int charCount) throws Exception {
System.out.println("-- count elements.");
final AtomicInteger count = new AtomicInteger();
trie.visit(new TrieVisitor() {
public void accept(Node node, int nest) {
if (node.isTerminate())
count.incrementAndGet();
}
});
System.out.println(count.intValue() + " elements.");
//*
System.out.println("-- list elements.");
final AtomicInteger n = new AtomicInteger();
final AtomicInteger l = new AtomicInteger();
final AtomicInteger ln = new AtomicInteger();
final AtomicInteger chars = new AtomicInteger();
trie.visit(new TrieVisitor() {
public void accept(Node node, int nest) {
if (node.isTerminate()) {
l.incrementAndGet();
} else {
n.incrementAndGet();
}
chars.addAndGet(node.getLetters().length);
}
});
System.out.println("node: " + n.intValue());
System.out.println("leaf: " + l.intValue());
System.out.println("label node: " + ln.intValue());
System.out.println("total char count: " + charCount);
System.out.println("total char count in trie: " + chars.intValue());
System.out.println("verifying trie...");
BufferedReader r = new BufferedReader(new InputStreamReader(// new GZIPInputStream(new FileInputStream("jawiki-20120220-all-titles-in-ns0.gz"))
new GZIPInputStream(new FileInputStream("enwiki-20120403-all-titles-in-ns0.gz")), CharsetUtil.newUTF8Decoder()));
long lap = System.currentTimeMillis();
int c = 0;
int sum = 0;
String word = null;
while ((word = r.readLine()) != null) {
if (c == maxCount)
break;
long d = System.currentTimeMillis();
boolean found = trie.contains(word);
sum += System.currentTimeMillis() - d;
if (!found) {
System.out.println("trie not contains [" + word + "]");
break;
}
if (c % 100000 == 0) {
System.out.println(c + " elements done.");
}
c++;
}
System.out.println("done in " + (System.currentTimeMillis() - lap) + " millis.");
System.out.println("contains time: " + sum + " millis.");
System.out.println(trie.getRoot().getChildren().length + "children in root");
final PatriciaTrie t = trie;
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(100000);
t.contains("hello");
} catch (InterruptedException e) {
}
}
}).start();
//*/
}
use of java.io.InputStreamReader in project torodb by torodb.
the class ConfigUtils method getPasswordFromPassFile.
private static String getPasswordFromPassFile(String passFile, String host, int port, String database, String user) throws FileNotFoundException, IOException {
File pass = new File(passFile);
if (pass.exists() && pass.canRead() && pass.isFile()) {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(pass), Charsets.UTF_8));
try {
String line;
int index = 0;
while ((line = br.readLine()) != null) {
index++;
String[] passChunks = line.split(":");
if (passChunks.length != 5) {
LOGGER.warn("Wrong format at line " + index + " of file " + passFile);
continue;
}
if ((passChunks[0].equals("*") || passChunks[0].equals(host)) && (passChunks[1].equals("*") || passChunks[1].equals(String.valueOf(port))) && (passChunks[2].equals("*") || passChunks[2].equals(database)) && (passChunks[3].equals("*") || passChunks[3].equals(user))) {
return passChunks[4];
}
}
br.close();
} finally {
br.close();
}
}
return null;
}
Aggregations