Created
August 22, 2013 21:06
-
-
Save xavivars/6312777 to your computer and use it in GitHub Desktop.
Sample version of the commandline tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.languagetool.commandline; | |
import java.io.*; | |
public class StdinTest { | |
public static void main (String [] args) throws Exception { | |
StdinTest stdinTest = new StdinTest(); | |
} | |
public StdinTest() throws Exception { | |
InputStreamReader isr = null; | |
BufferedReader br = null; | |
for (int i = 0; i< 4; i++) { | |
isr = getInputStreamReader("-", null); | |
br = new BufferedReader(isr); | |
String line; | |
StringBuilder sb = new StringBuilder(); | |
while ((line = br.readLine()) != null) { | |
sb.append(line); | |
} | |
System.out.println(sb); | |
br.close(); | |
isr.close(); | |
} | |
} | |
private InputStreamReader getInputStreamReader(String filename, String encoding) | |
throws UnsupportedEncodingException, FileNotFoundException { | |
final InputStreamReader isr; | |
if (!"-".equals(filename)) { | |
final File file = new File(filename); | |
if (encoding != null) { | |
isr = new InputStreamReader(new BufferedInputStream( | |
new FileInputStream(file.getAbsolutePath())), encoding); | |
} else { | |
isr = new InputStreamReader(new BufferedInputStream( | |
new FileInputStream(file.getAbsolutePath()))); | |
} | |
} else { | |
if (encoding != null) { | |
isr = new InputStreamReader(new BufferedInputStream(System.in), encoding); | |
} else { | |
isr = new InputStreamReader(new BufferedInputStream(System.in)); | |
} | |
} | |
return isr; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment