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.t3.net.LocalLocation.java

@Override
public void putContent(InputStream content) throws IOException {
    try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(getFile()))) {
        IOUtils.copy(content, out);
        IOUtils.closeQuietly(content);//w w  w.j  a v  a  2 s  .  c o m
    }
}

From source file:io.inkstand.scribble.http.rules.UrlResourceHandler.java

@Override
protected void writeResource(final OutputStream outputStream) throws IOException {
    try (InputStream inputStream = resource.openStream()) {
        IOUtils.copy(inputStream, outputStream);
    }/*from  ww  w  .  ja v  a2 s.c  om*/
}

From source file:com.googlecode.fannj.FannTrainerTest.java

@Test
public void testTrainingDefault() throws IOException {

    File temp = File.createTempFile("fannj_", ".tmp");
    temp.deleteOnExit();/*from   w w w.  j a v  a  2  s. c  o  m*/
    IOUtils.copy(this.getClass().getResourceAsStream("xor.data"), new FileOutputStream(temp));

    List<Layer> layers = new ArrayList<Layer>();
    layers.add(Layer.create(2));
    layers.add(Layer.create(3, ActivationFunction.FANN_SIGMOID_SYMMETRIC));
    layers.add(Layer.create(1, ActivationFunction.FANN_SIGMOID_SYMMETRIC));

    Fann fann = new Fann(layers);
    Trainer trainer = new Trainer(fann);

    float desiredError = .001f;
    float mse = trainer.train(temp.getPath(), 500000, 1000, desiredError);
    assertTrue("" + mse, mse <= desiredError);
}

From source file:net.sourceforge.floggy.maven.ZipUtils.java

/**
 * DOCUMENT ME!/*from  w ww  .  ja  v  a  2 s . c  o  m*/
*
* @param file DOCUMENT ME!
* @param directory DOCUMENT ME!
*
* @throws IOException DOCUMENT ME!
*/
public static void unzip(File file, File directory) throws IOException {
    ZipFile zipFile = new ZipFile(file);
    Enumeration entries = zipFile.entries();

    if (!directory.exists() && !directory.mkdirs()) {
        throw new IOException("Unable to create the " + directory + " directory!");
    }

    while (entries.hasMoreElements()) {
        File temp;
        ZipEntry entry = (ZipEntry) entries.nextElement();

        if (entry.isDirectory()) {
            temp = new File(directory, entry.getName());

            if (!temp.exists() && !temp.mkdirs()) {
                throw new IOException("Unable to create the " + temp + " directory!");
            }
        } else {
            temp = new File(directory, entry.getName());
            IOUtils.copy(zipFile.getInputStream(entry), new FileOutputStream(temp));
        }
    }

    zipFile.close();
}

From source file:com.vaadin.tests.applicationservlet.VaadinRefreshServlet.java

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (request.getRequestURI().contains("/UIDL")) {
        InputStream loginHtml = request.getServletContext().getResourceAsStream("/statictestfiles/login.html");
        IOUtils.copy(loginHtml, response.getOutputStream());
        return;/*www .j  a va  2 s . co  m*/
    }
    super.service(request, response);
}

From source file:hu.juranyi.zsolt.jauthortagger.util.TestUtils.java

public static File exportResourceFile(String resFn, String outFn) {
    File outFile = new File(TEST_DIR, outFn);
    InputStream is = null;//from ww  w.  j  a va  2  s . c om
    OutputStream os = null;
    try {
        File parent = outFile.getParentFile();
        if (null != parent && !parent.exists()) {
            parent.mkdirs();
        }
        is = resource(resFn);
        os = new FileOutputStream(outFile);
        IOUtils.copy(is, os);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (null != is) {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (null != os) {
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return outFile;
}

From source file:com.mirth.connect.plugins.pdfviewer.PDFViewer.java

public void viewAttachments(String channelId, Long messageId, String attachmentId) {

    try {// ww  w .  j  a  va  2s . c om
        Attachment attachment = parent.mirthClient.getAttachment(channelId, messageId, attachmentId);
        byte[] rawData = attachment.getContent();
        Base64InputStream in = new Base64InputStream(new ByteArrayInputStream(rawData));

        File temp = File.createTempFile(attachment.getId(), ".pdf");
        temp.deleteOnExit();

        OutputStream out = new FileOutputStream(temp);
        IOUtils.copy(in, out);
        out.close();

        new MirthPDFViewer(true, temp);

    } catch (Exception e) {
        parent.alertThrowable(parent, e);
    }
}

From source file:net.dontdrinkandroot.utils.resource.CachedFileResource.java

@Override
public void write(final OutputStream os) throws IOException {

    final FileInputStream fis = new FileInputStream(this.file);
    IOUtils.copy(fis, os);
    IOUtils.closeQuietly(fis);//from w  ww.ja  v a 2  s . c o  m
}

From source file:com.jslsolucoes.tagria.lib.grid.exporter.impl.XmlExporter.java

public void doExport(OutputStream outputStream) throws IOException {
    IOUtils.copy(new ByteArrayInputStream(export()), outputStream);
}

From source file:com.boundlessgeo.geoserver.api.converters.ResourceMessageConverter.java

@Override
protected void writeInternal(Resource resource, HttpOutputMessage msg)
        throws IOException, HttpMessageNotWritableException {
    InputStream in = resource.in();
    try {// w ww  .j av  a2 s.  co  m
        IOUtils.copy(in, msg.getBody());
    } finally {
        IOUtils.closeQuietly(in);
    }
}