Here are the examples of the java api class java.io.BufferedReader taken from open source projects.
1. BufferedReaderTest#leavesMark()
Project: teavm
File: BufferedReaderTest.java
File: BufferedReaderTest.java
@Test public void leavesMark() throws IOException { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 1000; ++i) { sb.append((char) i); } BufferedReader reader = new BufferedReader(new StringReader(sb.toString()), 100); reader.skip(50); reader.mark(70); reader.skip(60); reader.reset(); char[] buffer = new char[150]; int charsRead = reader.read(buffer); assertEquals(150, charsRead); assertEquals(50, buffer[0]); assertEquals(51, buffer[1]); assertEquals(199, buffer[149]); }
2. MiscUtils#printProcess()
Project: bytecode-viewer
File: MiscUtils.java
File: MiscUtils.java
public static void printProcess(Process process) throws Exception { //Read out dir output InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { System.out.println(line); } br.close(); is = process.getErrorStream(); isr = new InputStreamReader(is); br = new BufferedReader(isr); while ((line = br.readLine()) != null) { System.out.println(line); } br.close(); }
3. IT#run()
Project: Duke
File: IT.java
File: IT.java
private Result run(String cmd) throws IOException { Process p = Runtime.getRuntime().exec(cmd); StringBuilder tmp = new StringBuilder(); BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = r.readLine()) != null) tmp.append(line + " "); r.close(); r = new BufferedReader(new InputStreamReader(p.getErrorStream())); while ((line = r.readLine()) != null) tmp.append(line + " "); r.close(); try { // we wait for process to exit p.waitFor(); } catch (InterruptedException e) { } return new Result(tmp.toString(), p.exitValue()); }
4. ITDoggedCubeBuilderTest#fileCompare()
Project: kylin
File: ITDoggedCubeBuilderTest.java
File: ITDoggedCubeBuilderTest.java
private void fileCompare(File file, File file2) throws IOException { BufferedReader r1 = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); BufferedReader r2 = new BufferedReader(new InputStreamReader(new FileInputStream(file2), "UTF-8")); String line1, line2; do { line1 = r1.readLine(); line2 = r2.readLine(); assertEquals(line1, line2); } while (line1 != null || line2 != null); r1.close(); r2.close(); }
5. GZIPcompress#main()
Project: java-core-learning-example
File: GZIPcompress.java
File: GZIPcompress.java
public static void main(String[] args) throws IOException { // ?Reader??? BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("data.gz"), "UTF-8")); // ??????????????? BufferedOutputStream out = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream("data.gz"))); System.out.println("Writing File ??"); int c; while ((c = in.read()) > 0) out.write(String.valueOf((char) c).getBytes("UTF-8")); in.close(); out.close(); System.out.println("Reading File ??"); // ?????????? BufferedReader in2 = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream("data.gz")), // encoding question "UTF-8")); String s; while ((s = in2.readLine()) != null) System.out.println(s); in2.close(); }
6. AbstractPacketTest#testToString()
Project: pcap4j
File: AbstractPacketTest.java
File: AbstractPacketTest.java
@Test public void testToString() throws Exception { FileReader fr = new FileReader(new StringBuilder().append(resourceDirPath).append("/").append(getClass().getSimpleName()).append(".log").toString()); BufferedReader fbr = new BufferedReader(fr); StringReader sr = new StringReader(getPacket().toString()); BufferedReader sbr = new BufferedReader(sr); String line; while ((line = fbr.readLine()) != null) { assertEquals(line, sbr.readLine()); } assertNull(sbr.readLine()); fbr.close(); fr.close(); sr.close(); sbr.close(); }
7. TestInputOutputFormat#testReadWrite()
Project: parquet-mr
File: TestInputOutputFormat.java
File: TestInputOutputFormat.java
private void testReadWrite(CompressionCodecName codec, Map<String, String> conf) throws IOException, ClassNotFoundException, InterruptedException { runMapReduceJob(codec, conf); final BufferedReader in = new BufferedReader(new FileReader(new File(inputPath.toString()))); final BufferedReader out = new BufferedReader(new FileReader(new File(outputPath.toString(), "part-m-00000"))); String lineIn; String lineOut = null; int lineNumber = 0; while ((lineIn = in.readLine()) != null && (lineOut = out.readLine()) != null) { ++lineNumber; lineOut = lineOut.substring(lineOut.indexOf("\t") + 1); assertEquals("line " + lineNumber, lineIn, lineOut); } assertNull("line " + lineNumber, out.readLine()); assertNull("line " + lineNumber, lineIn); in.close(); out.close(); }
8. TestParamSubPreproc#compareResults()
Project: pig
File: TestParamSubPreproc.java
File: TestParamSubPreproc.java
private void compareResults(InputStream expected, InputStream result) throws IOException { BufferedReader inExpected = new BufferedReader(new InputStreamReader(expected)); BufferedReader inResult = new BufferedReader(new InputStreamReader(result)); String exLine; String resLine; int lineNum = 0; while (true) { lineNum++; exLine = inExpected.readLine(); resLine = inResult.readLine(); if (exLine == null || resLine == null) break; assertEquals("Command line parameter substitution failed. " + "Expected : " + exLine + " , but got : " + resLine + " in line num : " + lineNum, exLine.trim(), resLine.trim()); } if (!(exLine == null && resLine == null)) { fail("Command line parameter substitution failed. " + "Expected : " + exLine + " , but got : " + resLine + " in line num : " + lineNum); } inExpected.close(); inResult.close(); }
9. GraphBuilder_Popularity#readDataProperties()
Project: Web-Karma
File: GraphBuilder_Popularity.java
File: GraphBuilder_Popularity.java
private List<Triple> readDataProperties(String dataPropertiesFile) throws IOException { InputStream f; BufferedReader br; String line; String[] parts; List<Triple> triples = new ArrayList<Triple>(); f = new FileInputStream(dataPropertiesFile); br = new BufferedReader(new InputStreamReader(f, Charset.forName("UTF-8"))); while ((line = br.readLine()) != null) { parts = line.trim().split(","); if (parts == null || parts.length != 3) continue; Triple t = new Triple(parts[0].trim(), parts[1].trim(), Integer.parseInt(parts[2].trim())); triples.add(t); } // Done with the file br.close(); br = null; f = null; return triples; }
10. GraphBuilder_Popularity#readObjectProperties()
Project: Web-Karma
File: GraphBuilder_Popularity.java
File: GraphBuilder_Popularity.java
private List<Triple> readObjectProperties(String objectPropertiesFile) throws IOException { InputStream f; BufferedReader br; String line; String[] parts; List<Triple> triples = new ArrayList<Triple>(); f = new FileInputStream(objectPropertiesFile); br = new BufferedReader(new InputStreamReader(f, Charset.forName("UTF-8"))); while ((line = br.readLine()) != null) { parts = line.trim().split(","); if (parts == null || parts.length != 4) continue; Triple t = new Triple(parts[0].trim(), parts[1].trim(), parts[2].trim(), Integer.parseInt(parts[3].trim())); triples.add(t); } // Done with the file br.close(); br = null; f = null; return triples; }
11. AuditManager#getReviewInfo()
Project: spacewalk
File: AuditManager.java
File: AuditManager.java
/** * Retrieve the review info for a specified machine/time * @param machine The machine name * @param start The start time in ms from the epoch * @param end The end time in ms from the epoch * @throws IOException Throws when the audit review file is unreadable * @return An AuditReviewDto, possibly with review info set */ public static AuditReviewDto getReviewInfo(String machine, long start, long end) throws IOException { BufferedReader brdr; Date reviewedOn = null; String str, part1, reviewedBy = null; String[] revInfo; part1 = machine + "," + (start / 1000) + "," + (end / 1000) + ","; brdr = new BufferedReader(new FileReader(reviewFile)); while ((str = brdr.readLine()) != null) { if (str.startsWith(part1)) { revInfo = str.split(","); reviewedBy = revInfo[3]; reviewedOn = new Date(Long.parseLong(revInfo[4]) * 1000); break; } } brdr.close(); return new AuditReviewDto(machine, new Date(start), new Date(end), reviewedBy, reviewedOn); }
12. HttpNegotiateServer#test6578647()
Project: jdk7u-jdk
File: HttpNegotiateServer.java
File: HttpNegotiateServer.java
static void test6578647() throws Exception { BufferedReader reader; java.net.Authenticator.setDefault(new KnowAllAuthenticator()); reader = new BufferedReader(new InputStreamReader(webUrl.openConnection().getInputStream())); if (!reader.readLine().equals(CONTENT)) { throw new RuntimeException("Bad content"); } reader = new BufferedReader(new InputStreamReader(proxyUrl.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_HOST, proxyPort))).getInputStream())); if (!reader.readLine().equals(CONTENT)) { throw new RuntimeException("Bad content"); } }
13. ExternalSortTest#testMergeSortedFilesDistinct()
Project: jackrabbit-oak
File: ExternalSortTest.java
File: ExternalSortTest.java
@Test public void testMergeSortedFilesDistinct() throws Exception { String line; List<String> result; BufferedReader bf; Comparator<String> cmp = new Comparator<String>() { @Override public int compare(String o1, String o2) { return o1.compareTo(o2); } }; File out = folder.newFile(); ExternalSort.mergeSortedFiles(this.fileList, out, cmp, Charset.defaultCharset(), true); bf = new BufferedReader(new FileReader(out)); result = new ArrayList<String>(); while ((line = bf.readLine()) != null) { result.add(line); } bf.close(); assertArrayEquals(Arrays.toString(result.toArray()), EXPECTED_MERGE_DISTINCT_RESULTS, result.toArray()); }
14. ExternalSortTest#testMergeSortedFiles()
Project: jackrabbit-oak
File: ExternalSortTest.java
File: ExternalSortTest.java
@Test public void testMergeSortedFiles() throws Exception { String line; List<String> result; BufferedReader bf; Comparator<String> cmp = new Comparator<String>() { @Override public int compare(String o1, String o2) { return o1.compareTo(o2); } }; File out = folder.newFile(); ExternalSort.mergeSortedFiles(this.fileList, out, cmp, Charset.defaultCharset(), false); bf = new BufferedReader(new FileReader(out)); result = new ArrayList<String>(); while ((line = bf.readLine()) != null) { result.add(line); } bf.close(); assertArrayEquals(Arrays.toString(result.toArray()), EXPECTED_MERGE_RESULTS, result.toArray()); }
15. HttpNegotiateServer#test6578647()
Project: openjdk
File: HttpNegotiateServer.java
File: HttpNegotiateServer.java
static void test6578647() throws Exception { BufferedReader reader; java.net.Authenticator.setDefault(new KnowAllAuthenticator()); reader = new BufferedReader(new InputStreamReader(webUrl.openConnection().getInputStream())); if (!reader.readLine().equals(CONTENT)) { throw new RuntimeException("Bad content"); } reader = new BufferedReader(new InputStreamReader(proxyUrl.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_HOST, proxyPort))).getInputStream())); if (!reader.readLine().equals(CONTENT)) { throw new RuntimeException("Bad content"); } }
16. ReTokenizeFile#readFile()
Project: lenya
File: ReTokenizeFile.java
File: ReTokenizeFile.java
/** * reads a file in the specified encoding. * @param file the file to read. * @param encoding the file encoding * @return the content of the file. * @throws FileNotFoundException if the file does not exists. * @throws IOException if something else went wrong. */ protected String readFile(File file, Charset charset) throws FileNotFoundException, IOException { FileInputStream inputFile = new FileInputStream(file); InputStreamReader inputStream; if (charset != null) { inputStream = new InputStreamReader(inputFile, charset); } else { inputStream = new InputStreamReader(inputFile); } BufferedReader bufferReader = new BufferedReader(inputStream); StringBuffer buffer = new StringBuffer(); String line = ""; while (bufferReader.ready()) { line = bufferReader.readLine(); buffer.append(line); } bufferReader.close(); inputStream.close(); inputFile.close(); return buffer.toString(); }
17. echo#echoTCP()
Project: commons-net
File: echo.java
File: echo.java
public static final void echoTCP(String host) throws IOException { EchoTCPClient client = new EchoTCPClient(); BufferedReader input, echoInput; PrintWriter echoOutput; String line; // We want to timeout if a response takes longer than 60 seconds client.setDefaultTimeout(60000); client.connect(host); System.out.println("Connected to " + host + "."); input = new BufferedReader(new InputStreamReader(System.in)); echoOutput = new PrintWriter(new OutputStreamWriter(client.getOutputStream()), true); echoInput = new BufferedReader(new InputStreamReader(client.getInputStream())); while ((line = input.readLine()) != null) { echoOutput.println(line); System.out.println(echoInput.readLine()); } client.disconnect(); }
18. TextFile#readAllLines()
Project: hapi-fhir
File: TextFile.java
File: TextFile.java
public static List<String> readAllLines(String path) throws IOException { List<String> result = new ArrayList<String>(); File file = new CSFile(path); BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); while (reader.ready()) result.add(reader.readLine()); reader.close(); return result; }
19. WordGraph#read()
Project: fnlp
File: WordGraph.java
File: WordGraph.java
public void read(String path) throws IOException { BufferedReader bfr; bfr = new BufferedReader(new InputStreamReader(new FileInputStream(path), "utf8")); String line = null; while ((line = bfr.readLine()) != null) { if (line.length() == 0) continue; String[] toks = line.split("\\s+"); WordRelationEnum rel = WordRelationEnum.getWithName(toks[0]); if (toks.length < 2) continue; addRel(rel, Arrays.copyOfRange(toks, 1, toks.length)); } bfr.close(); }
20. SeqEval#readOOV()
Project: fnlp
File: SeqEval.java
File: SeqEval.java
public HashSet<String> readOOV(String path) throws IOException { dict = new HashSet<String>(); BufferedReader bfr; bfr = new BufferedReader(new InputStreamReader(new FileInputStream(path), "utf8")); String line = null; while ((line = bfr.readLine()) != null) { if (line.length() == 0) continue; dict.add(line); } bfr.close(); return dict; }
21. ProcessCorpus#processLabeledData()
Project: fnlp
File: ProcessCorpus.java
File: ProcessCorpus.java
public static void processLabeledData(String input, String output) throws Exception { FileInputStream is = new FileInputStream(input); //skip BOM is.skip(3); BufferedReader r = new BufferedReader(new InputStreamReader(is, "utf8")); OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(output), "utf8"); while (true) { String sent = r.readLine(); if (null == sent) break; String s = Tags.genSegSequence(sent, delimer, 4); w.write(s); } r.close(); w.close(); }
22. ProcessCorpus#processUnLabeledData()
Project: fnlp
File: ProcessCorpus.java
File: ProcessCorpus.java
public static void processUnLabeledData(String input, String output) throws Exception { FileInputStream is = new FileInputStream(input); // is.skip(3); //skip BOM BufferedReader r = new BufferedReader(new InputStreamReader(is, "utf8")); OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(output), "utf8"); while (true) { String sent = r.readLine(); if (sent == null) break; String s = Tags.genSegSequence(sent, delimer, 4); w.write(s); } w.close(); r.close(); }
23. BatchComment#main()
Project: fnlp
File: BatchComment.java
File: BatchComment.java
public static void main(String[] args) throws IOException { String comFile = "PageHeader.txt"; BufferedReader cf = new BufferedReader(new InputStreamReader(new FileInputStream(comFile), "UTF-8")); String line = null; StringBuilder sb = new StringBuilder(); sb.append("/**\n"); while ((line = cf.readLine()) != null) { sb.append("* ").append(line).append("\n"); } sb.append("*/\n"); cf.close(); String comments = sb.toString(); File f = new File("./fnlp-core/"); commentFile(f, comments); System.out.print(count); }
24. MyFiles#conver()
Project: fnlp
File: MyFiles.java
File: MyFiles.java
/** * ?????? * @param infile * @param outfile * @param enc1 * @param enc2 * @throws IOException */ public static void conver(String infile, String outfile, String enc1, String enc2) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(infile), enc1)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfile), enc2)); String line = null; while ((line = in.readLine()) != null) { line = line.trim(); if (line.length() == 0) continue; out.write(line); out.newLine(); } in.close(); out.close(); }
25. MyCollection#loadList()
Project: fnlp
File: MyCollection.java
File: MyCollection.java
/** * ?????????? * @param file * @param delim ??? * @return * @throws IOException */ public static ArrayList<String> loadList(String file, String delim) throws IOException { ArrayList<String> list = new ArrayList<String>(); BufferedReader bfr = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf8")); String line = null; while ((line = bfr.readLine()) != null) { if (line.length() == 0) continue; if (delim != null) { String[] toks = line.split(delim); for (String t : toks) { list.add(t); } } else { list.add(line); } } bfr.close(); return list; }
26. MyCollection#loadTStringFloatMap()
Project: fnlp
File: MyCollection.java
File: MyCollection.java
public static TObjectFloatHashMap<String> loadTStringFloatMap(String path) throws IOException { TObjectFloatHashMap<String> dict = new TObjectFloatHashMap<String>(); BufferedReader bfr = new BufferedReader(new InputStreamReader(new FileInputStream(path), "utf8")); String line = null; while ((line = bfr.readLine()) != null) { if (line.length() == 0) continue; int idx = line.lastIndexOf("\t"); dict.put(line.substring(0, idx), Float.parseFloat(line.substring(idx + 1))); } bfr.close(); return dict; }
27. MyCollection#loadTSet()
Project: fnlp
File: MyCollection.java
File: MyCollection.java
/** * ?????????? * @param path * @param b true,???????;false: ??????? * @return * @throws IOException */ public static THashSet<String> loadTSet(String path, boolean b) throws IOException { THashSet<String> dict = new THashSet<String>(); BufferedReader bfr; try { bfr = new BufferedReader(new InputStreamReader(new FileInputStream(path), "utf8")); } catch (FileNotFoundException e) { System.out.print("??????" + path); return dict; } String line = null; while ((line = bfr.readLine()) != null) { if (line.length() == 0) continue; if (b) dict.add(line); else { String[] toks = line.split("\\s+"); for (String tok : toks) dict.add(tok); } } bfr.close(); return dict; }
28. CharClassDictionary#load()
Project: fnlp
File: CharClassDictionary.java
File: CharClassDictionary.java
public void load(String path, String tag) throws Exception { if (path == null) return; BufferedReader bfr; bfr = new BufferedReader(new InputStreamReader(new FileInputStream(path), "utf8")); String line = null; while ((line = bfr.readLine()) != null) { if (line.length() == 0) continue; int len = line.length(); dict.add(line.charAt(0)); if (len > 1) { for (int i = 1; i < len - 1; i++) { dict.add(line.charAt(i)); } dict.add(line.charAt(len - 1)); } } name = tag; }
29. WordSimilarity#gramString()
Project: fnlp
File: WordSimilarity.java
File: WordSimilarity.java
public void gramString(String inputpath) throws IOException { initHashSet(); BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(inputpath), "UTF-8")); String s; int count = 0; while ((s = reader.readLine()) != null) { if (++count % 100000 == 0) System.out.println(count); gramPerString(s); } reader.close(); System.out.println("Finished load file"); }
30. WordSimilarity#countAllC()
Project: fnlp
File: WordSimilarity.java
File: WordSimilarity.java
private void countAllC(String inputpath) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(inputpath), "UTF-8")); String s; while ((s = reader.readLine()) != null) { for (int i = 0; i < s.length(); i++) { allC.add(String.valueOf(s.charAt(i))); } } reader.close(); set2List(); System.out.println("Finished count all character"); System.out.println("word size: " + word.size()); }
31. KMeansWordCluster#cluster()
Project: fnlp
File: KMeansWordCluster.java
File: KMeansWordCluster.java
public void cluster() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(trainPath), "UTF-8")); String s; int n = 0; while ((s = br.readLine()) != null) { ArrayList<TrainInstance> trainData = genFeatures(s); clusterList(trainData); printTerminal(n, 10000, "cluster line"); if ((n + 1) % 10000 == 0) saveObject("tmpdata/classCenterTemp", classCenter); n++; } br.close(); updateAverageCenter(); }
32. KMeansWordCluster#initCluster()
Project: fnlp
File: KMeansWordCluster.java
File: KMeansWordCluster.java
private void initCluster() throws IOException { initVector(); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(trainPath), "UTF-8")); String s; int n = 0; while ((s = br.readLine()) != null) { ArrayList<TrainInstance> trainData = genFeatures(s); initAddInstanceList(trainData); printTerminal(n, 10000, "init line"); n++; } br.close(); normalClassCenter(); initBaseDist(); }
33. KMeansWordCluster#readTemplete()
Project: fnlp
File: KMeansWordCluster.java
File: KMeansWordCluster.java
private void readTemplete(String path) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8")); String s; while ((s = br.readLine()) != null) { String[] str = s.split(","); int[] fea = new int[str.length]; for (int i = 0; i < fea.length; i++) { int id = 0; try { id = Integer.parseInt(str[i]); } catch (Exception e) { e.printStackTrace(); } fea[i] = id; } template.add(fea); } setLongestTemplate(); br.close(); System.out.println("Finish load template!"); }
34. KMeansWordCluster#readData()
Project: fnlp
File: KMeansWordCluster.java
File: KMeansWordCluster.java
void readData(String path) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8")); String s; int n = 0; while ((s = br.readLine()) != null) { genFeatures(s); printTerminal(n, 10000, "raad"); n++; } br.close(); System.out.println("Finish load training data!"); }
35. KMeansWordCluster#readClass()
Project: fnlp
File: KMeansWordCluster.java
File: KMeansWordCluster.java
private void readClass(String path) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8")); String s; int n = 0; while ((s = br.readLine()) != null) { String[] allc = s.split("\\s+"); add2Class(allc, n); n++; } br.close(); System.out.println("Finish load class!"); }
36. WordCount#count()
Project: fnlp
File: WordCount.java
File: WordCount.java
private void count(String ifile) throws IOException { BufferedReader bfr = new BufferedReader(new InputStreamReader(new FileInputStream(ifile), "utf8")); String line = null; int count = 0; while ((line = bfr.readLine()) != null) { if (line.length() == 0) continue; if (count % 1000 == 0) System.out.println(count); count++; if (seg != null) { String[] words = seg.tag2Array(line); for (String w : words) { add(w); } } } bfr.close(); }
37. Unlabeled#processUnLabeledData()
Project: fnlp
File: Unlabeled.java
File: Unlabeled.java
public static void processUnLabeledData(String input, String output) throws Exception { FileInputStream is = new FileInputStream(input); // is.skip(3); //skip BOM BufferedReader r = new BufferedReader(new InputStreamReader(is, "utf8")); OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(output), "utf8"); while (true) { String sent = r.readLine(); if (sent == null) break; String[][] ss = String2Sequence.genSequence(sent); String s = MyStrings.toString(ss, "\n"); w.write(s); } w.close(); r.close(); }
38. Tags#processFile()
Project: fnlp
File: Tags.java
File: Tags.java
/** * ?????????????? * @param infile * @param outfile * @throws IOException */ public static void processFile(String infile, String outfile, String delimer, int tagnum) throws IOException { BufferedReader in = new BufferedReader(new UnicodeReader(new FileInputStream(infile), "utf8")); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfile), "utf8")); String line = null; while ((line = in.readLine()) != null) { line = line.trim(); String newline; newline = genSegSequence(line, delimer, tagnum); out.write(newline); // out.newLine(); } in.close(); out.close(); }
39. DependentTreeProducter#ruleRead()
Project: fnlp
File: DependentTreeProducter.java
File: DependentTreeProducter.java
/** * ???? * @param rulePath ?????? * @throws IOException */ public void ruleRead(String rulePath) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(rulePath)), Charset.forName("GBK"))); String line = null; String[][] value = null; while ((line = br.readLine()) != null) { String[] tokens = line.split("\t"); String key = tokens[0]; String[] words = tokens[1].split(";"); value = new String[words.length][]; for (int j = 0; j < words.length; j++) { value[j] = words[j].split("\\s"); } ruleList.put(key, value); } br.close(); }
40. CTB2CONLL#clean()
Project: fnlp
File: CTB2CONLL.java
File: CTB2CONLL.java
/** * ?ctb????????????????????????????? * @param file ??? * @throws IOException * ??5:34:24 */ private static void clean(String file) throws IOException { StringBuffer sb = new StringBuffer(); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.forName("utf8"))); String str; while ((str = br.readLine()) != null) { if (str.length() != 0 && !str.trim().startsWith("<")) { if (str.equalsIgnoreCase("root")) continue; if (str.contains("</HEADER> ") || str.contains("</HEADLINE>")) continue; sb.append(str + "\n"); } } br.close(); Writer wr = new //???? OutputStreamWriter(//???? new FileOutputStream(new File(file)), //???? Charset.forName("gbk")); wr.write(sb.toString()); wr.close(); }
41. CharEnc#processLabeledData()
Project: fnlp
File: CharEnc.java
File: CharEnc.java
public static void processLabeledData(String input, String enc1, String enc2) throws Exception { FileInputStream is = new FileInputStream(input); // is.skip(3); //skip BOM BufferedReader r = new BufferedReader(new InputStreamReader(is, enc1)); OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(input + "." + enc2), enc2); while (true) { String sent = r.readLine(); if (null == sent) break; w.write(sent); w.write('\n'); } r.close(); w.close(); }
42. ChineseTrans#toHalfWidthFile()
Project: fnlp
File: ChineseTrans.java
File: ChineseTrans.java
/** * ???????????? * @param infile * @param outfile * @throws IOException */ public static void toHalfWidthFile(String infile, String outfile) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(infile), "utf8")); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfile), "utf8")); String line = null; while ((line = in.readLine()) != null) { line = line.trim(); if (line.length() == 0) continue; line = toHalfWidth(line); out.write(line); out.newLine(); } in.close(); out.close(); }
43. TestFlumeShell#testSaveConfigCommand()
Project: flume
File: TestFlumeShell.java
File: TestFlumeShell.java
/** * Create a master, connect via shell, create some logical nodes, save the * config for the node and check if the output looks as expected. */ @Test public void testSaveConfigCommand() throws IOException { FlumeShell sh = new FlumeShell(); long retval; retval = sh.executeLine("connect localhost:" + FlumeConfiguration.DEFAULT_ADMIN_PORT); assertEquals(0, retval); retval = sh.executeLine("exec config foo 'null' 'console'"); assertEquals(0, retval); File saveFile = FileUtil.createTempFile("test-flume", ""); saveFile.delete(); saveFile.deleteOnExit(); retval = sh.executeLine("exec save '" + saveFile.getAbsolutePath() + "'"); assertEquals(0, retval); BufferedReader in = new BufferedReader(new FileReader(saveFile)); assertEquals("foo : null | console;", in.readLine()); assertNull(in.readLine()); in.close(); }
44. LoggerTest#testLogSecondLineInSameFile()
Project: fitnesse
File: LoggerTest.java
File: LoggerTest.java
@Test public void testLogSecondLineInSameFile() throws Exception { l.log(ld); LogData ld2 = new LogData("newHost", ld.time, ld.requestLine, ld.status, ld.size, ld.username); l.log(ld2); File dir = l.getDirectory(); File file = new File(dir, filename); BufferedReader br = new BufferedReader(new FileReader(file)); assertEquals(logLine, br.readLine()); assertEquals("newHost - - [06/Mar/2003:13:42:05 -0100] \"request\" 42 666", br.readLine()); assertTrue(br.readLine() == null); br.close(); }
45. TestYahooDownload#testYahooDownloadCSV()
Project: encog-java-core
File: TestYahooDownload.java
File: TestYahooDownload.java
public void testYahooDownloadCSV() throws IOException { YahooDownload yahoo = new YahooDownload(); yahoo.setPercision(2); yahoo.loadAllData("yhoo", new File("test.txt"), CSVFormat.ENGLISH, new GregorianCalendar(2000, 00, 01).getTime(), new GregorianCalendar(2000, 00, 10).getTime()); BufferedReader tr = new BufferedReader(new FileReader("test.txt")); Assert.assertEquals("date,time,open price,high price,low price,close price,volume,adjusted price", tr.readLine()); Assert.assertEquals("20000110,0,432.5,451.25,420,436.06,61022400,109.02", tr.readLine()); Assert.assertEquals("20000107,0,366.75,408,363,407.25,48999600,101.81", tr.readLine()); Assert.assertEquals("20000106,0,406.25,413,361,368.19,71301200,92.05", tr.readLine()); Assert.assertEquals("20000105,0,430.5,431.12,402,410.5,83194800,102.62", tr.readLine()); tr.close(); }
46. TestSort#testSortNoHeaders()
Project: encog-java-core
File: TestSort.java
File: TestSort.java
public void testSortNoHeaders() throws IOException { generateTestFileHeadings(false); SortCSV norm = new SortCSV(); norm.getSortOrder().add(new SortedField(1, SortType.SortInteger, true)); norm.setProduceOutputHeaders(false); norm.process(INPUT_NAME, OUTPUT_NAME, false, CSVFormat.ENGLISH); BufferedReader tr = new BufferedReader(new FileReader(OUTPUT_NAME)); Assert.assertEquals("\"one\",1", tr.readLine()); Assert.assertEquals("\"two\",2", tr.readLine()); Assert.assertEquals("\"three\",3", tr.readLine()); Assert.assertEquals("\"four\",4", tr.readLine()); Assert.assertEquals("\"five\",5", tr.readLine()); Assert.assertEquals("\"six\",6", tr.readLine()); Assert.assertNull(tr.readLine()); tr.close(); (new File("test.csv")).delete(); (new File("test2.csv")).delete(); }
47. TestSort#testSortHeaders()
Project: encog-java-core
File: TestSort.java
File: TestSort.java
public void testSortHeaders() throws IOException { generateTestFileHeadings(true); SortCSV norm = new SortCSV(); norm.getSortOrder().add(new SortedField(1, SortType.SortString, true)); norm.process(INPUT_NAME, OUTPUT_NAME, true, CSVFormat.ENGLISH); BufferedReader tr = new BufferedReader(new FileReader(OUTPUT_NAME)); Assert.assertEquals("\"a\",\"b\"", tr.readLine()); Assert.assertEquals("\"one\",1", tr.readLine()); Assert.assertEquals("\"two\",2", tr.readLine()); Assert.assertEquals("\"three\",3", tr.readLine()); Assert.assertEquals("\"four\",4", tr.readLine()); Assert.assertEquals("\"five\",5", tr.readLine()); Assert.assertEquals("\"six\",6", tr.readLine()); Assert.assertNull(tr.readLine()); tr.close(); (new File("test.csv")).delete(); (new File("test2.csv")).delete(); }
48. TestShuffle#testShuffleNoHeaders()
Project: encog-java-core
File: TestShuffle.java
File: TestShuffle.java
public void testShuffleNoHeaders() throws IOException { generateTestFileHeadings(false); ShuffleCSV norm = new ShuffleCSV(); norm.analyze(INPUT_NAME, false, CSVFormat.ENGLISH); norm.setProduceOutputHeaders(false); norm.process(OUTPUT_NAME); BufferedReader tr = new BufferedReader(new FileReader(OUTPUT_NAME)); String line; Map<String, Integer> list = new HashMap<String, Integer>(); while ((line = tr.readLine()) != null) { list.put(line, 0); } Assert.assertEquals(6, list.size()); tr.close(); (new File("test.csv")).delete(); (new File("test2.csv")).delete(); }
49. TestShuffle#testShuffleHeaders()
Project: encog-java-core
File: TestShuffle.java
File: TestShuffle.java
public void testShuffleHeaders() throws IOException { generateTestFileHeadings(true); ShuffleCSV norm = new ShuffleCSV(); norm.analyze(INPUT_NAME, true, CSVFormat.ENGLISH); norm.process(OUTPUT_NAME); BufferedReader tr = new BufferedReader(new FileReader(OUTPUT_NAME)); String line; Map<String, Integer> list = new HashMap<String, Integer>(); while ((line = tr.readLine()) != null) { list.put(line, 0); } Assert.assertEquals(7, list.size()); tr.close(); (new File("test.csv")).delete(); (new File("test2.csv")).delete(); }
50. TestProcessIndicators#TestIndicatorsNoHeaders()
Project: encog-java-core
File: TestProcessIndicators.java
File: TestProcessIndicators.java
public void TestIndicatorsNoHeaders() throws IOException { generateTestFileHeadings(false); ProcessIndicators norm = new ProcessIndicators(); norm.analyze(INPUT_NAME, false, CSVFormat.ENGLISH); norm.addColumn(new MovingAverage(3, true)); norm.addColumn(new BestClose(3, true)); norm.getColumns().get(0).setOutput(true); norm.renameColumn(1, "close"); norm.process(OUTPUT_NAME); BufferedReader tr = new BufferedReader(new FileReader(OUTPUT_NAME)); Assert.assertEquals("20100103,3,2,6", tr.readLine()); Assert.assertEquals("20100104,4,3,7", tr.readLine()); Assert.assertEquals("20100105,5,4,8", tr.readLine()); Assert.assertEquals("20100106,6,5,9", tr.readLine()); Assert.assertEquals("20100107,7,6,10", tr.readLine()); tr.close(); INPUT_NAME.delete(); OUTPUT_NAME.delete(); }
51. TestProcessIndicators#testIndicatorsHeaders()
Project: encog-java-core
File: TestProcessIndicators.java
File: TestProcessIndicators.java
public void testIndicatorsHeaders() throws IOException { generateTestFileHeadings(true); ProcessIndicators norm = new ProcessIndicators(); norm.analyze(INPUT_NAME, true, CSVFormat.ENGLISH); norm.addColumn(new MovingAverage(3, true)); norm.addColumn(new BestClose(3, true)); norm.getColumns().get(0).setOutput(true); norm.process(OUTPUT_NAME); BufferedReader tr = new BufferedReader(new FileReader(OUTPUT_NAME)); Assert.assertEquals("\"date\",\"close\",\"MovAvg\",\"PredictBestClose\"", tr.readLine()); Assert.assertEquals("20100103,3,2,6", tr.readLine()); Assert.assertEquals("20100104,4,3,7", tr.readLine()); Assert.assertEquals("20100105,5,4,8", tr.readLine()); Assert.assertEquals("20100106,6,5,9", tr.readLine()); Assert.assertEquals("20100107,7,6,10", tr.readLine()); tr.close(); INPUT_NAME.delete(); OUTPUT_NAME.delete(); }
52. TestNinjaStreamWriter#testWrite()
Project: encog-java-core
File: TestNinjaStreamWriter.java
File: TestNinjaStreamWriter.java
public void testWrite() throws IOException { NinjaStreamWriter nsw = new NinjaStreamWriter(); nsw.open("test.csv", true, CSVFormat.ENGLISH); nsw.beginBar(new GregorianCalendar(2010, 00, 01).getTime()); nsw.storeColumn("close", 10); nsw.endBar(); nsw.beginBar(new GregorianCalendar(2010, 00, 02).getTime()); nsw.storeColumn("close", 11); nsw.endBar(); nsw.close(); BufferedReader tr = new BufferedReader(new FileReader("test.csv")); Assert.assertEquals("date,time,\"close\"", tr.readLine()); Assert.assertEquals("20100101,0,10", tr.readLine()); Assert.assertEquals("20100102,0,11", tr.readLine()); tr.close(); }
53. TestNinjaFileConvert#testConvert()
Project: encog-java-core
File: TestNinjaFileConvert.java
File: TestNinjaFileConvert.java
public void testConvert() throws IOException { generateTestFileHeadings(true); NinjaFileConvert norm = new NinjaFileConvert(); norm.analyze(INPUT_NAME, true, CSVFormat.ENGLISH); norm.process(OUTPUT_NAME); BufferedReader tr = new BufferedReader(new FileReader(OUTPUT_NAME)); Assert.assertEquals("20100101 000000;10;12;8;9;1000", tr.readLine()); Assert.assertEquals("20100102 000000;9;17;7;15;1000", tr.readLine()); tr.close(); INPUT_NAME.delete(); OUTPUT_NAME.delete(); }
54. TestFilter#TestFilterCSVNoHeaders()
Project: encog-java-core
File: TestFilter.java
File: TestFilter.java
public void TestFilterCSVNoHeaders() throws IOException { generateTestFileHeadings(false); FilterCSV norm = new FilterCSV(); norm.analyze(INPUT_NAME, false, CSVFormat.ENGLISH); norm.exclude(1, "1"); norm.process(OUTPUT_NAME); BufferedReader tr = new BufferedReader(new FileReader(OUTPUT_NAME)); Assert.assertEquals("four,2", tr.readLine()); tr.close(); INPUT_NAME.delete(); OUTPUT_NAME.delete(); }
55. TestFilter#testFilterCSVHeaders()
Project: encog-java-core
File: TestFilter.java
File: TestFilter.java
public void testFilterCSVHeaders() throws IOException { generateTestFileHeadings(true); FilterCSV norm = new FilterCSV(); norm.analyze(INPUT_NAME, true, CSVFormat.ENGLISH); norm.exclude(1, "1"); norm.process(OUTPUT_NAME); BufferedReader tr = new BufferedReader(new FileReader(OUTPUT_NAME)); Assert.assertEquals("\"a\",\"b\"", tr.readLine()); Assert.assertEquals("four,2", tr.readLine()); tr.close(); INPUT_NAME.delete(); OUTPUT_NAME.delete(); }
56. TestBalanceCSV#TestBalanceCSVNoHeaders()
Project: encog-java-core
File: TestBalanceCSV.java
File: TestBalanceCSV.java
public void TestBalanceCSVNoHeaders() throws IOException { generateTestFile(false); BalanceCSV norm = new BalanceCSV(); norm.analyze(INPUT_NAME, false, CSVFormat.ENGLISH); norm.process(OUTPUT_NAME, 1, 2); BufferedReader tr = new BufferedReader(new FileReader(OUTPUT_NAME)); Assert.assertEquals("one,1", tr.readLine()); Assert.assertEquals("two,1", tr.readLine()); Assert.assertEquals("four,2", tr.readLine()); Assert.assertEquals("five,2", tr.readLine()); Assert.assertEquals("six,3", tr.readLine()); Assert.assertEquals(2, norm.getCounts().get("1").intValue()); Assert.assertEquals(2, norm.getCounts().get("2").intValue()); Assert.assertEquals(1, norm.getCounts().get("3").intValue()); tr.close(); INPUT_NAME.delete(); OUTPUT_NAME.delete(); }
57. TestBalanceCSV#testBalanceCSVHeaders()
Project: encog-java-core
File: TestBalanceCSV.java
File: TestBalanceCSV.java
public void testBalanceCSVHeaders() throws IOException { generateTestFile(true); BalanceCSV norm = new BalanceCSV(); norm.analyze(INPUT_NAME, true, CSVFormat.ENGLISH); norm.process(OUTPUT_NAME, 1, 2); BufferedReader tr = new BufferedReader(new FileReader(OUTPUT_NAME)); Assert.assertEquals("\"a\",\"b\"", tr.readLine()); Assert.assertEquals("one,1", tr.readLine()); Assert.assertEquals("two,1", tr.readLine()); Assert.assertEquals("four,2", tr.readLine()); Assert.assertEquals("five,2", tr.readLine()); Assert.assertEquals("six,3", tr.readLine()); Assert.assertEquals(2, norm.getCounts().get("1").intValue()); Assert.assertEquals(2, norm.getCounts().get("2").intValue()); Assert.assertEquals(1, norm.getCounts().get("3").intValue()); tr.close(); INPUT_NAME.delete(); OUTPUT_NAME.delete(); }
58. FileUtil#readStreamAsString()
Project: encog-java-core
File: FileUtil.java
File: FileUtil.java
public static String readStreamAsString(InputStream is) throws java.io.IOException { StringBuffer fileData = new StringBuffer(1000); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); char[] buf = new char[1024]; int numRead = 0; while ((numRead = reader.read(buf)) != -1) { String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); buf = new char[1024]; } reader.close(); return fileData.toString(); }
59. EmojiLoader#inputStreamToString()
Project: emoji-java
File: EmojiLoader.java
File: EmojiLoader.java
private static String inputStreamToString(InputStream stream) throws IOException { StringBuilder sb = new StringBuilder(); InputStreamReader isr = new InputStreamReader(stream, "UTF-8"); BufferedReader br = new BufferedReader(isr); String read; while ((read = br.readLine()) != null) { sb.append(read); } br.close(); return sb.toString(); }
60. AbstractSourceTest#sqlScript()
Project: elasticsearch-jdbc
File: AbstractSourceTest.java
File: AbstractSourceTest.java
private void sqlScript(Connection connection, String resourceName) throws Exception { InputStream in = getClass().getResourceAsStream(resourceName); BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); String sql; while ((sql = br.readLine()) != null) { try { logger.trace("executing {}", sql); Statement p = connection.createStatement(); p.execute(sql); p.close(); } catch (SQLException e) { logger.error(sql + " failed. Reason: " + e.getMessage()); } finally { connection.commit(); } } br.close(); }
61. AbstractSinkTest#sqlScript()
Project: elasticsearch-jdbc
File: AbstractSinkTest.java
File: AbstractSinkTest.java
private void sqlScript(Connection connection, String resourceName) throws Exception { InputStream in = getClass().getResourceAsStream(resourceName); BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); String sql; while ((sql = br.readLine()) != null) { try { logger.info("executing {}", sql); Statement p = connection.createStatement(); p.execute(sql); p.close(); } catch (Exception e) { logger.error(sql + " failed. Reason: " + e.getMessage()); } finally { connection.commit(); } } br.close(); }
62. AbstractColumnStrategyTest#sqlScript()
Project: elasticsearch-jdbc
File: AbstractColumnStrategyTest.java
File: AbstractColumnStrategyTest.java
private void sqlScript(Connection connection, String resourceName) throws Exception { InputStream in = getClass().getResourceAsStream(resourceName); BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); String sql; while ((sql = br.readLine()) != null) { try { logger.trace("executing {}", sql); Statement p = connection.createStatement(); p.execute(sql); p.close(); } catch (SQLException e) { logger.error(sql + " failed. Reason: " + e.getMessage()); } finally { connection.commit(); } } br.close(); }
63. GrobidProperties#updatePropertyFile()
Project: grobid
File: GrobidProperties.java
File: GrobidProperties.java
/** * Update the input file with the key and value given as argument. * * @param pPropertyFile * file to update. * * @param pKey * key to replace * @param pValue * value to replace * @throws IOException */ public static void updatePropertyFile(File pPropertyFile, String pKey, String pValue) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(pPropertyFile)); String line, content = StringUtils.EMPTY, lineToReplace = StringUtils.EMPTY; while ((line = reader.readLine()) != null) { if (line.contains(pKey)) { lineToReplace = line; } content += line + "\r\n"; } reader.close(); if (!StringUtils.EMPTY.equals(lineToReplace)) { String newContent = content.replaceAll(lineToReplace, pKey + "=" + pValue); FileWriter writer = new FileWriter(pPropertyFile.getAbsoluteFile()); writer.write(newContent); writer.close(); } }
64. RequestListener#getMessage()
Project: GladiatorManager
File: RequestListener.java
File: RequestListener.java
// Helper methods public static String getMessage(HttpExchange t) throws IOException { InputStreamReader isr = new InputStreamReader(t.getRequestBody(), "utf-8"); BufferedReader br = new BufferedReader(isr); int b; StringBuilder buf = new StringBuilder(); while ((b = br.read()) != -1) { buf.append((char) b); } br.close(); isr.close(); return buf.toString(); }
65. JsonServlet#readJson()
Project: gitblit
File: JsonServlet.java
File: JsonServlet.java
private String readJson(HttpServletRequest request, HttpServletResponse response) throws IOException { BufferedReader reader = request.getReader(); StringBuilder json = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { json.append(line); } reader.close(); if (json.length() == 0) { logger.error(MessageFormat.format("Failed to receive json data from {0}", request.getRemoteAddr())); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return null; } return json.toString(); }
66. FilestoreServlet#readJson()
Project: gitblit
File: FilestoreServlet.java
File: FilestoreServlet.java
private String readJson(HttpServletRequest request, HttpServletResponse response) throws IOException { BufferedReader reader = request.getReader(); StringBuilder json = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { json.append(line); } reader.close(); if (json.length() == 0) { logger.error(MessageFormat.format("Failed to receive json data from {0}", request.getRemoteAddr())); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return null; } return json.toString(); }
67. StringHelperTest#assertLinesEqual()
Project: Git-Credential-Manager-for-Mac-and-Linux
File: StringHelperTest.java
File: StringHelperTest.java
public static void assertLinesEqual(final String expected, final String actual) throws IOException { final StringReader expectedSr = new StringReader(expected); final BufferedReader expectedBr = new BufferedReader(expectedSr); final StringReader actualSr = new StringReader(actual); final BufferedReader actualBr = new BufferedReader(actualSr); String expectedLine; String actualLine; while ((expectedLine = expectedBr.readLine()) != null) { if ((actualLine = actualBr.readLine()) != null) { Assert.assertEquals(expectedLine, actualLine); } else { Assert.fail("'expected' contained more lines than 'actual'."); } } if ((actualLine = actualBr.readLine()) != null) { Assert.fail("'actual' contained more lines than 'expected'."); } }
68. AppsForYourDomainMigrationClient#readFile()
Project: gdata-java-client
File: AppsForYourDomainMigrationClient.java
File: AppsForYourDomainMigrationClient.java
/** * Helper method to read a file and return its contents as a text string, * with lines separated by "\r\n" (CR+LF) style newlines. * @param location the path to the file * @return the String contents of the file * @throws IOException if an error occurs reading the file */ private static String readFile(String location) throws IOException { FileInputStream is = new FileInputStream(new File(location)); BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringBuffer fileContents = new StringBuffer(); String newLine = br.readLine(); while (newLine != null) { fileContents.append(newLine); fileContents.append("\r\n"); newLine = br.readLine(); } br.close(); return fileContents.toString(); }
69. FileUtils#getStringFromFile()
Project: Gadgetbridge
File: FileUtils.java
File: FileUtils.java
public static String getStringFromFile(File file) throws IOException { FileInputStream fin = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(fin)); StringBuilder sb = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } reader.close(); fin.close(); return sb.toString(); }
70. ModelCache#readValueFromDisk()
Project: frisbee
File: ModelCache.java
File: ModelCache.java
private Object readValueFromDisk(InputStream is) throws IOException, ClassNotFoundException { BufferedReader fss = new BufferedReader(new InputStreamReader(is, "UTF-8")); String className = fss.readLine(); if (className == null) { return null; } String line; String content = ""; while ((line = fss.readLine()) != null) { content += line; } fss.close(); Class<?> clazz = Class.forName(className); return mGson.fromJson(content, clazz); }
71. AbstractSourceDocument#load()
Project: forrest
File: AbstractSourceDocument.java
File: AbstractSourceDocument.java
/** * Loads the remainder of the content from the input stream. * * @throws IOException * */ private void load() throws IOException { final StringBuffer fileData = new StringBuffer(1000); final BufferedReader reader = this.getReader(); char[] buf = new char[1000]; int numRead = 0; while ((numRead = reader.read(buf)) != -1) { final String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); buf = new char[1000]; } this.addContent(fileData.toString()); this.setComplete(true); reader.close(); }
72. TestMapReduceLocal#readFile()
Project: hadoop-mapreduce
File: TestMapReduceLocal.java
File: TestMapReduceLocal.java
public static String readFile(String name) throws IOException { DataInputStream f = localFs.open(new Path(TEST_ROOT_DIR + "/" + name)); BufferedReader b = new BufferedReader(new InputStreamReader(f)); StringBuilder result = new StringBuilder(); String line = b.readLine(); while (line != null) { result.append(line); result.append('\n'); line = b.readLine(); } b.close(); return result.toString(); }
73. TestMapReduceLocal#readFile()
Project: hadoop-common
File: TestMapReduceLocal.java
File: TestMapReduceLocal.java
public String readFile(String name) throws IOException { DataInputStream f = localFs.open(new Path(TEST_ROOT_DIR + "/" + name)); BufferedReader b = new BufferedReader(new InputStreamReader(f)); StringBuilder result = new StringBuilder(); String line = b.readLine(); while (line != null) { result.append(line); result.append('\n'); line = b.readLine(); } b.close(); return result.toString(); }
74. LocalStore#zipCompress()
Project: hadoop-common
File: LocalStore.java
File: LocalStore.java
/** * Compress a text file using the ZIP compressing algorithm. * * @param filename the path to the file to be compressed */ public static void zipCompress(String filename) throws IOException { FileOutputStream fos = new FileOutputStream(filename + COMPRESSION_SUFFIX); CheckedOutputStream csum = new CheckedOutputStream(fos, new CRC32()); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(csum)); out.setComment("Failmon records."); BufferedReader in = new BufferedReader(new FileReader(filename)); out.putNextEntry(new ZipEntry(new File(filename).getName())); int c; while ((c = in.read()) != -1) out.write(c); in.close(); out.finish(); out.close(); }
75. TestMapReduceLocal#readFile()
Project: hadoop-20
File: TestMapReduceLocal.java
File: TestMapReduceLocal.java
public static String readFile(String name) throws IOException { DataInputStream f = localFs.open(new Path(TEST_ROOT_DIR + "/" + name)); BufferedReader b = new BufferedReader(new InputStreamReader(f)); StringBuilder result = new StringBuilder(); String line = b.readLine(); while (line != null) { result.append(line); result.append('\n'); line = b.readLine(); } b.close(); return result.toString(); }
76. TestLocalRunner#verifyOutput()
Project: hadoop-20
File: TestLocalRunner.java
File: TestLocalRunner.java
/** * Verify that we got the correct amount of output. */ private void verifyOutput(Path outputPath) throws IOException { Configuration conf = new Configuration(); FileSystem fs = FileSystem.getLocal(conf); Path outputFile = new Path(outputPath, "part-r-00000"); InputStream is = fs.open(outputFile); BufferedReader r = new BufferedReader(new InputStreamReader(is)); // Should get a single line of the form "0\t(count)" String line = r.readLine().trim(); assertTrue("Line does not have correct key", line.startsWith("0\t")); int count = Integer.valueOf(line.substring(2)); assertEquals("Incorrect count generated!", TOTAL_RECORDS, count); r.close(); }
77. ValidateNamespaceDirPolicy#execCommand()
Project: hadoop-20
File: ValidateNamespaceDirPolicy.java
File: ValidateNamespaceDirPolicy.java
private static String[] execCommand(String command) throws IOException { Process p = Runtime.getRuntime().exec(command); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); // Skip the first line, which is the header info br.readLine(); String output = br.readLine(); FLOG.info("Running: " + command + ", output: " + output); if (output == null || output.isEmpty()) { return new String[0]; } return output.split("\\s+"); }
78. LinuxUtilizationGauger#readFile()
Project: hadoop-20
File: LinuxUtilizationGauger.java
File: LinuxUtilizationGauger.java
/** * Read a file line by line * @param fileName * @return String[] contains lines * @throws IOException */ private String[] readFile(String fileName) throws IOException { ArrayList<String> result = new ArrayList<String>(); FileReader fReader = new FileReader(fileName); BufferedReader bReader = new BufferedReader(fReader); while (true) { String line = bReader.readLine(); if (line == null) { break; } result.add(line); } bReader.close(); fReader.close(); return (String[]) result.toArray(new String[result.size()]); }
79. LocalStore#zipCompress()
Project: hadoop-20
File: LocalStore.java
File: LocalStore.java
/** * Compress a text file using the ZIP compressing algorithm. * * @param filename the path to the file to be compressed */ public static void zipCompress(String filename) throws IOException { FileOutputStream fos = new FileOutputStream(filename + COMPRESSION_SUFFIX); CheckedOutputStream csum = new CheckedOutputStream(fos, new CRC32()); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(csum)); out.setComment("Failmon records."); BufferedReader in = new BufferedReader(new FileReader(filename)); out.putNextEntry(new ZipEntry(new File(filename).getName())); int c; while ((c = in.read()) != -1) out.write(c); in.close(); out.finish(); out.close(); }
80. CharSourceTester#testOpenBufferedStream()
Project: guava
File: CharSourceTester.java
File: CharSourceTester.java
public void testOpenBufferedStream() throws IOException { BufferedReader reader = source.openBufferedStream(); StringWriter writer = new StringWriter(); char[] buf = new char[64]; int read; while ((read = reader.read(buf)) != -1) { writer.write(buf, 0, read); } reader.close(); writer.close(); assertExpectedString(writer.toString()); }
81. CharSourceTest#testOpenBufferedStream()
Project: guava
File: CharSourceTest.java
File: CharSourceTest.java
public void testOpenBufferedStream() throws IOException { BufferedReader reader = source.openBufferedStream(); assertTrue(source.wasStreamOpened()); assertFalse(source.wasStreamClosed()); StringWriter writer = new StringWriter(); char[] buf = new char[64]; int read; while ((read = reader.read(buf)) != -1) { writer.write(buf, 0, read); } reader.close(); writer.close(); assertTrue(source.wasStreamClosed()); assertEquals(STRING, writer.toString()); }
82. TestFileUtils#load()
Project: Duke
File: TestFileUtils.java
File: TestFileUtils.java
public static Map<String, Link> load(String testfile) throws IOException { Map<String, Link> links = new HashMap(); BufferedReader reader = new BufferedReader(new FileReader(testfile)); String line = reader.readLine(); while (line != null) { int pos = line.indexOf(','); String id1 = line.substring(1, pos); String id2 = line.substring(pos + 1, line.length()); links.put(id1 + "," + id2, new Link(id1, id2, LinkStatus.ASSERTED, line.charAt(0) == '+' ? LinkKind.SAME : LinkKind.DIFFERENT, 0.0)); line = reader.readLine(); } reader.close(); return links; }
83. PersonNameCleaner#loadMapping()
Project: Duke
File: PersonNameCleaner.java
File: PersonNameCleaner.java
private Map<String, String> loadMapping() throws IOException { String mapfile = "no/priv/garshol/duke/name-mappings.txt"; Map<String, String> mapping = new HashMap(); ClassLoader cloader = Thread.currentThread().getContextClassLoader(); InputStream istream = cloader.getResourceAsStream(mapfile); InputStreamReader reader = new InputStreamReader(istream, "utf-8"); BufferedReader in = new BufferedReader(reader); String line = in.readLine(); while (line != null) { int pos = line.indexOf(','); mapping.put(line.substring(0, pos), line.substring(pos + 1)); line = in.readLine(); } in.close(); return mapping; }
84. DrlPackageDataTest#testHandleDrl2()
Project: drools
File: DrlPackageDataTest.java
File: DrlPackageDataTest.java
@Test public void testHandleDrl2() throws IOException, ParseException { BufferedReader in = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("DrlPackageTestData.drl"))); String rule = ""; String str; while ((str = in.readLine()) != null) { rule += str; rule += "\n"; } in.close(); DrlPackageParser s = DrlPackageParser.findPackageDataFromDrl(rule); assertNotNull(s); assertEquals("org.drools.test", s.getName()); assertEquals(5, s.getRules().size()); assertEquals("", s.getDescription()); }
85. FileManager#readInputStreamReaderAsString()
Project: drools
File: FileManager.java
File: FileManager.java
public String readInputStreamReaderAsString(InputStreamReader in) throws IOException { StringBuffer fileData = new StringBuffer(1000); BufferedReader reader = new BufferedReader(in); char[] buf = new char[1024]; int numRead = 0; while ((numRead = reader.read(buf)) != -1) { String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); buf = new char[1024]; } reader.close(); return fileData.toString(); }
86. Waltz#loadLines()
Project: drools
File: Waltz.java
File: Waltz.java
private void loadLines(final KieSession kSession, final String filename) throws IOException { final BufferedReader reader = new BufferedReader(new InputStreamReader(Waltz.class.getResourceAsStream(filename))); final Pattern pat = Pattern.compile(".*make line \\^p1 ([0-9]*) \\^p2 ([0-9]*).*"); String line = reader.readLine(); while (line != null) { final Matcher m = pat.matcher(line); if (m.matches()) { final Line l = new Line(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2))); kSession.insert(l); } line = reader.readLine(); } reader.close(); }
87. FileUtils#readAllText()
Project: Doradus
File: FileUtils.java
File: FileUtils.java
public static String readAllText(String filePath) throws Exception { BufferedReader reader = new BufferedReader(new FileReader(filePath)); StringBuilder result = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) result.append(line).append("\r\n"); reader.close(); return result.toString(); }
88. Krb5Parser#load()
Project: directory-kerby
File: Krb5Parser.java
File: Krb5Parser.java
/** * Load the krb5.conf into a member variable, which is a Map. * @throws IOException e */ public void load() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(krb5conf), StandardCharsets.UTF_8)); items = new IdentityHashMap<>(); String originLine = br.readLine(); while (originLine != null) { String line = originLine.trim(); /*parse through comments*/ if (line.startsWith("#") || line.length() == 0) { originLine = br.readLine(); } else if (line.startsWith("[")) { insertSections(line, br, items); originLine = br.readLine(); } else { throw new RuntimeException("Unable to parse:" + originLine); } } br.close(); }
89. IniConfigLoader#loadConfig()
Project: directory-kerby
File: IniConfigLoader.java
File: IniConfigLoader.java
/** * Load configs form the INI configuration format file. */ @Override protected void loadConfig(ConfigImpl config, Resource resource) throws IOException { rootConfig = config; currentConfig = config; InputStream is = (InputStream) resource.getResource(); BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); String line; while ((line = reader.readLine()) != null) { parseLine(line); } reader.close(); }
90. ServicePropertiesFileTest#grepForToken()
Project: derby
File: ServicePropertiesFileTest.java
File: ServicePropertiesFileTest.java
/** * Looks for the specified token in the given file. * * @param token the search token * @param file the file to search * @return The number of matching lines. * * @throws IOException if accessing the specified file fails */ private int grepForToken(String token, File file) throws IOException { int matchingLines = 0; BufferedReader in = new BufferedReader(new InputStreamReader(PrivilegedFileOpsForTests.getFileInputStream(file), SPF_ENCODING)); String line; while ((line = in.readLine()) != null) { if (line.indexOf(token) != -1) { matchingLines++; } } in.close(); return matchingLines; }
91. ServicePropertiesFileTest#assertEOFToken()
Project: derby
File: ServicePropertiesFileTest.java
File: ServicePropertiesFileTest.java
/** * Asserts that the specified file ends with the end-of-file token. */ private void assertEOFToken(File file, String encoding) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(PrivilegedFileOpsForTests.getFileInputStream(file), encoding)); String prev = null; String cur; while ((cur = in.readLine()) != null) { prev = cur; } in.close(); assertNotNull("last line is null - empty file?", prev); assertTrue("prev:" + prev + ": does not equal " + END_TOKEN, prev.startsWith(END_TOKEN)); }
92. ClobTest#transferData()
Project: derby
File: ClobTest.java
File: ClobTest.java
private int transferData(Reader source, int tz) throws IOException, SQLException { if (tz < 1) { throw new IllegalArgumentException("Buffer size must be 1 or greater: " + tz); } BufferedReader in = new BufferedReader(source); char[] bridge = new char[tz]; int total = 0; int read; while ((read = in.read(bridge, 0, tz)) != -1) { this.clob.setString(total + 1L, String.copyValueOf(bridge, 0, read)); total += read; } in.close(); return total; }
93. ClobTest#transferData()
Project: derby
File: ClobTest.java
File: ClobTest.java
/** * Transfer data from a source Reader to a destination Writer. * * @param source source data * @param dest destination to write to * @param tz buffer size in number of characters. Must be 1 or greater. * @return Number of characters read from the source data. This should equal the * number of characters written to the destination. */ private int transferData(Reader source, Writer dest, int tz) throws IOException { if (tz < 1) { throw new IllegalArgumentException("Buffer size must be 1 or greater: " + tz); } BufferedReader in = new BufferedReader(source); BufferedWriter out = new BufferedWriter(dest, tz); char[] bridge = new char[tz]; int total = 0; int read; while ((read = in.read(bridge, 0, tz)) != -1) { out.write(bridge, 0, read); total += read; } in.close(); // Don't close the stream, in case it will be written to again. out.flush(); return total; }
94. SimpleDiff#lineCount()
Project: derby
File: SimpleDiff.java
File: SimpleDiff.java
int lineCount(String file) throws IOException { BufferedReader input = new BufferedReader(new FileReader(file)); int count = 0; String aLine = input.readLine(); while (aLine != null) { count++; aLine = input.readLine(); } input.close(); return count; }
95. RunTest#appendStderr()
Project: derby
File: RunTest.java
File: RunTest.java
static void appendStderr(BufferedOutputStream bos, InputStream is) throws IOException { PrintWriter tmpPw = new PrintWriter(bos); // reader for stderr BufferedReader errReader = new BufferedReader(new InputStreamReader(is, "UTF-8")); String s = null; int lines = 0; while ((s = errReader.readLine()) != null) { tmpPw.println(s); } errReader.close(); tmpPw.flush(); }
96. InternalClobTest#transferData()
Project: derby
File: InternalClobTest.java
File: InternalClobTest.java
/** * Transfers data from the source to the destination. */ public static long transferData(Reader src, Writer dest, long charsToCopy) throws IOException { BufferedReader in = new BufferedReader(src); BufferedWriter out = new BufferedWriter(dest, BUFFER_SIZE); char[] bridge = new char[BUFFER_SIZE]; long charsLeft = charsToCopy; int read; while ((read = in.read(bridge, 0, (int) Math.min(charsLeft, BUFFER_SIZE))) > 0) { out.write(bridge, 0, read); charsLeft -= read; } in.close(); // Don't close the stream, in case it will be written to again. out.flush(); return charsToCopy - charsLeft; }
97. CSVBenchmark#parseCommonsCSV()
Project: commons-csv
File: CSVBenchmark.java
File: CSVBenchmark.java
@Benchmark public int parseCommonsCSV(final Blackhole bh) throws Exception { final BufferedReader in = getReader(); final CSVFormat format = CSVFormat.DEFAULT.withHeader(); int count = 0; for (final CSVRecord record : format.parse(in)) { count++; } bh.consume(count); in.close(); return count; }
98. CSVBenchmark#split()
Project: commons-csv
File: CSVBenchmark.java
File: CSVBenchmark.java
@Benchmark public int split(final Blackhole bh) throws Exception { final BufferedReader in = getReader(); int count = 0; String line; while ((line = in.readLine()) != null) { final String[] values = StringUtils.split(line, ','); count += values.length; } bh.consume(count); in.close(); return count; }
99. CSVBenchmark#read()
Project: commons-csv
File: CSVBenchmark.java
File: CSVBenchmark.java
@Benchmark public int read(final Blackhole bh) throws Exception { final BufferedReader in = getReader(); int count = 0; String line; while ((line = in.readLine()) != null) { count++; } bh.consume(count); in.close(); return count; }
100. LongSymLinkTest#setUpFileList()
Project: commons-compress
File: LongSymLinkTest.java
File: LongSymLinkTest.java
@BeforeClass public static void setUpFileList() throws Exception { assertTrue(ARCDIR.exists()); final File listing = new File(ARCDIR, "files.txt"); assertTrue("files.txt is readable", listing.canRead()); final BufferedReader br = new BufferedReader(new FileReader(listing)); String line; while ((line = br.readLine()) != null) { if (!line.startsWith("#")) { FILELIST.add(line); } } br.close(); }