List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:com.esri.gpt.framework.robots.BotsParserTest.java
@Before public void setUp() throws IOException { InputStream inputRobots = Thread.currentThread().getContextClassLoader() .getResourceAsStream("com/esri/gpt/framework/robots/robots.txt"); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); IOUtils.copy(inputRobots, buffer);//from w w w .ja v a 2 s .com IOUtils.closeQuietly(inputRobots); IOUtils.closeQuietly(buffer); robotsTxt = buffer.toString("UTF-8"); }
From source file:applica.framework.licensing.LicenseManager.java
public void generateLicenseFile(String user, Date validity, String path) throws LicenseGenerationException { License license = new License(user, validity); license.generate();/*from w w w .ja v a2 s . co m*/ FileOutputStream out = null; try { out = new FileOutputStream(path); IOUtils.write(license.getBytes(), out); } catch (FileNotFoundException e) { throw new LicenseGenerationException(e); } catch (IOException e) { throw new LicenseGenerationException(e); } finally { if (out != null) { IOUtils.closeQuietly(out); } } }
From source file:com.igormaznitsa.zxpoly.utils.ROMLoader.java
static byte[] loadHTTPArchive(final String url) throws IOException { final HttpClient client = HttpClientBuilder.create().build(); final HttpContext context = HttpClientContext.create(); final HttpGet get = new HttpGet(url); final HttpResponse response = client.execute(get, context); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { InputStream in = null;//from w w w . j a va 2s .c om try { final HttpEntity entity = response.getEntity(); in = entity.getContent(); final byte[] data = entity.getContentLength() < 0L ? IOUtils.toByteArray(entity.getContent()) : IOUtils.toByteArray(entity.getContent(), entity.getContentLength()); return data; } finally { IOUtils.closeQuietly(in); } } else { throw new IOException("Can't download from http '" + url + "' code [" + url + ']'); } }
From source file:com.t3.net.LocalLocation.java
@Override public void putContent(InputStream content) throws IOException { try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(getFile()))) { IOUtils.copy(content, out);//w w w. ja v a 2 s . c o m IOUtils.closeQuietly(content); } }
From source file:net.rptools.maptool.client.AppSetup.java
/** * Overwrites any existing README file in the ~/.maptool/resource directory with the one from the current MapTool * JAR file. This way any updates to the README will eventually be seen by the user, although only when a new * directory is added to the resource library... * /*from w ww .ja v a2 s.co m*/ * @throws IOException */ private static void createREADME() throws IOException { File outFilename = new File(AppConstants.UNZIP_DIR, "README"); InputStream inStream = null; OutputStream outStream = null; try { inStream = AppSetup.class.getResourceAsStream("README"); outStream = new BufferedOutputStream(new FileOutputStream(outFilename)); IOUtils.copy(inStream, outStream); } finally { IOUtils.closeQuietly(inStream); IOUtils.closeQuietly(outStream); } }
From source file:eionet.cr.util.FileUtil.java
/** * Downloads the contents of the given URL into the given file and closes the file. * * @param urlString downloadable url//from w ww . j ava2s . c om * @param toFile output file location * @throws IOException if input of output fails */ public static void downloadUrlToFile(final String urlString, final File toFile) throws IOException { URLConnection urlConnection = null; InputStream inputStream = null; try { URL url = new URL(urlString == null ? urlString : StringUtils.replace(urlString, " ", "%20")); urlConnection = url.openConnection(); urlConnection.setRequestProperty("Connection", "close"); inputStream = urlConnection.getInputStream(); FileUtil.streamToFile(inputStream, toFile); } finally { IOUtils.closeQuietly(inputStream); URLUtil.disconnect(urlConnection); } }
From source file:com.mirth.connect.donkey.server.data.jdbc.XmlQuerySource.java
public void load(String xmlFile) throws XmlQuerySourceException { Document document = null;//from w w w.j ava 2s . c o m try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = dbf.newDocumentBuilder(); InputStream is = ResourceUtil.getResourceStream(XmlQuerySource.class, xmlFile); document = documentBuilder.parse(is); IOUtils.closeQuietly(is); } catch (Exception e) { throw new XmlQuerySourceException("Failed to read query file: " + xmlFile, e); } NodeList queryNodes = document.getElementsByTagName("query"); int queryNodeCount = queryNodes.getLength(); for (int i = 0; i < queryNodeCount; i++) { Node node = queryNodes.item(i); if (node.hasAttributes()) { Attr attr = (Attr) node.getAttributes().getNamedItem("id"); if (attr != null) { String query = StringUtils.trim(node.getTextContent()); if (query.length() > 0) { queries.put(attr.getValue(), query); } } } } }
From source file:be.isl.desamouryv.sociall.service.FileServiceImpl.java
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) @Override/*from www . j av a2 s .com*/ public String storeFile(InputStream input, String fileName, String uploadPath) throws IOException { logger.log(Level.INFO, "uploadPath: {0}", uploadPath); String prefix = FilenameUtils.getBaseName(fileName).replaceAll(" ", ""); String suffix = FilenameUtils.getExtension(fileName); File tempFile = File.createTempFile(prefix + "-", "." + suffix, new File(uploadPath)); OutputStream output = new FileOutputStream(tempFile); try { IOUtils.copy(input, output); } finally { IOUtils.closeQuietly(output); IOUtils.closeQuietly(input); } logger.log(Level.INFO, "file uploaded at: {0}", tempFile.getAbsolutePath()); return tempFile.getName(); }
From source file:com.ms.commons.test.classloader.util.AntxconfigUtil.java
private static void writeUrlToFile(URL url, File file) throws Exception { InputStream in = url.openStream(); String str = IOUtils.toString(in, ENDODING); str = str.replaceAll("description=\".*\"", "description=\"\""); IOUtils.closeQuietly(in); FileUtils.writeStringToFile(file, str, ENDODING); }
From source file:net.dontdrinkandroot.utils.resource.CachedFileResource.java
@Override public void write(final OutputStream os) throws IOException { final FileInputStream fis = new FileInputStream(this.file); IOUtils.copy(fis, os);// ww w .j a v a2s . c om IOUtils.closeQuietly(fis); }