Search in sources :

Example 61 with FileReader

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));
    }
}
Also used : HasWord(edu.stanford.nlp.ling.HasWord) TaggedWord(edu.stanford.nlp.ling.TaggedWord) MaxentTagger(edu.stanford.nlp.tagger.maxent.MaxentTagger) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) List(java.util.List)

Example 62 with FileReader

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;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) FileReader(java.io.FileReader) File(java.io.File) URL(java.net.URL)

Example 63 with FileReader

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;
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File)

Example 64 with FileReader

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;
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) FileReader(java.io.FileReader) Method(java.lang.reflect.Method) URI(java.net.URI) Callable(java.util.concurrent.Callable) IOException(java.io.IOException) FileReader(java.io.FileReader)

Example 65 with FileReader

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();
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Aggregations

FileReader (java.io.FileReader)1873 BufferedReader (java.io.BufferedReader)1289 IOException (java.io.IOException)893 File (java.io.File)811 FileNotFoundException (java.io.FileNotFoundException)304 ArrayList (java.util.ArrayList)274 Test (org.junit.Test)197 FileWriter (java.io.FileWriter)148 HashMap (java.util.HashMap)116 Reader (java.io.Reader)99 BufferedWriter (java.io.BufferedWriter)98 Properties (java.util.Properties)66 InputStreamReader (java.io.InputStreamReader)64 LineNumberReader (java.io.LineNumberReader)61 Matcher (java.util.regex.Matcher)61 Map (java.util.Map)59 List (java.util.List)56 PrintWriter (java.io.PrintWriter)51 StringTokenizer (java.util.StringTokenizer)51 HashSet (java.util.HashSet)50