List of usage examples for org.apache.commons.io IOUtils copy
public static void copy(Reader input, OutputStream output) throws IOException
Reader
to bytes on an OutputStream
using the default character encoding of the platform, and calling flush. From source file:com.digitalreasoning.herman.JarCreater.java
public static void createJar(File outputJarFile, List<Entry> entries) throws IOException { if (!outputJarFile.getParentFile().exists()) { outputJarFile.getParentFile().mkdirs(); }//from www . j a v a 2 s . c o m if (!outputJarFile.exists()) { outputJarFile.createNewFile(); } FileOutputStream fOut = new FileOutputStream(outputJarFile); JarOutputStream jarOut = new JarOutputStream(fOut); Set<String> packageSet = new HashSet<String>(); try { for (Entry folderFile : entries) { InputStream inputStream = folderFile.resource.openStream(); try { if (!packageSet.contains(folderFile.parentFolderName)) { jarOut.putNextEntry(new ZipEntry(folderFile.parentFolderName)); jarOut.closeEntry(); packageSet.add(folderFile.parentFolderName); } jarOut.putNextEntry(new ZipEntry(folderFile.parentFolderName + (folderFile.parentFolderName.endsWith("/") ? "" : "/") + folderFile.fileName)); IOUtils.copy(inputStream, jarOut); jarOut.closeEntry(); } finally { inputStream.close(); } } } finally { jarOut.close(); fOut.close(); } }
From source file:com.abstratt.graphviz.GraphViz.java
public static void generate(final InputStream input, String format, int dimensionX, int dimensionY, IPath outputLocation) throws CoreException { MultiStatus status = new MultiStatus(GraphVizActivator.ID, 0, "Errors occurred while running Graphviz", null);//from www .ja va2s . c o m File dotInput = null, dotOutput = outputLocation.toFile(); // we keep the input in memory so we can include it in error messages ByteArrayOutputStream dotContents = new ByteArrayOutputStream(); try { // determine the temp input location dotInput = File.createTempFile(TMP_FILE_PREFIX, DOT_EXTENSION); // dump the contents from the input stream into the temporary file // to be submitted to dot FileOutputStream tmpDotOutputStream = null; try { IOUtils.copy(input, dotContents); tmpDotOutputStream = new FileOutputStream(dotInput); IOUtils.copy(new ByteArrayInputStream(dotContents.toByteArray()), tmpDotOutputStream); } finally { IOUtils.closeQuietly(tmpDotOutputStream); } IStatus result = runDot(format, dimensionX, dimensionY, dotInput, dotOutput); if (dotOutput.isFile() && dotOutput.length() > 0) { if (!result.isOK() && Platform.inDebugMode()) LogUtils.log(status); // success! return; } } catch (IOException e) { status.add(new Status(IStatus.ERROR, GraphVizActivator.ID, "", e)); } finally { dotInput.delete(); IOUtils.closeQuietly(input); } throw new CoreException(status); }
From source file:ee.ria.DigiDoc.configuration.Configuration.java
private static void unpackSchema(Context context) { File schemaPath = FileUtils.getSchemaCacheDirectory(context); try (ZipInputStream zis = new ZipInputStream(context.getResources().openRawResource(R.raw.schema))) { ZipEntry ze;//from ww w. ja v a2s.c o m while ((ze = zis.getNextEntry()) != null) { File entryFile = new File(schemaPath, ze.getName()); FileOutputStream out = new FileOutputStream(entryFile); IOUtils.copy(zis, out); out.close(); } } catch (IOException e) { Timber.e(e, "Library configuration initialization failed"); } }
From source file:com.none.tom.simplerssreader.net.FeedDownloader.java
private static InputStream getInputStream(final InputStream in) throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); if (IOUtils.copy(in, out) > CURRENT_FEED_SIZE_LIMIT) { ErrorHandler.setErrno(ErrorHandler.ERROR_HTTP_FILE_SIZE); LogUtils.logError("Feed size limit exceeded" + '(' + CURRENT_FEED_SIZE_LIMIT + ')'); return null; }//from w w w .jav a 2 s . c o m in.close(); return new ByteArrayInputStream(out.toByteArray()); }
From source file:com.atlassian.connector.eclipse.team.ui.AbstractTeamUiConnector.java
protected byte[] getResourceContent(InputStream is) { final ByteArrayOutputStream out = new ByteArrayOutputStream(); try {//from w w w.j ava 2s . c om IOUtils.copy(is, out); return out.toByteArray(); } catch (IOException e) { return new byte[0]; } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(out); } }
From source file:com.epam.wilma.test.server.compress.gzip.GzipDecompressor.java
/** * Decompresses an input stream from gzip. * @param body the inputstream that is decompressed. * @return the decompressed {@link ByteArrayOutputStream} *//* w w w . j av a2s . co m*/ public ByteArrayOutputStream decompress(final InputStream body) { ByteArrayOutputStream writer = new ByteArrayOutputStream(); try { GZIPInputStream gzipStream = new GZIPInputStream(body); IOUtils.copy(gzipStream, writer); } catch (IOException e) { logger.error("Error when decompress inputStream, exception message:" + e.getMessage()); } return writer; }
From source file:com.youTransactor.uCube.mdm.task.SendLogsTask.java
@Override protected void start() { HttpURLConnection urlConnection = null; try {/*from ww w .j a v a2s . com*/ urlConnection = MDMManager.getInstance().initRequest(SEND_LOGS_WS + deviceInfos.getPartNumber() + '/' + deviceInfos.getSerial() + "?type=" + fileType, MDMManager.POST_METHOD); urlConnection.setRequestProperty("Content-Type", "application/octet-stream"); OutputStream output = urlConnection.getOutputStream(); IOUtils.copy(in, output); HTTPResponseCode = urlConnection.getResponseCode(); if (HTTPResponseCode == 200) { notifyMonitor(TaskEvent.SUCCESS); return; } LogManager.debug(GetConfigTask.class.getSimpleName(), "send logs WS error: " + HTTPResponseCode); } catch (Exception e) { LogManager.debug(GetConfigTask.class.getSimpleName(), "\"send logs WS error", e); } finally { if (urlConnection != null) { urlConnection.disconnect(); } } notifyMonitor(TaskEvent.FAILED, this); }
From source file:fr.putnami.pwt.plugin.ajaxbot.controller.SiteMapController.java
@RequestMapping(value = "/sitemap.txt", method = RequestMethod.GET) public void welcomePage(HttpServletResponse response) { try {/*from w w w . j a v a 2s .co m*/ InputStream is = new FileInputStream(sitemap); response.setContentType("text/plain"); response.setContentLength((int) sitemap.length()); IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); } catch (IOException ex) { throw new RuntimeException("IOError writing file to output stream", ex); } }
From source file:eu.peppol.document.PayloadDigestCalculator.java
public static MessageDigestResult calcDigest(String algorithm, StandardBusinessDocumentHeader sbdh, InputStream inputStream) { MessageDigest messageDigest;/*from w ww.j a v a 2 s. c om*/ try { messageDigest = MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException( "Unknown digest algorithm " + OxalisConstant.DEFAULT_DIGEST_ALGORITHM + " " + e.getMessage(), e); } InputStream inputStreamToCalculateDigestFrom = null; ManifestItem manifestItem = SbdhFastParser.searchForAsicManifestItem(sbdh); if (manifestItem != null) { // creates an FilterInputStream, which will extract the ASiC in binary format. inputStreamToCalculateDigestFrom = new Base64InputStream(new AsicFilterInputStream(inputStream)); } else inputStreamToCalculateDigestFrom = inputStream; DigestInputStream digestInputStream = new DigestInputStream( new BufferedInputStream(inputStreamToCalculateDigestFrom), messageDigest); try { IOUtils.copy(digestInputStream, new NullOutputStream()); } catch (IOException e) { throw new IllegalStateException("Unable to calculate digest for payload"); } return new MessageDigestResult(messageDigest.digest(), messageDigest.getAlgorithm()); }
From source file:edu.scripps.fl.pubchem.app.cids.WriteSDFStage.java
@Override public void process(Object obj) throws StageException { URL url = (URL) obj;/*w w w. jav a2s . com*/ try { File outputFile = newOutputFile(counter.incrementAndGet()); logger.info("Writing SDF file: " + outputFile); IOUtils.copy(new GZIPInputStream(url.openStream()), FileUtils.openOutputStream(outputFile)); emit(outputFile); } catch (Exception ex) { throw new StageException(this, ex); } }