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;
}
}
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;
}
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();
}
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);
}
}
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();
}
Aggregations