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.google.mr4c.sources.BytesDataFileSink.java

public synchronized void writeFile(InputStream input) throws IOException {
    m_stream.reset();
    IOUtils.copy(input, m_stream);
}

From source file:com.cognifide.aet.common.ReportWriter.java

void write(String buildDirectory, String endpointUrl, String saveAsFileName) throws IOException {
    URL url = new URL(endpointUrl);
    boolean directoryExists = tryCreateDirectory(buildDirectory);
    if (directoryExists) {
        try (InputStream inputStream = url.openStream();
                OutputStream outputStream = new FileOutputStream(
                        getTargetPath(buildDirectory, saveAsFileName))) {
            IOUtils.copy(inputStream, outputStream);
        }//ww w.  j a v a 2 s .c  o  m
    } else {
        throw new IOException("Failed to create directory: " + buildDirectory);
    }
}

From source file:brut.util.Jar.java

public static File extractToTmp(String resourcePath, String tmpPrefix) throws BrutException {
    try {/*from  ww w  .  ja v a2 s .c  om*/
        InputStream in = Class.class.getResourceAsStream(resourcePath);
        if (in == null) {
            throw new FileNotFoundException(resourcePath);
        }
        File fileOut = File.createTempFile(tmpPrefix, null);
        fileOut.deleteOnExit();
        OutputStream out = new FileOutputStream(fileOut);
        IOUtils.copy(in, out);
        in.close();
        out.close();
        return fileOut;
    } catch (IOException ex) {
        throw new BrutException("Could not extract resource: " + resourcePath, ex);
    }
}

From source file:net.akehurst.build.resolver.p2.osgi.SimpleTransport.java

@Override
public IStatus download(URI toDownload, OutputStream target, long startPos, IProgressMonitor monitor) {
    try {/*from w w w .  j a  v  a  2  s  .c o  m*/
        IOUtils.copy(toDownload.toURL().openStream(), target);
        return Status.OK_STATUS;
    } catch (Exception ex) {
        return Status.OK_STATUS;
    }
}

From source file:com.spotify.echoprintserver.DecodeTest.java

@Test
/** make sure that the echoprint string -> code sequence function works as expected */
public void testEchoprintStringDecoding() throws IOException {
    StringWriter sw = new StringWriter();
    IOUtils.copy(this.getClass().getResourceAsStream("/echoprint_string.txt"), sw);
    String echoprintString = sw.toString();
    List<Integer> expectedCodes = Arrays
            .asList(TestUtils.parseCsv(this.getClass().getResourceAsStream("/echoprint_codes.txt")).get(0));
    List<Integer> computedCodes = Util.decodeEchoprintString(echoprintString);
    for (int i = 0; i < expectedCodes.size(); i++)
        Assert.assertEquals(expectedCodes.get(i), computedCodes.get(i));

}

From source file:io.tourniquet.junit.http.rules.UrlResourceHandler.java

@Override
protected void writeResource(final OutputStream outputStream, String queryString) throws IOException {
    try (InputStream inputStream = resource.openStream()) {
        IOUtils.copy(inputStream, outputStream);
    }/*from  w ww . j a  va  2s .com*/
}

From source file:com.tango.BucketSyncer.S32S3TestFile.java

public S32S3TestFile() throws Exception {
    file = File.createTempFile(getClass().getName(), ".tmp");
    data = S32S3MirrorTest.random(TEST_FILE_SIZE + (RandomUtils.nextInt() % 1024));
    @Cleanup/*from ww  w. j a  va 2 s .  c o  m*/
    FileOutputStream out = new FileOutputStream(file);
    IOUtils.copy(new ByteArrayInputStream(data.getBytes()), out);
    file.deleteOnExit();
}

From source file:net.rptools.maptool.client.AppSetup.java

/**
 * Overwrites any existing README file in the ~/.maptool/resource directory with the one from the current MapTool
 * JAR file. This way any updates to the README will eventually be seen by the user, although only when a new
 * directory is added to the resource library...
 * //from   w w w.  jav a 2  s .c o m
 * @throws IOException
 */
private static void createREADME() throws IOException {
    File outFilename = new File(AppConstants.UNZIP_DIR, "README");
    InputStream inStream = null;
    OutputStream outStream = null;
    try {
        inStream = AppSetup.class.getResourceAsStream("README");
        outStream = new BufferedOutputStream(new FileOutputStream(outFilename));
        IOUtils.copy(inStream, outStream);
    } finally {
        IOUtils.closeQuietly(inStream);
        IOUtils.closeQuietly(outStream);
    }
}

From source file:de.micromata.genome.tpsb.httpmockup.testbuilder.HttpSectionParserTest.java

@Test
public void testParseHttpScenario() {
    try {//from ww  w .  ja  va 2s. c o m
        String content = FileUtils.readFileToString(new File("./dev/extrc/tests/httpmockup/HttpScenario1.txt"),
                "UTF-8");
        HttpScenario scen = new HttpScenario(content);
        MockHttpServletRequest req = scen.getRequest();
        final StringWriter sw = new StringWriter();
        IOUtils.copy(req.getReader(), sw);
        String s = sw.toString();
        s.length();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

}

From source file:com.openshift.internal.restclient.model.Secret.java

@Override
public void addData(String key, InputStream data) {
    try {//w w  w  . j  a  v  a  2  s  . c o  m
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        IOUtils.copy(data, os);
        addData(key, os.toByteArray());
    } catch (IOException e) {
        throw new IllegalArgumentException("Could not process data stream", e);
    }
}