Java BufferedReader Read loadSentences(InputStream stream, List jsonSentences)

Here you can find the source of loadSentences(InputStream stream, List jsonSentences)

Description

load Sentences

License

Creative Commons License

Declaration

public static void loadSentences(InputStream stream, List<JsonObject> jsonSentences) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

import com.google.common.base.Preconditions;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

public class Main {
    public static JsonParser jsonParser = new JsonParser();

    public static void loadSentences(InputStream stream, List<JsonObject> jsonSentences) throws IOException {
        Preconditions.checkNotNull(jsonSentences);

        BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        try {/*w  ww  . j a v a  2 s.  c o  m*/
            String line = br.readLine();
            while (line != null) {
                line = line.trim();
                if (line.equals("") || line.charAt(0) == '#') {
                    line = br.readLine();
                    continue;
                }
                JsonObject sentence = jsonParser.parse(line).getAsJsonObject();
                jsonSentences.add(sentence);
                line = br.readLine();
            }
        } finally {
            br.close();
        }
    }
}

Related

  1. loadQueryFromFile(String queryFile)
  2. loadQueryNodeInfo(String input_file)
  3. loadReaderFromClasspath(Class c, String filename)
  4. loadReaderToList(Reader reader)
  5. loadRealDataGraphFromEmbers(String fileName, String splitter)
  6. loadSimpleTextFile(File file, int bufferSize)
  7. loadSqlFile(String path)
  8. loadSQLFromFile(String fileName)
  9. loadStream(InputStream is)