Search in sources :

Example 31 with BufferedReader

use of java.io.BufferedReader in project Talon-for-Twitter by klinker24.

the class TrimDataService method getDoc.

public Document getDoc() {
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet("https://play.google.com/store/apps/details?id=com.klinker.android.twitter");
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        InputStream is = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
            Log.v("talon_version", line);
        }
        String docHtml = sb.toString();
        is.close();
        return Jsoup.parse(docHtml);
    } catch (Exception e) {
        return null;
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) BufferedReader(java.io.BufferedReader) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 32 with BufferedReader

use of java.io.BufferedReader in project Lazy by l123456789jy.

the class M3U8ParserUtiles method parseString.

/**
     * 解析m3u8的ts下载地址
     * @param fis
     * @return
     */
public static List<String> parseString(FileInputStream fis) {
    List<String> resultList = null;
    try {
        if (fis != null) {
            resultList = new ArrayList<String>();
            BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
            String line = "";
            while ((line = reader.readLine()) != null) {
                if (line.startsWith("#")) {
                    //解析出播放视频的iv的key
                    if (line.startsWith("#EXT-X-KEY")) {
                        resultList.add(line);
                    }
                } else if (line.length() > 0 && line.startsWith("http://")) {
                    resultList.add(line);
                }
            }
            fis.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
        Log.e("Exception", "解析m3u8错误" + e.getMessage());
    }
    return resultList;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader)

Example 33 with BufferedReader

use of java.io.BufferedReader in project Lazy by l123456789jy.

the class FileUtils method readFileContent.

/**
     * 读取文本文件内容,以行的形式读取
     *
     * @param filePathAndName 带有完整绝对路径的文件名
     * @param encoding 文本文件打开的编码方式 例如 GBK,UTF-8
     * @param sep 分隔符 例如:#,默认为\n;
     * @param bufLen 设置缓冲区大小
     * @return String 返回文本文件的内容
     */
public static String readFileContent(String filePathAndName, String encoding, String sep, int bufLen) {
    if (filePathAndName == null || filePathAndName.equals("")) {
        return "";
    }
    if (sep == null || sep.equals("")) {
        sep = "\n";
    }
    if (!new File(filePathAndName).exists()) {
        return "";
    }
    StringBuffer str = new StringBuffer("");
    FileInputStream fs = null;
    InputStreamReader isr = null;
    BufferedReader br = null;
    try {
        fs = new FileInputStream(filePathAndName);
        if (encoding == null || encoding.trim().equals("")) {
            isr = new InputStreamReader(fs);
        } else {
            isr = new InputStreamReader(fs, encoding.trim());
        }
        br = new BufferedReader(isr, bufLen);
        String data = "";
        while ((data = br.readLine()) != null) {
            str.append(data).append(sep);
        }
    } catch (IOException e) {
    } finally {
        try {
            if (br != null)
                br.close();
            if (isr != null)
                isr.close();
            if (fs != null)
                fs.close();
        } catch (IOException e) {
        }
    }
    return str.toString();
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 34 with BufferedReader

use of java.io.BufferedReader in project Lazy by l123456789jy.

the class FileUtils method readFile.

/**
     * read file
     *
     * @param filePath    路径
     * @param charsetName The name of a supported {@link
     * java.nio.charset.Charset </code>charset<code>}
     * @return if file not exist, return null, else return content of file
     * @throws RuntimeException if an error occurs while operator
     * BufferedReader
     */
public static StringBuilder readFile(String filePath, String charsetName) {
    File file = new File(filePath);
    StringBuilder fileContent = new StringBuilder("");
    if (file == null || !file.isFile()) {
        return null;
    }
    BufferedReader reader = null;
    try {
        InputStreamReader is = new InputStreamReader(new FileInputStream(file), charsetName);
        reader = new BufferedReader(is);
        String line = null;
        while ((line = reader.readLine()) != null) {
            if (!fileContent.toString().equals("")) {
                fileContent.append("\r\n");
            }
            fileContent.append(line);
        }
        return fileContent;
    } catch (IOException e) {
        throw new RuntimeException("IOException occurred. ", e);
    } finally {
        IOUtils.close(reader);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 35 with BufferedReader

use of java.io.BufferedReader in project blueprints by tinkerpop.

the class GraphMLWriterTest method streamToString.

private String streamToString(final InputStream in) throws IOException {
    Writer writer = new StringWriter();
    char[] buffer = new char[1024];
    try {
        Reader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
        int n;
        while ((n = reader.read(buffer)) != -1) {
            writer.write(buffer, 0, n);
        }
    } finally {
        in.close();
    }
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Aggregations

BufferedReader (java.io.BufferedReader)5525 InputStreamReader (java.io.InputStreamReader)3410 IOException (java.io.IOException)2592 FileReader (java.io.FileReader)1282 File (java.io.File)936 InputStream (java.io.InputStream)840 ArrayList (java.util.ArrayList)764 FileInputStream (java.io.FileInputStream)693 URL (java.net.URL)520 Test (org.junit.Test)446 FileNotFoundException (java.io.FileNotFoundException)379 StringReader (java.io.StringReader)340 BufferedWriter (java.io.BufferedWriter)242 HashMap (java.util.HashMap)232 HttpURLConnection (java.net.HttpURLConnection)227 Matcher (java.util.regex.Matcher)222 OutputStreamWriter (java.io.OutputStreamWriter)212 URLConnection (java.net.URLConnection)208 PrintWriter (java.io.PrintWriter)205 Reader (java.io.Reader)200