List of usage examples for java.io BufferedReader close
public void close() throws IOException
From source file:Main.java
public static String[] getMounts(final String path) { try {/*from w w w . j ava 2 s . co m*/ BufferedReader br = new BufferedReader(new FileReader("/proc/mounts"), 256); String line = null; while ((line = br.readLine()) != null) { if (line.contains(path)) { return line.split(" "); } } br.close(); } catch (FileNotFoundException e) { Log.d(TAG, "/proc/mounts does not exist"); } catch (IOException e) { Log.d(TAG, "Error reading /proc/mounts"); } return null; }
From source file:Main.java
private static String readTextFile(String fullPathFilename) throws IOException { StringBuffer contents = new StringBuffer(); BufferedReader reader = null; reader = new BufferedReader(new FileReader(fullPathFilename)); String text = null;//from w w w. j a v a2 s. c o m while ((text = reader.readLine()) != null) { contents.append(text).append(System.getProperty("line.separator")); } reader.close(); return contents.toString(); }
From source file:com.github.seqware.queryengine.system.Utility.java
/** * <p>dumpVCFFromFeatureSetID.</p> * * @param fSet a {@link com.github.seqware.queryengine.model.FeatureSet} object. * @param file a {@link java.lang.String} object. *///from w w w .java 2 s . c om public static boolean dumpFromMapReducePlugin(String header, Reference ref, FeatureSet fSet, Class<? extends PluginInterface> arbitraryPlugin, String file, Object... params) { BufferedWriter outputStream = null; try { if (file != null) { outputStream = new BufferedWriter(new FileWriter(file)); } else { outputStream = new BufferedWriter(new OutputStreamWriter(System.out)); } if (header != null) { outputStream.append(header); } } catch (IOException e) { Logger.getLogger(Utility.class.getName()).fatal("Exception thrown starting export to file:", e); System.exit(-1); } if (SWQEFactory.getQueryInterface() instanceof MRHBasePersistentBackEnd) { if (SWQEFactory.getModelManager() instanceof MRHBaseModelManager) { try { QueryFuture<File> future = SWQEFactory.getQueryInterface().getFeaturesByPlugin(0, arbitraryPlugin, ref, params); File get = future.get(); Collection<File> listFiles = FileUtils.listFiles(get, new WildcardFileFilter("part*"), DirectoryFileFilter.DIRECTORY); for (File f : listFiles) { BufferedReader in = new BufferedReader(new FileReader(f)); IOUtils.copy(in, outputStream); in.close(); } get.deleteOnExit(); assert (outputStream != null); outputStream.flush(); outputStream.close(); return true; } catch (IOException e) { Logger.getLogger(VCFDumper.class.getName()).fatal("Exception thrown exporting to file:", e); System.exit(-1); } catch (Exception e) { Logger.getLogger(VCFDumper.class.getName()) .fatal("MapReduce exporting failed, falling-through to normal exporting to file", e); } } } return false; }
From source file:Main.java
@TargetApi(4) public static String getCpuInfo() { StringBuffer sb = new StringBuffer(); sb.append("abi: ").append(Build.CPU_ABI).append("\n"); if (new File("/proc/cpuinfo").exists()) { try {/*w w w . ja va2 s . c o m*/ BufferedReader br = new BufferedReader(new FileReader(new File("/proc/cpuinfo"))); String aLine; while ((aLine = br.readLine()) != null) { sb.append(aLine + "\n"); } if (br != null) { br.close(); } } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); }
From source file:Main.java
public static String getHtml(String getUrl, int outtime, String charsetName) { String html = ""; URL url;// ww w . j ava 2 s. com try { url = new URL(getUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; CIBA)"); // connection.setRequestProperty("Connection", "Keep-Alive"); // connection.setRequestProperty("Cache-Control", "no-cache"); connection.setConnectTimeout(outtime); connection.connect(); InputStream inStrm = connection.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(inStrm, charsetName)); String temp = ""; while ((temp = br.readLine()) != null) { html = html + (temp + '\n'); } try { br.close(); } catch (Exception e) { // TODO: handle exception } try { connection.disconnect(); } catch (Exception e) { // TODO: handle exception } } catch (Exception e) { e.printStackTrace(); } return html; }
From source file:Main.java
public static String get(String url) { try {/* w w w. j av a 2 s. c o m*/ URL u = new URL(url); HttpURLConnection connection = (HttpURLConnection) u.openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Charset", "UTF-8"); InputStream is = connection.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String response = ""; String readLine = ""; while ((readLine = br.readLine()) != null) { response += readLine; } br.close(); return response; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static StringBuffer readInputStream(InputStream inputStream) throws IOException { InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8"); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); StringBuffer requestXml = new StringBuffer(); String line;//from ww w .java 2s .com while (null != (line = bufferedReader.readLine())) { requestXml.append(line).append(System.getProperty("line.separator")); } bufferedReader.close(); inputStreamReader.close(); return requestXml; }
From source file:Main.java
public static List<String> readFile(Reader simpleReader) throws IOException { BufferedReader reader = new BufferedReader(simpleReader); try {/*ww w . jav a 2 s . c o m*/ List<String> res = new ArrayList<String>(); String line; while ((line = reader.readLine()) != null) { res.add(line); } return res; } finally { reader.close(); } }
From source file:gaffer.accumulo.utils.IngestUtils.java
/** * Read a splits file and get the number of split points within. * /*w w w. j a v a 2 s .c o m*/ * @param fs The FileSystem which contains the splits file * @param splitsFile The Path to the splits file * @return The number of split points * @throws IOException */ public static int getNumSplits(FileSystem fs, Path splitsFile) throws IOException { FSDataInputStream fis = fs.open(splitsFile); BufferedReader reader = new BufferedReader(new InputStreamReader(fis)); int numSplits = 0; while (reader.readLine() != null) { ++numSplits; } reader.close(); return numSplits; }
From source file:Main.java
public static String responseContentUri(URI uri) throws Exception { HttpClient client = new DefaultHttpClient(); HttpPost request = new HttpPost(); request.setURI(uri);// www. j a v a 2 s .com InputStream is = client.execute(request).getEntity().getContent(); BufferedReader inb = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(""); String line; String NL = System.getProperty("line.separator"); while ((line = inb.readLine()) != null) { sb.append(line).append(NL); } inb.close(); return sb.toString(); }