List of usage examples for java.io FileReader close
public void close() throws IOException
From source file:com.telefonica.euro_iaas.sdc.util.RSASignerImpl.java
/** * Get the private key//from w ww. ja v a 2s .c om * * @param privateKey * @param keyPassword * @return * @throws IOException */ private static KeyPair readKeyPair(File privateKey, char[] keyPassword) throws IOException { FileReader fileReader = new FileReader(privateKey); PEMReader r = new PEMReader(fileReader, new DefaultPasswordFinder(keyPassword)); try { return (KeyPair) r.readObject(); } catch (IOException ex) { throw new IOException("The private key could not be decrypted", ex); } finally { r.close(); fileReader.close(); } }
From source file:com.telefonica.euro_iaas.sdc.util.RSASignerImpl.java
/** * Get the public key/*from ww w .j a v a 2 s . c o m*/ * * @param privateKey * @param keyPassword * @return * @throws IOException */ private static JCERSAPublicKey readPublicKey(File privateKey, char[] keyPassword) throws IOException { FileReader fileReader = new FileReader(privateKey); PEMReader r = new PEMReader(fileReader, new DefaultPasswordFinder(keyPassword)); try { return (JCERSAPublicKey) r.readObject(); } catch (IOException ex) { throw new IOException("The private key could not be decrypted", ex); } finally { r.close(); fileReader.close(); } }
From source file:Main.java
public static int getCurrCpuFreq() { int result = 0; FileReader fr = null; BufferedReader br = null;/*w ww. ja v a 2 s . co m*/ try { fr = new FileReader(kCpuInfoCurFreqFilePath); br = new BufferedReader(fr); String text = br.readLine(); result = Integer.parseInt(text.trim()); } 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 result; }
From source file:Main.java
public static int getMinCpuFreq() { int result = 0; FileReader fr = null; BufferedReader br = null;/*from w ww. j a v a2 s. c o m*/ try { fr = new FileReader(kCpuInfoMinFreqFilePath); br = new BufferedReader(fr); String text = br.readLine(); result = Integer.parseInt(text.trim()); } 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 result; }
From source file:Main.java
public static int getMaxCpuFreq() { int result = 0; FileReader fr = null; BufferedReader br = null;/*from w ww . j a va 2 s . c om*/ try { fr = new FileReader(kCpuInfoMaxFreqFilePath); br = new BufferedReader(fr); String text = br.readLine(); result = Integer.parseInt(text.trim()); } 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 result; }
From source file:net.sourceforge.jcctray.utils.ObjectPersister.java
public static CruiseRegistry loadCruiseRegistry(String fileName) throws IOException, SAXException { Digester digester = new Digester(); FileReader fileReader = new FileReader(fileName); digester.addRule("cruiseregistry", new ObjectCreateRule(CruiseRegistry.class)); digester.addRule("cruiseregistry/cruiseImpls/cruiseImpl", new CallMethodRule("addCruiseImpl", 0, new Class[] { Class.class })); CruiseRegistry result = (CruiseRegistry) digester.parse(fileReader); fileReader.close(); return result; }
From source file:index.IncrementIndex.java
/** * * @param path/*from w ww . java2 s . c o m*/ * @param storeIdPath * @param rs * @return */ public static boolean indexBuilding(String path, String storeIdPath, ResultSet rs, String classPath, String keyName) throws SQLException { try { Analyzer luceneAnalyzer = new StandardAnalyzer(); // ??ID?? boolean isEmpty = true; try { File file = new File(storeIdPath); if (!file.exists()) { file.createNewFile(); } FileReader fr = new FileReader(storeIdPath); BufferedReader br = new BufferedReader(fr); if (br.readLine() != null) { isEmpty = false; } br.close(); fr.close(); } catch (IOException e) { e.printStackTrace(); } //isEmpty=false? IndexWriter writer = new IndexWriter(path, luceneAnalyzer, isEmpty); String storeId = ""; boolean indexFlag = false; // ? Class c2 = Class.forName(classPath); // java.lang.reflect.Field[] fields = c2.getDeclaredFields(); while (rs.next()) { // list? Map map = new HashMap(); // ???? for (java.lang.reflect.Field field : fields) { // if (keyName.equals(field.getName())) { storeId = rs.getString(field.getName().toUpperCase()); } // ??? if (whetherExist(field.getName().toUpperCase(), rs)) { map.put(field.getName(), rs.getString(field.getName().toUpperCase())); } } writer.addDocument(Document(map)); indexFlag = true; } writer.optimize(); writer.close(); if (indexFlag) { // ?ID? writeStoreId(storeIdPath, storeId); } return true; } catch (Exception e) { e.printStackTrace(); System.out.println("" + e.getClass() + "\n ?: " + e.getMessage()); return false; } finally { if (null != rs) { rs.close(); } } }
From source file:com.ianzepp.logging.jms.service.BasicDaoTest.java
/** * TODO Method description for <code>readTableMigration()</code> * /*from w w w .ja v a 2 s . c o m*/ * @param tableName * @return */ private static String readFile(String filePath) { StringBuffer fileData = new StringBuffer(4096); try { FileReader reader = new FileReader(filePath); char[] charBuffer = new char[2048]; int readSize = -1; while ((readSize = reader.read(charBuffer)) >= 0) { fileData.append(charBuffer, 0, readSize); } reader.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return fileData.toString(); }
From source file:com.teotigraphix.caustk.utils.RuntimeUtils.java
/** * Loads a String from the File./*from ww w. jav a 2 s . c o m*/ * * @param file The location of the File to load. * @return The String loaded from the File. * @throws IOException */ public static final String loadFile(File file) throws IOException { FileReader reader = new FileReader(file); BufferedReader br = new BufferedReader(reader); StringBuffer s = new StringBuffer(); String line; while ((line = br.readLine()) != null) { s.append(line); s.append("\n"); } reader.close(); return s.toString(); }
From source file:Main.java
public static String readDeviceUUID(String devicePath) { String uuid = null;/*from ww w . jav a2 s.co m*/ File root = new File(devicePath); if (root.isDirectory()) { File uFile = new File(devicePath, ".uuid"); FileReader reader = null; try { char[] buffer = new char[36]; reader = new FileReader(uFile); reader.read(buffer, 0, buffer.length); uuid = new String(buffer); Log.d(TAG, "readDeviceUUID uuid:" + uuid); return uuid; } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } } return uuid; }