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:brut.util.BrutIO.java
public static void copy(ZipFile inputFile, ZipOutputStream outputFile, ZipEntry entry) throws IOException { try (InputStream is = inputFile.getInputStream(entry)) { IOUtils.copy(is, outputFile); }//from w w w . j av a2s .c o m }
From source file:com.openkm.util.ArchiveUtils.java
/** * Create ZIP archive from file/*from www. ja v a 2 s. c om*/ */ public static void createZip(File path, OutputStream os) throws IOException { log.debug("createZip({}, {})", new Object[] { path, os }); if (path.exists() && path.canRead()) { ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(os); zaos.setComment("Generated by OpenKM"); zaos.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS); zaos.setUseLanguageEncodingFlag(true); zaos.setFallbackToUTF8(true); zaos.setEncoding("UTF-8"); log.debug("FILE {}", path); ZipArchiveEntry zae = new ZipArchiveEntry(path.getName()); zaos.putArchiveEntry(zae); FileInputStream fis = new FileInputStream(path); IOUtils.copy(fis, zaos); fis.close(); zaos.closeArchiveEntry(); zaos.flush(); zaos.finish(); zaos.close(); } else { throw new IOException("Can't access " + path); } log.debug("createZip: void"); }
From source file:net.gbmb.collector.impl.TestTempStorage.java
@Override public String store(String cid, String contentId, InputStream content) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOUtils.copy(content, bos); IOUtils.closeQuietly(content);/*from w w w. j av a2 s .c o m*/ IOUtils.closeQuietly(bos); getCidContents(cid).put(contentId, bos.toByteArray()); return contentId; }
From source file:com.day.cq.wcm.foundation.TableXMLBuilder.java
public Table parse(Reader r) throws IOException { table = new Table(); rowNr = -1;/*from www .j ava 2 s .c o m*/ colNr = 0; cell = null; HtmlParser parser = new HtmlParser(); parser.setTagInclusionSet(TABLE_TAGS); parser.setContentHandler(this); IOUtils.copy(r, parser); parser.close(); parser.finished(); return table; }
From source file:com.s2g.pst.resume.importer.UnZipHelper.java
/** * Unzip it// w w w.j a v a 2s . c om * * @param fileName * @param outputFolder * * @throws java.io.FileNotFoundException */ public void unZipFolder(String fileName, String outputFolder) throws IOException { ZipFile zipFile = new ZipFile(fileName); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File entryDestination = new File(outputFolder, entry.getName()); entryDestination.getParentFile().mkdirs(); if (entry.isDirectory()) { //FileHelper fileHelper = new FileHelper(); //String filename = fileHelper.getUniqueFileName(outputFolder, FilenameUtils.removeExtension(entry.getName())); //System.out.println("zip :" + filename); //new File(filename).mkdirs(); entryDestination.mkdirs(); } else { InputStream in = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream(entryDestination); IOUtils.copy(in, out); IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } } zipFile.close(); this.deleteZipFile(fileName); System.out.println("Done"); }
From source file:com.picklecode.popflix.App.java
private static void loadLib(String name) { try {/*from ww w.ja v a2 s . co m*/ if (isWindows()) { name = name.substring("lib".length()); } String ext = getExtension(); name = name + ext; LOG.info(System.getProperty("os.arch")); LOG.info(System.getProperty("os.name")); Path tmp = Files.createTempDirectory("popflix"); setLibraryPath(tmp.toString()); LOG.info(tmp.toString() + "/" + name); File fileOut = new File(tmp.toString() + "/" + name); LOG.info(System.getProperty("java.library.path")); System.out.println("/lib/" + getFolder() + "/" + name); InputStream in = Popflix.class.getResourceAsStream("/lib/" + getFolder() + "/" + name); if (in != null) { OutputStream out = FileUtils.openOutputStream(fileOut); IOUtils.copy(in, out); in.close(); out.close(); } System.load(fileOut.getAbsolutePath());//loading goes here } catch (Exception e) { LOG.error(e.getMessage()); System.exit(-1); } }
From source file:com.epam.wilma.test.server.compress.gzip.GzipCompressor.java
/** * Compresses an {@link InputStream} object into gzip. * @param source the input stream that will be compressed. * @return a {@link ByteArrayOutputStream} containing gzipped byte array. *///from w w w .j a va2 s. c om public ByteArrayOutputStream compress(final InputStream source) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { GZIPOutputStream gout = new GZIPOutputStream(baos); //... Code to read from your original uncompressed data and write to gout. IOUtils.copy(source, gout); gout.finish(); gout.close(); } catch (IOException e) { throw new SystemException("error", e); } return baos; }
From source file:net.estinet.gFeatures.Feature.CTF.Confligs.ConfligInit.java
public void MakeFile(String filename) throws IOException { Reader paramReader = new InputStreamReader(getClass().getResourceAsStream(filename + ".yml")); StringWriter writer = new StringWriter(); IOUtils.copy(paramReader, writer); String theString = writer.toString(); File f = new File("plugins/CrackShot/weapons/" + filename + ".yml"); f.createNewFile();// www.j av a2 s . com BufferedWriter bw = new BufferedWriter(new FileWriter(f)); bw.write(theString); bw.close(); }
From source file:cz.hobrasoft.pdfmu.FileResource.java
public File getFile(TemporaryFolder folder) throws IOException { File file;//from w ww . j av a2 s . co m try (InputStream in = getStream()) { assert in != null; file = MainTest.newFile(folder, fileName, true); assert file.exists(); try (OutputStream out = new FileOutputStream(file)) { assert out != null; IOUtils.copy(in, out); } } return file; }
From source file:fr.duminy.jbackup.core.archive.zip.ZipArchiveOutputStream.java
@Override public void addEntry(String name, InputStream input) throws IOException { output.putArchiveEntry(new ZipArchiveEntry(name)); IOUtils.copy(input, output); output.closeArchiveEntry();//from w w w. ja va 2 s .c om }