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:net.ontopia.utils.EncryptionUtils.java

/**
 * INTERNAL: Reads all the data in the InputStream, encrypts it, and
 * writes it to the OutputStream.//from  w  ww.  j a  v a 2  s. c o  m
 */
public static void encrypt(InputStream in, OutputStream out) throws IOException {

    IOUtils.copy(new EncryptedInputStream(in), out);

}

From source file:acmi.l2.clientmod.l2_version_switcher.Util.java

public static boolean hashEquals(File file, String hashString) throws IOException {
    try {//from   w  w w .  j  a  va 2 s . c om
        MessageDigest md = MessageDigest.getInstance("sha-1");
        try (FileInputStream hashBytes = new FileInputStream(file)) {
            DigestInputStream dis = new DigestInputStream(hashBytes, md);
            IOUtils.copy(dis, NullOutputStream.NULL_OUTPUT_STREAM);
        }
        byte[] hash = md.digest();
        return Arrays.equals(hash, parseHexBinary(hashString));
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.daphne.es.maintain.editor.web.controller.utils.CompressUtils.java

private static void addFilesToCompression(ZipArchiveOutputStream zaos, File file, String dir)
        throws IOException {

    ZipArchiveEntry zipArchiveEntry = new ZipArchiveEntry(file, dir + file.getName());
    zaos.putArchiveEntry(zipArchiveEntry);

    if (file.isFile()) {
        BufferedInputStream bis = null;
        try {//from www . j a  va  2  s . c o  m
            bis = new BufferedInputStream(new FileInputStream(file));
            IOUtils.copy(bis, zaos);
            zaos.closeArchiveEntry();
        } catch (IOException e) {
            throw e;
        } finally {
            IOUtils.closeQuietly(bis);
        }
    } else if (file.isDirectory()) {
        zaos.closeArchiveEntry();

        for (File childFile : file.listFiles()) {
            addFilesToCompression(zaos, childFile, dir + file.getName() + File.separator);
        }
    }
}

From source file:net.di2e.ecdr.source.rest.TrustedServlet.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    OutputStream os = response.getOutputStream();
    IOUtils.copy(new StringReader("Trust this response"), os);
    os.flush();/*from w w w.jav a  2s. c  o  m*/

}

From source file:com.github.horrorho.inflatabledonkey.RawProtoDecoderLogger.java

@Override
public List<CloudKit.ResponseOperation> apply(InputStream input) throws IOException {
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        IOUtils.copy(input, baos);

        if (rawProtoDecoder != null) {
            List<String> rawProtos = rawProtoDecoder.decodeProtos(new ByteArrayInputStream(baos.toByteArray()));
            logger.debug("-- main() - raw decode: {}", rawProtos);

        } else {/*  w  w w .  ja v  a  2 s  .  c  o m*/
            logger.debug("-- main() - raw decode: no protoc decoder specified");
        }

        InputStream copy = new ByteArrayInputStream(baos.toByteArray());
        List<CloudKit.ResponseOperation> responseOperations = new ArrayList<>();
        CloudKit.ResponseOperation responseOperation;
        while ((responseOperation = CloudKit.ResponseOperation.parseDelimitedFrom(copy)) != null) {
            responseOperations.add(responseOperation);
        }

        return responseOperations;

    } catch (InterruptedException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:fi.helsinki.lib.simplerest.BinaryRepresentation.java

public void write(OutputStream outputStream) throws IOException {
    IOUtils.copy(this.inputStream, outputStream);
}

From source file:com.zte.gu.webtools.web.download.DownloadController.java

@RequestMapping(method = RequestMethod.GET)
public void download(HttpSession session, HttpServletResponse response) {
    String filePath = (String) session.getAttribute("filePath");
    String fileName = (String) session.getAttribute("fileName");
    if (filePath != null) {
        response.reset();/*from  ww w  .ja va2s.  co  m*/
        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        response.setContentType("application/octet-stream; charset=UTF-8");
        InputStream in = null;
        try {
            in = new FileInputStream(filePath);
            IOUtils.copy(in, response.getOutputStream());
        } catch (Exception e) {
            LoggerFactory.getLogger(DownloadController.class).warn("download error,", e);
        } finally {
            IOUtils.closeQuietly(in);
            session.removeAttribute("filePath");
            session.removeAttribute("fileName");
        }
    }
}

From source file:net.genesishub.gFeatures.Plus.Skript.SkriptManager.java

public void Enable(Extension s, String packages) throws IOException {
    try {//from ww  w .j  av a  2s. co m
        Reader paramReader = new InputStreamReader(getClass().getResourceAsStream(
                "/net/genesishub/gFeatures/Plus/Skript/" + packages + "/" + s.getName() + ".sk"));
        StringWriter writer = new StringWriter();
        IOUtils.copy(paramReader, writer);
        String theString = writer.toString();
        File f = new File("plugins/Skript/scripts/" + s.toString() + ".sk");
        f.createNewFile();
        BufferedWriter bw = new BufferedWriter(new FileWriter(f, true));
        bw.write(theString);
        bw.close();
    } catch (Exception E) {
    }
}

From source file:com.galenframework.actions.GalenActionHelp.java

@Override
public void execute() throws IOException {
    InputStream helpStream = getClass().getResourceAsStream("/galen-help-text");
    IOUtils.copy(helpStream, outStream);
}

From source file:com.izforge.izpack.installer.unpacker.DefaultFileUnpackerTest.java

/**
 * Creates a pack file stream.//from w  w w  .  jav  a 2s.c o m
 *
 * @param source the source
 * @return a new stream
 * @throws IOException for any I/O error
 */
@Override
protected InputStream createPackStream(File source) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.copy(new FileInputStream(source), out);
    out.close();
    return new ByteArrayInputStream(out.toByteArray());
}