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.purdue.cybercenter.dm.util.Helper.java

public static void stringToFile(String string, String filename) throws FileNotFoundException, IOException {
    try (OutputStream os = new FileOutputStream(filename); InputStream is = IOUtils.toInputStream(string)) {
        IOUtils.copy(is, os);
    }/*from  w  w w .j  a  va  2s.  c  o  m*/
}

From source file:net.gbmb.collector.impl.TestFinalStorage.java

@Override
public String store(String cid, InputStream content) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    IOUtils.copy(content, bos);
    IOUtils.closeQuietly(content);//from  w w w . j  a va 2  s .  c  o m
    IOUtils.closeQuietly(bos);
    contents.put(cid, bos.toByteArray());
    return cid;
}

From source file:com.arpnetworking.metrics.mad.performance.CollectdPipelinePT.java

@BeforeClass
public static void setUp() throws IOException, URISyntaxException {
    // Extract the sample file
    final Path gzipPath = Paths.get(Resources.getResource("collectd-sample1.log.gz").toURI());
    final FileInputStream fileInputStream = new FileInputStream(gzipPath.toFile());
    final GZIPInputStream gzipInputStream = new GZIPInputStream(fileInputStream);
    final Path path = Paths.get("target/tmp/perf/collectd-sample1.log");
    final FileOutputStream outputStream = new FileOutputStream(path.toFile());

    IOUtils.copy(gzipInputStream, outputStream);

    JSON_BENCHMARK_CONSUMER.prepareClass();
}

From source file:com.github.jrh3k5.mojo.flume.io.ArchiveUtils.java

/**
 * Un-GZIP a file./*ww  w .jav  a 2  s.c o  m*/
 * 
 * @param toUnzip
 *            A {@link URL} representing the GZIP file to be unzipped.
 * @param toFile
 *            A {@link File} representing the location to which the unzipped file should be placed.
 * @throws IOException
 *             If any errors occur during the unzipping.
 * @see #gzipFile(File, File)
 */
public static void gunzipFile(URL toUnzip, File toFile) throws IOException {
    if (toFile.exists() && !toFile.isFile()) {
        throw new IllegalArgumentException("Destination file " + toFile
                + " exists, but is not a file and, as such, cannot be written to.");
    }

    GZIPInputStream zipIn = null;
    FileOutputStream fileOut = null;
    try {
        zipIn = new GZIPInputStream(toUnzip.openStream());
        fileOut = new FileOutputStream(toFile);
        IOUtils.copy(zipIn, fileOut);
    } finally {
        IOUtils.closeQuietly(fileOut);
        IOUtils.closeQuietly(zipIn);
    }
}

From source file:com.googlecode.osde.internal.utils.ResourceUtil.java

/**
 * Retrieve the content in the resource file which you specify.
 *
 * @param path The resource file path./*from  w  w  w  . j a  va 2 s .c o  m*/
 * @param encoding File encoding.
 * @return The Content.
 * @throws IOException When some errors occurred.
 */
public static String loadTextResourceFile(String path, String encoding) throws IOException {
    InputStreamReader in = null;
    StringWriter out = null;
    try {
        in = new InputStreamReader(ResourceUtil.class.getResourceAsStream(path), encoding);
        out = new StringWriter();
        IOUtils.copy(in, out);
        String result = out.toString();
        return result;
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(out);
    }
}

From source file:edu.northwestern.bioinformatics.studycalendar.restlets.ClasspathResourceRepresentation.java

@Override
public void write(OutputStream outputStream) throws IOException {
    IOUtils.copy(getStream(), outputStream);
}

From source file:de.tudarmstadt.ukp.dkpro.lexsemresource.core.util.FileUtils.java

/**
 * Makes the given stream available as a file. The created file is temporary
 * and deleted upon normal termination of the JVM. Still the file should be
 * deleted as soon as possible if it is no longer required. In case the JVM
 * crashes the file would not be deleted. The source stream is closed by
 * this operation in all cases.//  ww  w  . j a va 2 s .c  o  m
 *
 * @param is
 *            the source.
 * @return the file.
 * @throws IOException
 *             in case of read or write problems.
 */
public static File getStreamAsFile(final InputStream is) throws IOException {
    OutputStream os = null;
    try {
        final File f = File.createTempFile("dkpro_stream", "tmp");
        f.deleteOnExit();
        os = new FileOutputStream(f);
        IOUtils.copy(is, os);
        return f;
    } finally {
        IOUtils.closeQuietly(os);
        IOUtils.closeQuietly(is);
    }
}

From source file:com.ruenzuo.pokeffective.activities.InfoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.info_activity);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    Uri data = getIntent().getData();/*  w  w  w  .j  a v  a  2  s.  co m*/
    if (data != null) {
        getActionBar().setTitle("License");
        AssetManager assetManager = getAssets();
        try {
            InputStream inputStream = assetManager.open("licenses/licenses.txt");
            StringWriter stringWriter = new StringWriter();
            IOUtils.copy(inputStream, stringWriter);
            String licenses = stringWriter.toString();
            TextView txtViewLicenses = (TextView) findViewById(R.id.txtViewLicenses);
            txtViewLicenses.setText(licenses);
            txtViewLicenses.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:edu.dfci.cccb.mev.deseq.domain.simple.FileBackedDESeq.java

@SneakyThrows
public static FileBackedDESeq from(InputStream results) {
    FileBackedDESeq result = new FileBackedDESeq(new TemporaryFolder());
    try (OutputStream full = new BufferedOutputStream(new FileOutputStream(result.full));
            BufferedInputStream in = new BufferedInputStream(results)) {
        IOUtils.copy(in, full);
    }/*w  w w.j  a  v a  2s .  c  o m*/
    return result;
}

From source file:gamepub.cloud.cloudUpload.java

public File stream2file(InputStream in) throws IOException {
    final File tempFile = File.createTempFile("stream2file", ".tmp");
    tempFile.deleteOnExit();//  www .j  a v a  2 s.c o m
    FileOutputStream out = new FileOutputStream(tempFile);
    IOUtils.copy(in, out);
    return tempFile;
}