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:edu.tum.cs.mylyn.internal.provisioning.git.UniqueInMemoryRepositoryTest.java

@Test
public void testRepository() throws ConfigInvalidException, IOException {
    DfsRepositoryDescription dfsRepositoryDescription = new DfsRepositoryDescription("test");
    UniqueInMemoryRepository repository1 = new UniqueInMemoryRepository(dfsRepositoryDescription);
    InputStream stream = new FileInputStream(new File("fixtures/repository-config"));
    StringWriter writer = new StringWriter();
    IOUtils.copy(stream, writer);
    repository1.getConfig().fromText(writer.toString());
    repository1.create();/*from   w w  w. ja v  a  2 s  . c  o  m*/

    UniqueInMemoryRepository repository2 = new UniqueInMemoryRepository(dfsRepositoryDescription);
    repository2.getConfig().fromText(writer.toString());
    repository2.create();

    assertEquals(repository1, repository2);
}

From source file:com.jaspersoft.jasperserver.war.xmla.XMLUtils.java

/**
 * read a file from classpath into a string
 * @param uri the path to the file (e.g. com/jaspersoft/foo/bar.xsl)
 * @return the content of the file/*ww  w. j a v  a 2s.  c  om*/
 * @throws IOException
 */
static String loadStyle(String uri) throws IOException {
    InputStream xslt = XMLUtils.class.getClassLoader().getResourceAsStream(uri);

    StringWriter xsltwriter = new StringWriter();
    IOUtils.copy(xslt, xsltwriter);

    return xsltwriter.toString();
}

From source file:com.hp.autonomy.idolutils.processors.CopyResponseProcessor.java

/**
 * Copies the given AciResponseInputStream into the OutputStream.
 * @param aciResponse The AciResponseInputStream to read
 * @return true If the method completes successfully
 * @throws ProcessorException If an IOException is thrown internally.
 *//*from www  . java  2s  .  c  o m*/
@Override
public Boolean process(final AciResponseInputStream aciResponse) {
    try {
        IOUtils.copy(aciResponse, outputStream);

        outputStream.flush();

        return true;
    } catch (final IOException e) {
        throw new ProcessorException(e);
    }
}

From source file:com.ctriposs.r2.filter.compression.GzipCompressor.java

@Override
public byte[] inflate(InputStream data) throws CompressionException {
    ByteArrayOutputStream out;//from   www  .j a  v a2s.  c om
    GZIPInputStream gzip = null;

    try {
        out = new ByteArrayOutputStream();
        gzip = new GZIPInputStream(data);

        IOUtils.copy(gzip, out);
    } catch (IOException e) {
        throw new CompressionException(CompressionConstants.DECODING_ERROR + getContentEncodingName(), e);
    } finally {
        if (gzip != null) {
            IOUtils.closeQuietly(gzip);
        }
    }

    return out.toByteArray();
}

From source file:fr.itinerennes.bundler.cli.GtfsFileOptionHandlerTest.java

@BeforeClass
public static void prepare() throws IOException {

    directory = File.createTempFile("junit-", "-itr.tmp");
    directory.delete();//from  w  ww .jav  a  2s .  c  o m
    directory.mkdir();

    invalidFile = File.createTempFile("junit-", "-itr.tmp");

    gtfsFile = File.createTempFile("junit-", "-itr.tmp.zip");
    final InputStream gtfsIn = GtfsFileOptionHandlerTest.class.getResourceAsStream("gtfs.zip");
    IOUtils.copy(gtfsIn, new FileOutputStream(gtfsFile));
}

From source file:com.trailmagic.image.ui.InputStreamView.java

private void writeOutput(Map model, HttpServletResponse res) throws IOException {
    OutputStream out = res.getOutputStream();
    InputStream in = (InputStream) model.get(STREAM_KEY);

    IOUtils.copy(in, out);
}

From source file:com.thoughtworks.go.agent.launcher.DownloadableFile.java

protected static boolean matchChecksum(File localFile, String expectedSignature) {
    try (FileInputStream input = new FileInputStream(localFile)) {
        MessageDigest digester = MessageDigest.getInstance("MD5");
        try (DigestInputStream digest = new DigestInputStream(input, digester)) {
            IOUtils.copy(digest, new NullOutputStream());
        }//from w  w w. ja v  a 2  s . co m
        return expectedSignature.equalsIgnoreCase(encodeHexString(digester.digest()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

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

public static void copy(InputStream in, Writer writer) throws IOException {
    Reader reader = new InputStreamReader(in, "UTF-8"); //$NON-NLS-1$
    try {//from  w w w  . java 2s .c  o m
        IOUtils.copy(reader, writer);
    } finally {
        try {
            reader.close();
        } catch (Exception ignore) {
        }
        try {
            writer.close();
        } catch (Exception ignore) {
        }
    }
}

From source file:com.lithium.flow.vault.AgentServer.java

public AgentServer(@Nonnull Config config) throws IOException {
    checkNotNull(config);//  ww  w .  j a  v  a  2s  .c  o  m

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    IOUtils.copy(System.in, baos);
    byte[] bytes = baos.toByteArray();

    ServerSocket server = new ServerSocket(config.getInt("agent.port"), -1, InetAddress.getByName(null));
    long endTime = System.currentTimeMillis() + config.getTime("agent.maximumTime", "1d");
    long inactiveTime = config.getTime("agent.inactiveTime", "8h");
    AtomicLong lastTime = new AtomicLong(System.currentTimeMillis());

    new LoopThread(() -> {
        try {
            Socket socket = server.accept();
            log.info("accepted connection: {}", socket);
            try (OutputStream out = socket.getOutputStream()) {
                IOUtils.copy(new ByteArrayInputStream(bytes), out);
            }
        } catch (IOException e) {
            //
        }

        lastTime.set(System.currentTimeMillis());
    });

    new LoopThread(1000, () -> {
        long time = System.currentTimeMillis();
        if (time > endTime) {
            log.info("maximum time reached");
            System.exit(0);
        }

        if (time > lastTime.get() + inactiveTime) {
            log.info("inactive time reached");
            System.exit(0);
        }
    });

    log.info("started agent on port {}", server.getLocalPort());
    Sleep.forever();
}

From source file:com.lithium.flow.util.HashEncoder.java

@Nonnull
public String process(@Nonnull InputStream in) throws IOException {
    checkNotNull(in);//from w  ww.j  a v a2  s . c  o  m
    try {
        HashingInputStream hashIn = new HashingInputStream(function, in);
        IOUtils.copy(hashIn, ByteStreams.nullOutputStream());
        return encoding.encode(hashIn.hash().asBytes());
    } finally {
        IOUtils.closeQuietly(in);
    }
}