List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:bookstore.BookUnmarshaller.java
public static Book[] BooksFromCsv(File file) { InputStream in = null;//from w ww .j ava2s . c o m Book[] books; try { in = FileUtils.openInputStream(file); books = BooksFromString(IOUtils.toString(in, Charset.forName("utf-8"))); } catch (IOException | ParseException | NumberFormatException e) { return null; } finally { IOUtils.closeQuietly(in); } return books; }
From source file:com.doculibre.constellio.utils.license.ApplyLicenseUtils.java
@SuppressWarnings("unchecked") private static List<String> readLines(File file) throws IOException { FileInputStream is = new FileInputStream(file); List<String> lines = IOUtils.readLines(is); IOUtils.closeQuietly(is); return lines; }
From source file:latexstudio.editor.files.FileService.java
public static String readFromStream(InputStream stream) { try {/* w w w. j av a 2 s .c o m*/ return IOUtils.toString(stream); } catch (IOException ex) { Exceptions.printStackTrace(ex); } finally { IOUtils.closeQuietly(stream); } return null; }
From source file:com.google.gwt.site.markdown.Util.java
public static void writeStringToFile(File file, String content) throws IOException { FileOutputStream fileOutputStream = null; try {//from w ww . ja v a 2s . c om fileOutputStream = new FileOutputStream(file); IOUtils.write(content, fileOutputStream); } finally { IOUtils.closeQuietly(fileOutputStream); } }
From source file:me.ryandowling.Utils.java
public static String urlToString(String url) throws IOException { InputStream in = new URL(url).openStream(); String response = null;// ww w . j a v a 2s . com try { response = IOUtils.toString(in); } finally { IOUtils.closeQuietly(in); } return response; }
From source file:it.cnr.ilc.ilcioutils.IlcInputToString.java
/** * Convert an inputstream into a string/*from w ww. j av a2 s . co 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(CLASS_NAME).log(Level.SEVERE, message); } //System.err.println("DDDD " + theString); IOUtils.closeQuietly(is); IOUtils.closeQuietly(writer); return theString; }
From source file:net.bpelunit.util.ZipUtil.java
public static void unzipFile(File zip, File dir) throws IOException { InputStream in = null;/*from w ww.ja v a2 s. c o m*/ OutputStream out = null; ZipFile zipFile = new ZipFile(zip); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (!entry.getName().endsWith("/")) { File unzippedFile = new File(dir, entry.getName()); try { in = zipFile.getInputStream(entry); unzippedFile.getParentFile().mkdirs(); out = new FileOutputStream(unzippedFile); IOUtils.copy(in, out); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } } } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.XStreamTools.java
public static String toXML(Object object) throws IOException { Writer out = new StringWriter(); out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); XStream xStream = getXStream();//from w w w. j a v a 2 s . c om xStream.toXML(object, out); IOUtils.closeQuietly(out); return out.toString(); }
From source file:com.google.gwt.benchmark.compileserver.server.manager.CliInteractorTest.java
License:asdf
private static String getTestOutput() throws IOException { FileInputStream inputStream = null; try {//from w ww . j ava 2 s . co m inputStream = new FileInputStream(new File("./target/test-out")); String out = IOUtils.toString(inputStream); // Cut off new line char return out.substring(0, out.length() - 1); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:net.erdfelt.android.sdkfido.logging.Logging.java
public static void config() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource("logging.properties"); if (url != null) { InputStream in = null;/*from w w w.j av a 2s . c o m*/ try { in = url.openStream(); LogManager.getLogManager().readConfiguration(in); } catch (IOException e) { e.printStackTrace(System.err); } finally { IOUtils.closeQuietly(in); } } System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger"); }