List of usage examples for java.io BufferedReader close
public void close() throws IOException
From source file:Main.java
public static String getContent(InputStream is) throws IOException { StringBuilder builder = new StringBuilder(); BufferedReader buffer = new BufferedReader(new InputStreamReader(is)); String line = null;//from ww w .j a v a2s . c o m while ((line = buffer.readLine()) != null) { builder.append(line).append("\n"); } buffer.close(); return builder.toString().trim(); }
From source file:Main.java
public static String decompress(byte[] bytes) { if (bytes == null || bytes.length == 0) { return ""; }// ww w . j a va 2 s . co m String outStr = ""; try { final GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes)); final BufferedReader bf = new BufferedReader(new InputStreamReader(gis, "UTF-8")); String line; while ((line = bf.readLine()) != null) { outStr += line; } bf.close(); } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return outStr; }
From source file:Main.java
static JSONObject load(Context ctxt, String fn) throws JSONException, IOException { FileInputStream is = ctxt.openFileInput(fn); InputStreamReader reader = new InputStreamReader(is); BufferedReader in = new BufferedReader(reader); StringBuilder buf = new StringBuilder(); String str;// ww w . j av a2s. c om while ((str = in.readLine()) != null) { buf.append(str); } in.close(); return (new JSONObject(buf.toString())); }
From source file:com.ibm.bi.dml.runtime.io.IOUtilFunctions.java
/** * /*ww w. j av a 2 s . c om*/ * @param br */ public static void closeSilently(BufferedReader br) { try { if (br != null) br.close(); } catch (Exception ex) { LOG.error("Failed to close buffered reader.", ex); } }
From source file:Main.java
private static String makeContent(InputStream is) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line;//from w w w . j av a 2s. c o m while ((line = br.readLine()) != null) { sb.append(line + "\n"); } br.close(); return sb.toString(); }
From source file:Main.java
public static List<String> readFileToList(String filepath) { List<String> data = new ArrayList<String>(); try {//from w ww . j ava 2 s. c o m File file = new File(filepath); FileReader fileReader = new FileReader(file); BufferedReader bufferedReader = new BufferedReader(fileReader); String temp; while ((temp = bufferedReader.readLine()) != null) { data.add(temp); } bufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } return data; }
From source file:Main.java
public static List<String> loadBusList(Context context) throws IOException { InputStream is = context.getAssets().open("list.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(is)); List<String> list = new ArrayList<String>(); String line;/* w w w . java 2s . c o m*/ while ((line = br.readLine()) != null) { list.add(line); } br.close(); return list; }
From source file:Main.java
public static List<String> readFromFile(String file, Context context) { List<String> readLines = new ArrayList<String>(); try {/*from w w w. j a va 2 s. c o m*/ // File readFile = new File(config.getApp().getDir("files", // Context.MODE_WORLD_READABLE), file); BufferedReader reader = toReader(context.openFileInput(file)); String read = null; while ((read = reader.readLine()) != null) { readLines.add(read); } reader.close(); } catch (IOException e) { } return readLines; }
From source file:com.roncoo.pay.utils.JsonUtils.java
/** * Json???Json//from w w w. j ava 2s.co m * @param httpServletRequest * @return */ public static JSONObject requestJson(HttpServletRequest httpServletRequest) { StringBuffer buffer = new StringBuffer(); String line = null; JSONObject jsonObject = null; try { BufferedReader reader = httpServletRequest.getReader(); while ((line = reader.readLine()) != null) { buffer.append(line); } reader.close(); jsonObject = JSONObject.parseObject(buffer.toString()); } catch (Exception e) { LOG.error(e); } return jsonObject; }
From source file:net.foxgenesis.helper.SiteReader.java
/** * Get a site's HTML//from w w w . jav a2s . c o m * * @param url * - site's url * @return site's HTML * @throws IOException */ public static String getHTML(URL url) throws IOException { BufferedReader in = getStream(url); String output = ""; String inputLine; while ((inputLine = in.readLine()) != null) output += inputLine; in.close(); return output; }