List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.MD5ChecksumCreatorFastTest.java
public void setUp() throws FileNotFoundException { PrintWriter writer = null;/*w w w. j a v a 2 s . co m*/ try { testFile = new File(TEST_FILE_NAME); //noinspection IOResourceOpenedButNotSafelyClosed writer = new PrintWriter(testFile); writer.print(TEST_CHECKSUM_TEXT); } finally { IOUtils.closeQuietly(writer); } }
From source file:MdDetect.java
/** * Convenience function to grab STDIN// w ww . j ava2s .c o m * * @return strings of lines from STDIN */ static List<String> getSysIn() { InputStreamReader inputStreamReader = null; try { // initialize the stream reader inputStreamReader = new InputStreamReader(System.in); // load it into a buffer BufferedReader bufferedReader = new BufferedReader(inputStreamReader); // init the out list List<String> input = new ArrayList<>(); String line; while (null != ( // iterate lines line = bufferedReader.readLine())) { input.add(line); } return input; } catch (IOException e) { // bail throw new RuntimeException(e.getCause()); } finally { if (null != inputStreamReader) { IOUtils.closeQuietly(inputStreamReader); } } }
From source file:com.igormaznitsa.zxpoly.components.RomData.java
public static RomData read(final InputStream in) throws IOException { try {// w ww . java 2 s . co m return new RomData(IOUtils.toByteArray(in)); } finally { IOUtils.closeQuietly(in); } }
From source file:com.yattatech.io.ShalomFileWriter.java
public boolean write(Seminary seminary) { final String path = seminary.getFilePath(); final String json = new Gson().toJson(seminary); boolean sucess = true; DataOutputStream out = null;//from ww w . j av a 2 s. c o m try { out = new DataOutputStream(new FileOutputStream(path)); out.writeLong(ChecksumCalculator.calculateChecksum(json)); out.writeUTF("\n"); out.writeUTF(json); } catch (IOException ioe) { LOGGER.log(Level.SEVERE, ioe.getMessage()); sucess = false; } finally { IOUtils.closeQuietly(out); return sucess; } }
From source file:acromusashi.kafka.log.producer.util.YamlReadUtil.java
/** * ???Yaml????Yaml?//w w w. j a v a 2 s . co m * * @param filePath * @return ??? * @throws IOException */ @SuppressWarnings({ "unchecked" }) public static Map<String, Object> readYaml(String filePath) throws IOException { Map<String, Object> configObject = null; Yaml yaml = new Yaml(); InputStream inputStream = null; InputStreamReader steamReader = null; File file = new File(filePath); try { inputStream = new FileInputStream(file.getAbsolutePath()); steamReader = new InputStreamReader(inputStream, "UTF-8"); configObject = (Map<String, Object>) yaml.load(steamReader); } catch (Exception ex) { // ScannerException/IOException????? // 2???????????????Exception????? throw new IOException(ex); } finally { IOUtils.closeQuietly(inputStream); } return configObject; }
From source file:com.adobe.acs.commons.redirectmaps.impl.RedirectEntriesUtils.java
protected static final List<String> readEntries(SlingHttpServletRequest request) throws IOException { List<String> lines = null; InputStream is = null;/*from w w w.j av a 2 s. c o m*/ try { is = request.getResource().getChild(RedirectMapModel.MAP_FILE_NODE).adaptTo(InputStream.class); lines = IOUtils.readLines(is); log.debug("Loaded {} lines", lines.size()); } finally { IOUtils.closeQuietly(is); } return lines; }
From source file:com.alibaba.stonelab.toolkit.autoconf.AutoconfTemplate.java
private void parser() throws Exception { InputStream in = new FileInputStream(file); String content = IOUtils.toString(in); IOUtils.closeQuietly(in); props.addAll(AutoconfUtil.parsePlaceholder(content)); }
From source file:es.bsc.demiurge.core.utils.CommandExecutor.java
/** * Executes a system command./*w w w. ja v a 2 s .c om*/ * * @param command the command * @return the result of executing the command */ public static String executeCommand(String command) throws IOException, InterruptedException { StringBuilder result = new StringBuilder(); Process p; BufferedReader reader = null; try { p = Runtime.getRuntime().exec(command); p.waitFor(); reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = reader.readLine()) != null) { result.append(line); result.append(System.getProperty("line.separator")); } return result.toString(); } finally { IOUtils.closeQuietly(reader); } }
From source file:net.mikaboshi.intra_mart.tools.log_stats.Application.java
private Application() { InputStream inStream = null;/*from w w w.j a va2 s . com*/ try { inStream = this.getClass().getResourceAsStream("im-log-stats.properties"); this.config.load(inStream); } catch (IOException e) { throw new Error(e); } finally { IOUtils.closeQuietly(inStream); } }
From source file:it.cnr.ilc.ilcioutils.IlcInputToString.java
/** * Convert an inputstream into a string/*w w w .ja v a 2 s . c om*/ * * @param theUrl the url to get the context from * @return the string from the input */ public static String convertInputStreamFromUrlToString(String theUrl) { StringWriter writer = new StringWriter(); InputStream is = null; String encoding = "UTF-8"; String message = ""; String theString = ""; try { is = new URL(theUrl).openStream(); IOUtils.copy(is, writer, encoding); theString = writer.toString(); } catch (Exception e) { message = "IOException in coverting the stream into a string " + e.getMessage(); Logger.getLogger(CLASS_NAME).log(Level.SEVERE, message); } //System.err.println("DDDD " + theString); IOUtils.closeQuietly(is); IOUtils.closeQuietly(writer); return theString; }