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:com.mayalogy.mayu.io.FileAppender.java

public static void appendToFile(final InputStream in, final File f) throws IOException {
    OutputStream stream = null;//from w  w w  . j a  v  a2  s  . c  om
    try {
        stream = outStream(f);
        IOUtils.copy(in, stream);
    } finally {
        IOUtils.closeQuietly(stream);
    }
}

From source file:net.bpelunit.util.FileUtil.java

public static byte[] readFile(File f) throws IOException {
    FileInputStream bprInputStream = null;
    try {/*ww  w  .  java 2 s  . c  om*/
        bprInputStream = new FileInputStream(f);
        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream((int) f.length());
        IOUtils.copy(bprInputStream, bytesOut);

        return bytesOut.toByteArray();
    } finally {
        IOUtils.closeQuietly(bprInputStream);
    }
}

From source file:com.zb.app.common.file.FileUtils.java

public static File stream2file(InputStream in) throws IOException {
    final File tempFile = File.createTempFile("stream2file", ".tmp");
    tempFile.deleteOnExit();/*from ww w . j a v a 2 s .  co m*/

    try (FileOutputStream out = new FileOutputStream(tempFile)) {
        IOUtils.copy(in, out);
    }
    return tempFile;
}

From source file:edu.purdue.cybercenter.dm.util.Helper.java

public static int streamToFile(InputStream is, String path) throws FileNotFoundException, IOException {
    int size;/*from  w w w.  j a  v a2s.com*/
    try (OutputStream os = new FileOutputStream(path)) {
        size = IOUtils.copy(is, os);
        os.flush();
    }
    return size;
}

From source file:brut.util.BrutIO.java

public static void copyAndClose(InputStream in, OutputStream out) throws IOException {
    try {//  w w  w  . j  ava  2 s  .  c  om
        IOUtils.copy(in, out);
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(out);
    }
}

From source file:com.ariatemplates.attester.junit.StreamRedirector.java

public static void redirectStream(final InputStream inputStream, final OutputStream outputStream) {

    Thread thread = new Thread(new Runnable() {
        public void run() {
            try {
                IOUtils.copy(inputStream, outputStream);
            } catch (IOException e) {
                e.printStackTrace();//w  ww . ja  v  a 2 s . c o  m
            }
        }
    });
    thread.setDaemon(false);
    thread.start();
}

From source file:com.capitaltg.bbcodeguard.StringUtils.java

public static String readResourceAndUpdateText(String resourceName, Map<String, String> values)
        throws IOException {
    InputStream inputStream = StringUtils.class.getClassLoader().getResourceAsStream(resourceName);
    StringWriter writer = new StringWriter();
    IOUtils.copy(inputStream, writer);
    inputStream.close();//w  w w.j a va  2s  . c  o  m
    return StringUtils.replaceAll(writer.toString(), values);
}

From source file:com.ibm.jaggr.core.util.CopyUtil.java

public static int copy(InputStream in, OutputStream out) throws IOException {
    try {//from  ww  w.  j  a  va2  s  .c  o  m
        return IOUtils.copy(in, out);
    } finally {
        try {
            out.close();
        } catch (Exception ignore) {
        }
        ;
        try {
            in.close();
        } catch (Exception ignore) {
        }
        ;
    }
}

From source file:invio.util.ArquivoUtil.java

public static boolean copiarParaArquivos(UploadedFile file) {
    try {/*  w  ww. j  a v  a  2 s .co m*/
        String path = contextPath(file.getFileName());
        FileOutputStream saida = new FileOutputStream(path);
        InputStream entrada = file.getInputstream();
        IOUtils.copy(entrada, saida);
        IOUtils.closeQuietly(saida);
        IOUtils.closeQuietly(entrada);
        return true;
    } catch (IOException e) {
        return false;
    }
}

From source file:com.rover12421.shaka.lib.JarUtil.java

public static void getResourceAsFile(String resourcePath, String desPath) throws IOException {
    File parentFile = new File(desPath).getParentFile();
    if (!parentFile.exists()) {
        parentFile.mkdirs();//from ww  w  . j  a  va  2  s .c  om
    }
    try (InputStream in = Class.class.getResourceAsStream(resourcePath);
            FileOutputStream fos = new FileOutputStream(desPath)) {
        IOUtils.copy(in, fos);
    }
}