List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:brut.util.BrutIO.java
public static void copyAndClose(InputStream in, OutputStream out) throws IOException { try {/*from w w w .j a va2s . co m*/ IOUtils.copy(in, out); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } }
From source file:com.igormaznitsa.zxpoly.utils.Utils.java
public static Image loadIcon(final String name) { final InputStream resource = findResourceOrError("com/igormaznitsa/zxpoly/icons/" + name); try {/*from w w w. ja v a 2s . c om*/ return ImageIO.read(resource); } catch (IOException ex) { throw new Error("Can't read resource icon [" + name + ']'); } finally { IOUtils.closeQuietly(resource); } }
From source file:it.cnr.ilc.tokenizer.utils.InputToString.java
/** * Convert an inputstream into a string//from ww w .j ava 2s . c o m * @param is the inputstream * @return the string from the input */ public static String convertInputStreamToString(InputStream is) { StringWriter writer = new StringWriter(); String encoding = "UTF-8"; String message = ""; String theString = ""; try { IOUtils.copy(is, writer, encoding); theString = writer.toString(); } catch (Exception e) { message = "IOException in coverting the stream into a string " + e.getMessage(); Logger.getLogger(Utilities.class.getName()).log(Level.SEVERE, message); } //System.err.println("DDDD " + theString); IOUtils.closeQuietly(is); IOUtils.closeQuietly(writer); return theString; }
From source file:invio.util.ArquivoUtil.java
public static boolean copiarParaArquivos(UploadedFile file) { try {//from w ww . j av a2 s . co m String path = contextPath(file.getFileName()); FileOutputStream saida = new FileOutputStream(path); InputStream entrada = file.getInputstream(); IOUtils.copy(entrada, saida); IOUtils.closeQuietly(saida); IOUtils.closeQuietly(entrada); return true; } catch (IOException e) { return false; } }
From source file:com.floreantpos.ui.util.StreamUtils.java
public static String toString(InputStream in) throws IOException { if (in == null) { return ""; //$NON-NLS-1$ }/*from w w w .ja va 2 s.c o m*/ try { return IOUtils.toString(in); } finally { IOUtils.closeQuietly(in); } }
From source file:de.ocarthon.core.utility.GzipCompression.java
public static String decompress(InputStream inputStream) throws IOException { GZIPInputStream gis = null;//ww w . j a v a2 s . c o m String json; try { gis = new GZIPInputStream(inputStream); json = IOUtils.toString(gis, "UTF-8"); } finally { IOUtils.closeQuietly(gis); } return json; }
From source file:gov.nih.nci.caintegrator.application.arraydata.GeneLocationFileLoader.java
static void loadFile(GeneLocationConfiguration geneLocationConfiguration, File geneLocationFile) throws ValidationException, IOException { CSVReader geneFileReader = new CSVReader(new FileReader(geneLocationFile), DELIMITER); try {//from w w w .j a v a2s. c o m loadFile(geneLocationConfiguration, geneFileReader); } finally { IOUtils.closeQuietly(geneFileReader); } }
From source file:com.mightypocket.utils.ResourceHelper.java
public static String loadString(String name, ResourceMap resourceMap) { String result = null;/*ww w.ja va 2s . c o m*/ InputStream is = null; try { is = AShot.class.getResourceAsStream("resources/" + name); result = IOUtils.toString(is); Set<String> keySet = resourceMap.keySet(); for (String key : keySet) { String token = "${" + key + "}"; if (result.contains(token)) { String value = resourceMap.getString(key); result = result.replace(token, value); } } } catch (Exception e) { //should never be a case logger.error("Cannot load resource", e); } finally { IOUtils.closeQuietly(is); } return result; }
From source file:com.searchcode.app.util.Properties.java
public static synchronized java.util.Properties getProperties() { if (properties == null) { properties = new java.util.Properties(); FileInputStream fileInputStream = null; try {/*from ww w . j a v a 2s . co m*/ fileInputStream = new FileInputStream(Values.PROPERTIES_FILE_NAME); properties.load(fileInputStream); } catch (IOException e) { // TODO Use second 'stdout' logger here, because ctor LoggerWrapper call this method Singleton.getLogger().severe( "Unable to load 'searchcode.properties' file. Will resort to defaults for all values."); } finally { IOUtils.closeQuietly(fileInputStream); } } return properties; }
From source file:cn.guoyukun.spring.utils.FileCharset.java
/** * ??GBKUTF-16LEUTF-16BE,UTF-8window???ANSI,Unicode,Unicode big endian,UTF-8 * * @param file/*from w ww .j a v a2 s .com*/ * @return */ public static String getCharset(File file) { InputStream is = null; try { is = new FileInputStream(file); return getCharset(new BufferedInputStream(is)); } catch (FileNotFoundException e) { return DEFAULT_CHARSET; } finally { IOUtils.closeQuietly(is); } }