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.ctriposs.r2.filter.compression.Bzip2Compressor.java

@Override
public byte[] inflate(InputStream data) throws CompressionException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    BZip2CompressorInputStream bzip2 = null;

    try {//from w  w w  .jav  a2s  .  co  m
        bzip2 = new BZip2CompressorInputStream(data);
        IOUtils.copy(bzip2, out);
    } catch (IOException e) {
        throw new CompressionException(CompressionConstants.DECODING_ERROR + getContentEncodingName(), e);
    } finally {
        if (bzip2 != null) {
            IOUtils.closeQuietly(bzip2);
        }
    }

    return out.toByteArray();
}

From source file:codes.thischwa.c5c.requestcycle.response.mode.Prieview.java

@Override
@JsonIgnore// ww w .ja va2 s  .  co m
public void write(HttpServletResponse resp) throws IOException {
    String contentType = contentTypes.getContentTypeFor(fullPath);
    resp.setHeader("Content-Type", contentType);
    resp.setHeader("Content-Length", String.valueOf(contentLength));
    IOUtils.copy(in, resp.getOutputStream());
}

From source file:eu.planets_project.ifr.core.techreg.formats.DroidConfig.java

/**
 * @return The location of the DROID signature file taken from the
 *          Droid configuration properties file
 *//*from ww w  . j  a v a  2  s.  c om*/
public static String getSigFileLocation() {
    // String to hold the location
    String sigFileLocation = null;
    // Get the configuration object from the ServiceConfig util
    try {
        Configuration conf = ServiceConfig.getConfiguration(COMMON_CONF_FILE_NAME);
        // Create the file name from the properties
        sigFileLocation = conf.getString(SIG_FILE_LOC_KEY) + File.separator + conf.getString(SIG_FILE_NAME_KEY);
    } catch (ConfigurationException e) {
        log.severe("Could not find configuration file! " + e);
    }
    log.info("DROID Signature File location:" + sigFileLocation);
    // Check if the sigFileLocation is sane, and override with internal resource if not:
    File sfl = null;
    if (sigFileLocation != null)
        sfl = new File(sigFileLocation);
    if (sfl == null || !sfl.exists() || !sfl.isFile()) {
        try {
            File tmp = File.createTempFile("DroidSigFile", "xml");
            tmp.deleteOnExit();
            IOUtils.copy(DroidConfig.class.getResourceAsStream("/droid/DROID_SignatureFile.xml"),
                    new FileOutputStream(tmp));
            sigFileLocation = tmp.getAbsolutePath();
            log.info("Wrote cached Droid sig file to " + sigFileLocation);
        } catch (IOException e) {
            e.printStackTrace();
            log.severe("Could not generate external Droid Sig File.");
        }
    }
    return sigFileLocation;
}

From source file:com.github.khandroid.http.misc.FileDownloader.java

public static void download(HttpClient httpClient, URI source, File destination)
        throws ClientProtocolException, IOException {
    byte[] content = download(httpClient, source);
    ByteArrayInputStream input = new ByteArrayInputStream(content);
    BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(destination));

    IOUtils.copy(input, output);
    input.close();/*from   w ww. ja va2  s . co  m*/
    output.close();
}

From source file:com.lithium.flow.filer.CachedReadFiler.java

public CachedReadFiler(@Nonnull Filer delegate) {
    super(checkNotNull(delegate));
    cache = Caches.build(path -> {/* w ww.j a  va 2s . c om*/
        try (InputStream in = delegate.readFile(path)) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            IOUtils.copy(in, out);
            return Pair.of(delegate.getRecord(path).getTime(), out.toByteArray());
        }
    }, CacheBuilder::softValues);
}

From source file:com.stratio.ingestion.morphline.commons.CalculatorTest.java

protected Config parse(String file, Config... overrides) throws IOException {
    File tmpFile = File.createTempFile("morphlines_", ".conf");
    IOUtils.copy(getClass().getResourceAsStream(file), new FileOutputStream(tmpFile));
    Config config = new Compiler().parse(tmpFile, overrides);
    config = config.getConfigList("morphlines").get(0);
    Preconditions.checkNotNull(config);//from  w w  w .  ja v  a  2s.co m
    return config;
}

From source file:de.iew.imageupload.actions.UploadImageAction.java

public void actionPerformed(ActionEvent ev) {
    try {/* ww  w.j  a va2s . c  om*/
        Socket socket = new Socket("squeeze", 8124);

        FileInputStream fin = new FileInputStream(this.fileToUpload);
        OutputStream out = socket.getOutputStream();

        IOUtils.copy(fin, out);

        out.flush();
        fin.close();
        out.close();

        socket.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:edu.umn.msi.tropix.proteomics.test.InstrumentsTest.java

public void testInstruments(final boolean fromFile) throws IOException {
    Instruments instruments;//from   w w  w.  j a  va 2s.  co m
    if (fromFile) {
        final File tempFile = File.createTempFile("tpxtest", "");
        tempFile.deleteOnExit();
        final FileOutputStream stream = new FileOutputStream(tempFile);
        IOUtils.copy(getClass().getResourceAsStream("instruments.csv"), stream);
        instruments = new Instruments(tempFile.getAbsolutePath());
    } else {
        instruments = new Instruments(ProteomicsTests.getResourceAsStream("instruments.csv"));
    }
    assert instruments.ionUsed("Default", "1+ fragments") != null : "Null check 1";
    assert instruments.ionUsed("Default", "w or w' series ions") != null : "Null check 2";
    assert instruments.ionUsed("MALDI QIT TOF", "1+ fragments") != null : "Null check 3";
    assert instruments.ionUsed("MALDI QIT TOF", "w or w' series ions") != null : "Null check 4";
    assert instruments.ionUsed("ETD TRAP", "c series ions") != null : "Null check 5";
    assert instruments.ionUsed("Default", "c series ions") != null : "Null check 6";
    assert instruments.ionUsed("MALDI QUAD TOF", "c series ions") != null : "Null check 7";

    assert instruments.ionUsed("NOT AN INSTRUMENT", "NOT AN ION SERIES") == null;

    assert instruments.ionUsed("Default", "1+ fragments") : "Check 1";
    assert !instruments.ionUsed("Default", "w or w' series ions") : "Check 2";
    assert instruments.ionUsed("MALDI QIT TOF", "1+ fragments") : "Check 3";
    assert !instruments.ionUsed("MALDI QIT TOF", "w or w' series ions") : "Check 4";
    assert instruments.ionUsed("ETD TRAP", "c series ions") : "Check 5";
    assert !instruments.ionUsed("Default", "c series ions") : "Check 6";
    assert !instruments.ionUsed("MALDI QUAD TOF", "c series ions") : "Check 7";
}

From source file:com.seven.designbox.designpatterns.patterns.proxy.download.StreamCopyUtils.java

public static void copy(InputStream in, OutputStream out) throws IOException {
    IOUtils.copy(in, out);
}

From source file:com.sap.research.connectivity.gw.GwUtils.java

public static void createClassFileFromTemplate(String packageName, String subFolder, String templateFileName,
        String targetFileName, Map<String, String> replacements, FileManager fileManager,
        Class<?> loadingClass) {
    InputStream inputStream = null;
    OutputStream outputStream = null;
    String targetFile = subFolder + SEPARATOR + targetFileName;
    MutableFile mutableFile = fileManager.exists(targetFile) ? fileManager.updateFile(targetFile)
            : fileManager.createFile(targetFile);
    try {/*from   ww  w . ja va  2s .  c  om*/
        inputStream = FileUtils.getInputStream(loadingClass, templateFileName);
        outputStream = mutableFile.getOutputStream();
        String inputStreamString = IOUtils.toString(inputStream);

        for (Map.Entry<String, String> entry : replacements.entrySet()) {
            inputStreamString = inputStreamString.replace(entry.getKey(), entry.getValue());
        }
        //System.out.println(inputStreamString);
        inputStream = IOUtils.toInputStream(inputStreamString);
        IOUtils.copy(inputStream, outputStream);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } finally {
        IOUtils.closeQuietly(inputStream);
        IOUtils.closeQuietly(outputStream);
    }
}