List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:io.kahu.hawaii.util.call.http.util.HttpResponseToOutputStreamWriter.java
public void writeResponseToOutputStream(HttpResponse response, OutputStream out) throws ServerException { try {// w ww . j av a 2 s.c om response.getEntity().writeTo(out); } catch (IOException e) { throw new ServerException(ServerError.IO, e); } finally { IOUtils.closeQuietly(out); } }
From source file:com.github.ibole.infrastructure.security.key.PemUtils.java
private static byte[] parsePEMFile(File pemFile) throws IOException { if (!pemFile.isFile() || !pemFile.exists()) { throw new FileNotFoundException( String.format("The file '%s' doesn't exist.", pemFile.getAbsolutePath())); }/*from w w w.ja v a 2s . c om*/ PemReader reader = null; PemObject pemObject; try { reader = new PemReader(new FileReader(pemFile)); pemObject = reader.readPemObject(); } finally { IOUtils.closeQuietly(reader); } return pemObject.getContent(); }
From source file:com.adguard.compiler.UrlUtils.java
public static String downloadString(URL url, String encoding, String userAgent) throws IOException { HttpURLConnection connection = null; InputStream inputStream = null; try {//from w w w . j ava 2 s . co m connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-Agent", userAgent); connection.connect(); inputStream = connection.getInputStream(); return IOUtils.toString(inputStream, encoding); } finally { IOUtils.closeQuietly(inputStream); if (connection != null) { connection.disconnect(); } } }
From source file:com.oneis.appserver.FileResponse.java
public void writeToOutputStream(OutputStream stream) throws IOException { InputStream in = new FileInputStream(file); try {/* w w w .jav a 2 s.c om*/ IOUtils.copy(in, stream); } finally { IOUtils.closeQuietly(in); } }
From source file:com.sap.prd.mobile.ios.mios.ScriptRunner.java
private static File copyScript(String script, File workingDirectory) throws IOException { if (!workingDirectory.exists()) if (!workingDirectory.mkdirs()) throw new IOException("Cannot create directory '" + workingDirectory + "'."); final File scriptFile = new File(workingDirectory, getScriptFileName(script)); scriptFile.deleteOnExit();// w w w . j a v a2 s . com OutputStream os = null; InputStream is = null; try { is = ScriptRunner.class.getResourceAsStream(script); if (is == null) throw new FileNotFoundException(script + " not found."); os = FileUtils.openOutputStream(scriptFile); IOUtils.copy(is, os); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } Forker.forkProcess(System.out, null, "chmod", "755", scriptFile.getCanonicalPath()); return scriptFile; }
From source file:cz.cas.lib.proarc.authentication.utils.AuthUtils.java
/** * Writes the authentication required status to the HTTP response. * @param response response/*from w w w .j a va 2s .co m*/ * @throws IOException failure * @see #HEADER_AUTHENTICATE_TYPE * @see <a href='http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/docs/Relogin.html'>SmartGWT Relogin</a> */ public static void setLoginRequiredResponse(HttpServletResponse response) throws IOException { response.setHeader(HEADER_AUTHENTICATE_TYPE, Authenticators.getInstance().getLoginType()); response.setStatus(HttpServletResponse.SC_FORBIDDEN); response.setContentType(MediaType.TEXT_HTML); InputStream res = ProarcAuthFilter.class.getResourceAsStream("loginRequiredMarker.html"); try { IOUtils.copy(res, response.getOutputStream()); res.close(); } finally { IOUtils.closeQuietly(res); } }
From source file:com.yattatech.gcm.gui.GCMSender.java
private static void loadProperties() throws IOException { InputStream inStream = null;//from w w w . jav a2s .co m try { inStream = GCMSender.class.getResourceAsStream("config.properties"); PROPERTIES.load(inStream); } finally { IOUtils.closeQuietly(inStream); } }
From source file:it.cnr.ilc.tokenizer.utils.InputToString.java
/** * Convert an inputstream into a string// ww w . j a v a 2s .com * @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(Utilities.class.getName()).log(Level.SEVERE, message); } //System.err.println("DDDD " + theString); IOUtils.closeQuietly(is); IOUtils.closeQuietly(writer); return theString; }
From source file:com.amazon.alexa.avs.audio.AudioPlayer.java
/** * Play the given input stream. Note: This method blocks. * * @param inputStream/*ww w . j a va 2 s .c o m*/ * MP3 Audio bytes to play */ public void play(InputStream inputStream) { try { Player player = new Player(inputStream); player.play(); } catch (Exception e) { log.error("An error occurred while trying to play audio", e); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:com.thoughtworks.go.util.ObjectUtil.java
public static void writeObject(Object o, File file) throws IOException { FileOutputStream outputStream = null; try {/*from www . j a v a2 s. c o m*/ outputStream = new FileOutputStream(file); writeObject(o, outputStream); } finally { IOUtils.closeQuietly(outputStream); } }