List of usage examples for java.io FileReader close
public void close() throws IOException
From source file:com.serotonin.bacnet4j.util.sero.StreamUtils.java
public static String readFile(File file) throws IOException { FileReader in = null; try {//from w w w . j a v a2 s .c o m in = new FileReader(file); StringWriter out = new StringWriter(); transfer(in, out); return out.toString(); } finally { if (in != null) in.close(); } }
From source file:Main.java
public static String getCpuName() { FileReader fr = null; BufferedReader br = null;//from w ww . ja va 2 s.c o m try { fr = new FileReader("/proc/cpuinfo"); br = new BufferedReader(fr); String text = br.readLine(); String[] array = text.split(":\\s+", 2); for (int i = 0; i < array.length; i++) { } return array[1]; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (fr != null) try { fr.close(); } catch (IOException e) { e.printStackTrace(); } if (br != null) try { br.close(); } catch (IOException e) { e.printStackTrace(); } } return null; }
From source file:com.applerox.jack.AppleCommands.AppleCommands.java
public static boolean resetConfigFile(File configFile, boolean deleteOld) { if (deleteOld && configFile.exists()) { configFile.delete();// w w w. ja v a2 s .c o m try { //createDefaultItems(configFile, defaults); return true; } catch (Exception e) { ac.logger .severe("[AppleCommands] Failed to reset configuration! Let AppleCommands devs know this:"); e.printStackTrace(); } } else if (configFile.exists() && !deleteOld) { try { FileReader instream = new FileReader(configFile); FileWriter outstream = new FileWriter(configFile); BufferedReader reader = new BufferedReader(instream); BufferedWriter writer = new BufferedWriter(outstream); //for (line : reader.getLines()) { // li //} instream.close(); outstream.close(); } catch (Exception e) { ac.logger .severe("[AppleCommands] Failed to reset configuration! Let AppleCommands devs know this!"); e.printStackTrace(); } } else if (!configFile.exists()) { try { configFile.createNewFile(); } catch (Exception e) { ac.logger.severe( "[AppleCommands] Failed to create configuration file! Let AppleCommands devs know this!"); } } return true; }
From source file:net.rptools.lib.FileUtil.java
@SuppressWarnings("unchecked") public static List<String> getLines(File file) throws IOException { List<String> list; FileReader fr = new FileReader(file); try {// ww w. j a v a2 s . com list = IOUtils.readLines(fr); } finally { fr.close(); } return list; }
From source file:com.dbmojo.Util.java
/** Read a file into a String */ public static String fileToString(String file) throws IOException { StringBuilder lines = new StringBuilder(); FileReader fileReader = null; BufferedReader bufferedReader = null; String line = null;/* w w w. ja v a 2 s . com*/ try { fileReader = new FileReader(file); bufferedReader = new BufferedReader(fileReader); while ((line = bufferedReader.readLine()) != null) { lines.append(line); } } finally { if (bufferedReader != null) { bufferedReader.close(); } if (fileReader != null) { fileReader.close(); } } return lines.toString(); }
From source file:org.globus.workspace.groupauthz.Group.java
private static String gRead(String fileName) throws IOException { final StringBuffer sb = new StringBuffer(16); FileReader fr = null; BufferedReader br = null;//w w w . j a v a 2s . c o m try { fr = new FileReader(fileName); br = new BufferedReader(fr); String s = br.readLine(); while (s != null) { sb.append(s); sb.append("\n"); s = br.readLine(); } } finally { if (fr != null) { fr.close(); } if (br != null) { br.close(); } } return sb.toString(); }
From source file:com.netcrest.pado.internal.security.AESCipher.java
private static byte[] getUserPrivateKey() throws IOException { byte[] privateKey = null; String estr;/*from www .j av a 2s .c om*/ String certificateFilePath = PadoUtil.getProperty(Constants.PROP_SECURITY_AES_USER_CERTIFICATE, "security/user.cer"); if (certificateFilePath.startsWith("/") == false) { // TODO: Make server files relative to PADO_HOME also. if (PadoUtil.isPureClient()) { String padoHome = PadoUtil.getProperty(Constants.PROP_HOME_DIR); certificateFilePath = padoHome + "/" + certificateFilePath; } } File file = new File(certificateFilePath); if (file.exists() == false) { FileWriter writer = null; try { privateKey = AESCipher.getPrivateKey(); Base64 base64 = new Base64(0); // no line breaks estr = base64.encodeToString(privateKey); writer = new FileWriter(file); writer.write(estr); } finally { if (writer != null) { writer.close(); } } } else { FileReader reader = null; try { reader = new FileReader(file); StringBuffer buffer = new StringBuffer(2048); int c; while ((c = reader.read()) != -1) { buffer.append((char) c); } estr = buffer.toString(); } finally { if (reader != null) { reader.close(); } } } Base64 base64 = new Base64(0); // no line breaks privateKey = base64.decode(estr); return privateKey; }
From source file:org.apache.hyracks.control.cc.ClusterControllerService.java
private static ClusterTopology computeClusterTopology(CCConfig ccConfig) throws Exception { if (ccConfig.getClusterTopology() == null) { return null; }//from w w w . j ava 2 s. co m FileReader fr = new FileReader(ccConfig.getClusterTopology()); InputSource in = new InputSource(fr); try { return TopologyDefinitionParser.parse(in); } finally { fr.close(); } }
From source file:org.eclipse.orion.internal.server.core.metastore.SimpleMetaStoreUtil.java
/** * Get the JSON from the MetaFile in the provided parent folder. * @param parent The parent folder./*from w ww. j av a 2s . c o m*/ * @param name The name of the MetaFile * @return The JSON containing the data in the MetaFile. */ public static JSONObject readMetaFile(File parent, String name) { JSONObject jsonObject; try { if (!isMetaFile(parent, name)) { return null; } File savedFile = retrieveMetaFile(parent, name); FileReader fileReader = new FileReader(savedFile); char[] chars = new char[(int) savedFile.length()]; fileReader.read(chars); fileReader.close(); jsonObject = new JSONObject(new String(chars)); } catch (FileNotFoundException e) { throw new RuntimeException("Meta File Error, file not found", e); } catch (IOException e) { throw new RuntimeException("Meta File Error, file IO error", e); } catch (JSONException e) { throw new RuntimeException("Meta File Error, could not build JSON", e); } return jsonObject; }
From source file:de.uni_rostock.goodod.tools.Configuration.java
private static boolean isXMLConfig(File confFile) throws FileNotFoundException, IOException { FileReader reader = new FileReader(confFile); char beginning[] = new char[7]; // we search for "<?xml" but need two additional characters to accommodate a potential BOM reader.read(beginning, 0, 7);/*from w w w. j av a 2 s . c o m*/ if (('<' == beginning[0]) && ('?' == beginning[1]) && ('x' == beginning[2]) && ('m' == beginning[3]) && ('l' == beginning[4])) { reader.close(); return true; } // Case with byte order mark: if (('<' == beginning[2]) && ('?' == beginning[3]) && ('x' == beginning[4]) && ('m' == beginning[5]) && ('l' == beginning[6])) { reader.close(); return true; } reader.close(); return false; }