List of usage examples for java.io BufferedReader close
public void close() throws IOException
From source file:Main.java
public static int loadUserInfo(Context c) throws Exception { ArrayList<String> fileContents = new ArrayList<String>(); BufferedReader br; br = new BufferedReader(new InputStreamReader(c.openFileInput(userInfoPath))); String nextLine = br.readLine(); while (nextLine != null) { fileContents.add(nextLine);//from www .jav a 2 s . co m nextLine = br.readLine(); } br.close(); String[] info = new String[nFields]; for (int i = 0; i < nFields; i++) { info[i] = ""; } int nC = 0; for (String f : fileContents) { if (!f.equals(separator)) { info[nC] += f + eol; } else { info[nC] = info[nC].trim(); nC += 1; } } userInfo = info; return nC; }
From source file:com.github.seqware.queryengine.system.exporters.VCFDumper.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 ww. j a v a 2s . c om public static void dumpVCFFromFeatureSetID(FeatureSet fSet, String file) { BufferedWriter outputStream = null; try { if (file != null) { outputStream = new BufferedWriter(new FileWriter(file)); } else { outputStream = new BufferedWriter(new OutputStreamWriter(System.out)); } outputStream.append("#CHROM POS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n"); } catch (IOException e) { Logger.getLogger(VCFDumper.class.getName()).fatal("Exception thrown starting export to file:", e); System.exit(-1); } boolean caughtNonVCF = false; boolean mrSuccess = false; if (SWQEFactory.getQueryInterface() instanceof MRHBasePersistentBackEnd) { // hack to use VCF MR if (SWQEFactory.getModelManager() instanceof MRHBaseModelManager) { try { // pretend that the included com.github.seqware.queryengine.plugins.hbasemr.MRFeaturesByAttributesPlugin is an external plug-in Class<? extends PluginInterface> arbitraryPlugin; arbitraryPlugin = VCFDumperPlugin.class; // get a FeatureSet from the back-end QueryFuture<File> future = SWQEFactory.getQueryInterface().getFeaturesByPlugin(0, arbitraryPlugin, fSet); File get = future.get(); BufferedReader in = new BufferedReader(new FileReader(get)); IOUtils.copy(in, outputStream); in.close(); get.deleteOnExit(); outputStream.flush(); outputStream.close(); mrSuccess = true; } catch (IOException e) { // fail out on IO error Logger.getLogger(VCFDumper.class.getName()).fatal("Exception thrown exporting to file:", e); System.exit(-1); } catch (Exception e) { Logger.getLogger(VCFDumper.class.getName()) .info("MapReduce exporting failed, falling-through to normal exporting to file"); // fall-through and do normal exporting if Map Reduce exporting fails } } // TODO: clearly this should be expanded to include closing database etc } if (mrSuccess) { return; } // fall-through if plugin-fails try { for (Feature feature : fSet) { StringBuffer buffer = new StringBuffer(); boolean caught = outputFeatureInVCF(buffer, feature); if (caught) { caughtNonVCF = true; } outputStream.append(buffer); outputStream.newLine(); } outputStream.flush(); } catch (IOException e) { Logger.getLogger(VCFDumper.class.getName()).fatal("Exception thrown exporting to file:", e); System.exit(-1); } finally { IOUtils.closeQuietly(outputStream); } }
From source file:Main.java
/** * From http://stackoverflow.com/questions/9544737/read-file-from-assets *///from w w w.j av a 2 s . c om public static String readAsset(Context context, String fileName) throws IOException { BufferedReader reader = new BufferedReader( new InputStreamReader(context.getAssets().open(fileName), "UTF-8")); String line; StringBuilder stringBuilder = new StringBuilder(); while ((line = reader.readLine()) != null) stringBuilder.append(line + "\n"); reader.close(); return stringBuilder.toString(); }
From source file:dk.sdu.mmmi.hwr.group2.Utils.java
public static String readURL(String address) throws IOException { StringBuilder response = new StringBuilder(); URL url = new URL(address); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String inputLine;/*from ww w .jav a 2 s . c om*/ while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); return response.toString(); }
From source file:Main.java
public static String getBuildString() { String strValue = null;//w w w . j a v a 2 s.c om BufferedReader birReader = null; try { Process p = Runtime.getRuntime().exec("getprop ro.modversion"); birReader = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024); strValue = birReader.readLine(); birReader.close(); } catch (IOException e) { Log.e("HelperFunctions", "Unable to read property", e); } finally { if (birReader != null) { try { birReader.close(); } catch (IOException e) { Log.e("HelperFunctions", "Exception while closing the file", e); } } } return strValue; }
From source file:com.aliyun.odps.mapred.bridge.TestUtils.java
private static List<String> fileToLines(String path) { List<String> lines = new LinkedList<String>(); String line = ""; try {/* ww w . j a v a 2s . c o m*/ BufferedReader in = new BufferedReader(new FileReader(path)); while ((line = in.readLine()) != null) { lines.add(line); } in.close(); } catch (IOException e) { e.printStackTrace(); } return lines; }
From source file:Main.java
/** * Reads an XML String from an HttpURLConnection. * * @param connection/* w ww . ja va 2s . com*/ * @return * @throws IOException */ public static String readString(HttpURLConnection connection) throws IOException { StringBuffer buffer = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; while ((line = reader.readLine()) != null) { buffer.append(line); } reader.close(); return buffer.toString(); }
From source file:NewFingerServer.java
private static void readPlan(String userName, PrintWriter pw) throws Exception { FileReader file = new FileReader(userName + ".plan"); BufferedReader buff = new BufferedReader(file); boolean eof = false; pw.println("\nUser name: " + userName + "\n"); while (!eof) { String line = buff.readLine(); if (line == null) eof = true;/*from w w w . j a v a2s . co m*/ else pw.println(line); } buff.close(); }
From source file:de.dakror.scpuller.SCPuller.java
public static String getFileContents(URL u) throws IOException { String res = "", line = ""; BufferedReader br = new BufferedReader(new InputStreamReader(u.openStream())); while ((line = br.readLine()) != null) { res += line;/*from w w w . ja v a 2 s. c om*/ } br.close(); return res; }
From source file:com.oneops.transistor.test.TransistorTest.java
private static String getProcDef(String filePath) throws java.io.IOException { StringBuffer fileData = new StringBuffer(1000); BufferedReader reader = new BufferedReader(new FileReader(filePath)); char[] buf = new char[1024]; int numRead = 0; while ((numRead = reader.read(buf)) != -1) { String readData = String.valueOf(buf, 0, numRead); fileData.append(readData);//ww w. j av a 2 s. c om buf = new char[1024]; } reader.close(); return fileData.toString(); }