List of usage examples for java.io FileReader close
public void close() throws IOException
From source file:org.apache.hadoop.mapred.LinuxUtilizationGauger.java
/** * Read a file line by line/*from ww w . j av a 2 s. c o m*/ * @param fileName * @return String[] contains lines * @throws IOException */ private String[] readFile(String fileName) throws IOException { ArrayList<String> result = new ArrayList<String>(); FileReader fReader = new FileReader(fileName); BufferedReader bReader = new BufferedReader(fReader); while (true) { String line = bReader.readLine(); if (line == null) { break; } result.add(line); } bReader.close(); fReader.close(); return (String[]) result.toArray(new String[result.size()]); }
From source file:it.crs4.seal.read_sort.MergeAlignments.java
private void calculateChecksums() throws IOException { if (generatedMd5) { log.info("Calculating reference checksum..."); log.info("Reference fasta path: " + referenceRootPath.toString()); checksums = new FastaChecksummer(); FileReader reader = new FileReader(new File(referenceRootPath.toUri())); try {//w ww . j a v a 2s . c o m checksums.setInput(reader); checksums.calculate(); } finally { reader.close(); } log.info("checksum complete"); } }
From source file:org.hyperic.hq.autoinventory.ScanState.java
private static void loadInstalldirExcludes() { String path = System.getProperty("user.home") + File.separator + ".hq" + File.separator + "installdir.excludes"; File excludes = new File(path); if (!excludes.exists()) { return;/*ww w . j a va2s .c om*/ } FileReader is = null; try { is = new FileReader(excludes); BufferedReader in = new BufferedReader(is); String line; while ((line = in.readLine()) != null) { line = line.trim(); if (line.length() == 0) { continue; } if (line.charAt(0) == '#') { continue; } if (line.endsWith("*")) { line = line.substring(0, line.length() - 1); installdirExcludesPrefixes.add(line); } installdirExcludes.put(line, Boolean.TRUE); } } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } }
From source file:org.callistasoftware.maven.plugins.propertyscanner.MyMojo.java
private Properties loadProperties(Log logger) throws MojoExecutionException { FilenameFilter filter = new SuffixFileFilter(".properties"); Properties allProperties = new Properties(); for (File propertiesDirectory : propertiesDirectories) { if (!propertiesDirectory.exists()) { throw new MojoExecutionException("Could not find properties directory: " + propertiesDirectory); }//from w ww . ja v a2 s .c o m File[] propertiesFiles = propertiesDirectory.listFiles(filter); for (File propertiesFile : propertiesFiles) { if (!propertiesFile.exists()) { throw new MojoExecutionException("Could not find properties file: " + propertiesFile); } //loading properties Properties properties = new Properties(); FileReader r = null; try { r = new FileReader(propertiesFile); properties.load(r); } catch (IOException e) { throw new MojoExecutionException( "Error loading properties from translation file: " + propertiesFile, e); } finally { try { r.close(); } catch (Exception e) { //nothing } } logger.debug("Loaded properties, read " + properties.size() + " entries"); allProperties.putAll(properties); } } logger.info("Total properties loaded: " + allProperties.size()); return allProperties; }
From source file:gov.nih.nci.caintegrator.domain.analysis.GisticGeneMapFileParser.java
/** * @param inputFile input file//w ww . ja v a2 s. c o m * @throws IOException IO exception * @return gene map to wide peak boundaries */ public Map<String, List<Gene>> parse(File inputFile) throws IOException { FileReader fileReader = new FileReader(inputFile); CSVReader csvReader = new CSVReader(fileReader, '\t'); String[] fields; while ((fields = csvReader.readNext()) != null) { if (WIDE_PEAK_BOUNDARIES.equalsIgnoreCase(fields[0].trim())) { processBoundaries(fields); } else if (GENES_IN_WIDE_PEAK.equalsIgnoreCase(fields[0].trim()) || StringUtils.isBlank(fields[0])) { processGene(fields); } } csvReader.close(); fileReader.close(); removeBoundariesWithNoGenes(); FileUtils.deleteQuietly(inputFile); return geneMap; }
From source file:com.hiqes.android.demopermissionsm.ui.ProgLogFragment.java
public void doLoadFile(String filePath) { String errMsg;/*from w ww. j a va2 s . c om*/ Context ctx = getActivity(); try { File inFile = new File(filePath); FileReader reader = new FileReader(inFile); char[] text = new char[(int) inFile.length()]; int readCount = reader.read(text); if (readCount != inFile.length()) { errMsg = ctx.getString(R.string.warn_file_truncated); Toast.makeText(getActivity(), R.string.warn_file_truncated, Toast.LENGTH_LONG).show(); Logger.w(TAG, errMsg); } Logger.d(TAG, "Read contents from log: " + inFile.getName()); reader.close(); mLoadedLog.setText(text, 0, readCount); } catch (FileNotFoundException e) { Logger.e(TAG, "Unable to open file: " + filePath); errMsg = ctx.getString(R.string.err_file_not_found); Toast.makeText(getActivity(), errMsg, Toast.LENGTH_LONG).show(); } catch (IOException e) { Logger.e(TAG, "Failed to read saved file: " + e.getMessage()); errMsg = ctx.getString(R.string.err_file_read); Toast.makeText(getActivity(), errMsg, Toast.LENGTH_LONG).show(); } }
From source file:com.bigdata.rdf.sail.webapp.AbstractTestNanoSparqlClient.java
protected static Graph readGraphFromFile(final File file) throws RDFParseException, RDFHandlerException, IOException { final RDFFormat format = RDFFormat.forFileName(file.getName()); final RDFParserFactory rdfParserFactory = RDFParserRegistry.getInstance().get(format); if (rdfParserFactory == null) { throw new RuntimeException("Parser not found: file=" + file + ", format=" + format); }//ww w.jav a 2 s .co m final RDFParser rdfParser = rdfParserFactory.getParser(); rdfParser.setValueFactory(new ValueFactoryImpl()); rdfParser.setVerifyData(true); rdfParser.setStopAtFirstError(true); rdfParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); final StatementCollector rdfHandler = new StatementCollector(); rdfParser.setRDFHandler(rdfHandler); /* * Run the parser, which will cause statements to be * inserted. */ final FileReader r = new FileReader(file); try { rdfParser.parse(r, file.toURI().toString()/* baseURL */); } finally { r.close(); } final Graph g = new GraphImpl(); g.addAll(rdfHandler.getStatements()); return g; }
From source file:com.webcohesion.enunciate.EnunciateConfiguration.java
public String readGeneratedCodeLicenseFile() { License license = getGeneratedCodeLicense(); String filePath = license == null ? null : license.getFile(); if (filePath == null) { return null; }//from w ww.j a v a 2 s . co m File file = resolveFile(filePath); try { FileReader reader = new FileReader(file); StringWriter writer = new StringWriter(); char[] chars = new char[100]; int read = reader.read(chars); while (read >= 0) { writer.write(chars, 0, read); } reader.close(); writer.close(); return writer.toString(); } catch (IOException e) { throw new EnunciateException(e); } }
From source file:org.apache.archiva.policies.ChecksumPolicyTest.java
/** * Read the first line from the checksum file, and return it (trimmed). *//*from w w w . j a va 2 s . c o m*/ private String readChecksumFile(File checksumFile) throws Exception { FileReader freader = null; BufferedReader buf = null; try { freader = new FileReader(checksumFile); buf = new BufferedReader(freader); return buf.readLine(); } finally { if (buf != null) { buf.close(); } if (freader != null) { freader.close(); } } }
From source file:org.apache.flink.streaming.python.api.PythonStreamBinder.java
/** * Naive MD5 calculation from the python content of the given script. Spaces, blank lines and comments * are ignored./*from w ww .j a v a 2 s .c o m*/ * * @param filePath the full path of the given python script * @return the md5 value as a string * @throws NoSuchAlgorithmException * @throws IOException */ private String calcPythonMd5(String filePath) throws NoSuchAlgorithmException, IOException { FileReader fileReader = new FileReader(filePath); BufferedReader bufferedReader = new BufferedReader(fileReader); String line; MessageDigest md = MessageDigest.getInstance("MD5"); while ((line = bufferedReader.readLine()) != null) { line = line.trim(); if (line.isEmpty() || line.startsWith("#")) { continue; } byte[] bytes = line.getBytes(); md.update(bytes, 0, bytes.length); } fileReader.close(); byte[] mdBytes = md.digest(); //convert the byte to hex format method 1 StringBuffer sb = new StringBuffer(); for (int i = 0; i < mdBytes.length; i++) { sb.append(Integer.toString((mdBytes[i] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); }