Skip to content

Instantly share code, notes, and snippets.

@xavivars
Created August 22, 2013 21:06
Show Gist options
  • Save xavivars/6312777 to your computer and use it in GitHub Desktop.
Save xavivars/6312777 to your computer and use it in GitHub Desktop.
Sample version of the commandline tool
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