use of java.io.FileReader in project CoreNLP by stanfordnlp.
the class TaggerDemo method main.
public static void main(String[] args) throws Exception {
if (args.length != 2) {
log.info("usage: java TaggerDemo modelFile fileToTag");
return;
}
MaxentTagger tagger = new MaxentTagger(args[0]);
List<List<HasWord>> sentences = MaxentTagger.tokenizeText(new BufferedReader(new FileReader(args[1])));
for (List<HasWord> sentence : sentences) {
List<TaggedWord> tSentence = tagger.tagSentence(sentence);
System.out.println(SentenceUtils.listToString(tSentence, false));
}
}
use of java.io.FileReader in project camel by apache.
the class ManualGenerator method doGenerate.
private boolean doGenerate() throws MalformedURLException, IOException {
if (skip.equalsIgnoreCase("true")) {
// we don't want to generate the manual here
return false;
}
URL url = new URL(page);
File file = new File(targetDir, ".manualCache-" + url.getFile().substring(1));
if (file.exists()) {
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("HEAD");
long date = con.getLastModified();
FileReader reader = new FileReader(file);
char[] chars = new char[1000];
int i = reader.read(chars);
reader.close();
long lastDate = Long.parseLong(new String(chars, 0, i).trim());
if (date <= lastDate) {
return false;
}
}
return true;
}
use of java.io.FileReader in project camel by apache.
the class RouteBuilderParser method findLineNumber.
private static int findLineNumber(String fullyQualifiedFileName, int position) {
int lines = 0;
try {
int current = 0;
try (BufferedReader br = new BufferedReader(new FileReader(new File(fullyQualifiedFileName)))) {
String line;
while ((line = br.readLine()) != null) {
lines++;
// add 1 for line feed
current += line.length() + 1;
if (current >= position) {
return lines;
}
}
}
} catch (Exception e) {
// ignore
return -1;
}
return lines;
}
use of java.io.FileReader in project auto by google.
the class EclipseHack method getPropertyOrderer.
private PropertyOrderer getPropertyOrderer(TypeElement type) {
try {
// If we are in Eclipse, then processingEnv will be an instance of
// org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeProcessingEnvImpl
// and we can access its getEnclosingIFile method to obtain an Eclipse
// org.eclipse.core.resources.IFile. Then we will access the
// String getCharset();
// and
// InputStream getContents();
// methods to access the whole source file that includes this class.
// If the class in question has not changed since Eclipse last succeessfully compiled it
// then the IFile will be the compiled class file rather than the source, and we will need
// to read the order of the methods out of the class file. The method
// URI getRawLocationURI();
// will tell us this because the URI will end with .class instead of .java.
// If we are not in Eclipse then the reflection here will fail and we will return null,
// which will mean that the caller won't try to reorder.
Method getEnclosingIFile = processingEnv.getClass().getMethod("getEnclosingIFile", Element.class);
final Object iFile = getEnclosingIFile.invoke(processingEnv, type);
URI uri = (URI) iFile.getClass().getMethod("getRawLocationURI").invoke(iFile);
if (uri.getPath().endsWith(".class")) {
return new BinaryPropertyOrderer(uri);
} else {
Method getCharset = iFile.getClass().getMethod("getCharset");
final String charset = (String) getCharset.invoke(iFile);
final Method getContents = iFile.getClass().getMethod("getContents");
Callable<Reader> readerProvider = new Callable<Reader>() {
@Override
public Reader call() throws Exception {
InputStream inputStream = (InputStream) getContents.invoke(iFile);
return new InputStreamReader(inputStream, charset);
}
};
return new SourcePropertyOrderer(type, readerProvider);
}
} catch (Exception e) {
// through the getFileName method.
if (!type.getClass().getName().toLowerCase().contains("eclipse")) {
// Guard against the case where a non-Eclipse type happens to have a getFileName method
return null;
}
try {
final String filename = (String) type.getClass().getMethod("getFileName").invoke(type);
Callable<Reader> readerProvider = new Callable<Reader>() {
@Override
public Reader call() throws Exception {
return new FileReader(filename);
}
};
return new SourcePropertyOrderer(type, readerProvider);
} catch (Exception e2) {
// Reflection failed (twice), so we are presumably not in Eclipse.
return null;
}
}
}
use of java.io.FileReader in project gocd by gocd.
the class DataUtils method readFileContent.
public static String readFileContent(File file) throws Exception {
BufferedReader reader = null;
StringBuffer sb = new StringBuffer();
try {
reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
} finally {
if (reader != null) {
reader.close();
}
}
return sb.toString();
}
Aggregations