Example usage for org.apache.commons.io IOUtils copy

List of usage examples for org.apache.commons.io IOUtils copy

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils copy.

Prototype

public static void copy(Reader input, OutputStream output) throws IOException 

Source Link

Document

Copy chars from a Reader to bytes on an OutputStream using the default character encoding of the platform, and calling flush.

Usage

From source file:eu.europa.esig.dss.pdf.DSSPDFUtils.java

/**
 * This method returns the temporary {@code File} with the provided contents.
 *
 * @param pdfData {@code InputStream} representing the contents of the returned {@code File}
 * @return {@code File} with the given contents
 * @throws DSSException in case of any {@code IOException}
 *///from w  w w .  j  a  va2s.c  o m
public static File getFileFromPdfData(final InputStream pdfData) throws DSSException {

    FileOutputStream fileOutputStream = null;
    try {

        final File file = File.createTempFile("sd-dss-", ".pdf");
        fileOutputStream = new FileOutputStream(file);
        IOUtils.copy(pdfData, fileOutputStream);
        return file;
    } catch (IOException e) {
        throw new DSSException("The process has no rights to write or to access 'java.io.tmpdir': "
                + System.getProperty("java.io.tmpdir"), e);
    } finally {
        IOUtils.closeQuietly(pdfData);
        IOUtils.closeQuietly(fileOutputStream);
    }
}

From source file:com.cenrise.test.azkaban.GZIPUtils.java

public static byte[] unGzipBytes(final byte[] bytes) throws IOException {
    final ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bytes);
    final GZIPInputStream gzipInputStream = new GZIPInputStream(byteInputStream);

    final ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    IOUtils.copy(gzipInputStream, byteOutputStream);

    return byteOutputStream.toByteArray();
}

From source file:Configuration.ConfigHelper.java

public static String getUserHome() {
    String home = System.getProperty("user.home");
    if (home == null || home.length() <= 0) {
        try {/* www .j  a  v a 2s. co  m*/
            Process exec = Runtime.getRuntime().exec(new String[] { "bash", "-c", "echo $HOME" });
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            IOUtils.copy(exec.getInputStream(), baos);
            exec.getInputStream().close();
            home = baos.toString();
        } catch (Exception e) {
            return null;
        }
    }
    return home;
}

From source file:net.sf.nutchcontentexporter.WARCReaderTest.java

/**
 * Reads bz2 warc file//from   w  w  w  . j  a  v a 2s. c o  m
 *
 * @param file warc file
 * @throws IOException
 */
public static void readBz2(String file) throws IOException {
    // decompress bz2 file to tmp file
    File tmpFile = File.createTempFile("tmp", ".warc");
    BZip2CompressorInputStream inputStream = new BZip2CompressorInputStream(new FileInputStream(file));

    IOUtils.copy(inputStream, new FileOutputStream(tmpFile));

    WARCReader reader = WARCReaderFactory.get(tmpFile);

    int counter = 0;
    for (ArchiveRecord record : reader) {
        System.out.println(record.getHeader().getHeaderFields());

        counter++;
    }

    FileUtils.forceDelete(tmpFile);

    System.out.println(counter);
}

From source file:com.googlecode.t7mp.CommonsSetupUtil.java

@Override
public void copy(InputStream inputStream, OutputStream outputStream) throws IOException {
    IOUtils.copy(inputStream, outputStream);
}

From source file:eu.fusepool.p3.transformer.commons.util.InputStreamEntity.java

@Override
public void writeData(OutputStream out) throws IOException {
    IOUtils.copy(getData(), out);
}

From source file:at.gv.egovernment.moa.id.auth.builder.RedirectFormBuilder.java

private static String getTemplate() {

    if (template == null) {
        try {/* w w  w. j  a  v a  2 s  . c  o  m*/
            String classpathLocation = "resources/templates/redirectForm.html";
            InputStream input = Thread.currentThread().getContextClassLoader()
                    .getResourceAsStream(classpathLocation);
            StringWriter writer = new StringWriter();
            IOUtils.copy(input, writer);
            template = writer.toString();
        } catch (Exception e) {
            Logger.error("Failed to read template", e);
        }
    }

    return template;
}

From source file:fi.jumi.launcher.daemon.DirBasedSteward.java

private static void copyToFile(InputStream source, Path destination) throws IOException {
    Files.createDirectories(destination.getParent());
    try (OutputStream out = Files.newOutputStream(destination)) {
        IOUtils.copy(source, out);
    }/*from w w w.  ja  v a  2 s. c om*/
}

From source file:com.alexkasko.netty.ftp.ConsoleReceiver.java

@Override
public void receive(String name, InputStream data) throws IOException {
    System.out.println("receiving file: [" + name + "]");
    System.out.println("receiving data:");
    IOUtils.copy(data, System.out);
    System.out.println("");
}

From source file:com.thenairn.linker.config.Libraries.java

/**
 * Puts library to temp dir and loads to memory
 *///from  w w w.  ja v a2  s.c o  m
private static void loadLib(String path, String name) {
    name = name + ".dll";
    try {
        // have to use a stream
        InputStream in = Libraries.class.getResourceAsStream(LIB_BIN + name);
        // always write to different location
        File fileOut = new File(System.getProperty("java.io.tmpdir") + "/" + path + LIB_BIN + name);
        logger.info("Writing dll to: " + fileOut.getAbsolutePath());
        OutputStream out = FileUtils.openOutputStream(fileOut);
        IOUtils.copy(in, out);
        in.close();
        out.close();
        System.load(fileOut.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}