Example usage for org.apache.commons.io IOUtils closeQuietly

List of usage examples for org.apache.commons.io IOUtils closeQuietly

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils closeQuietly.

Prototype

public static void closeQuietly(OutputStream output) 

Source Link

Document

Unconditionally close an OutputStream.

Usage

From source file:com.mgmtp.jfunk.data.source.ArchiveDataSourceTest.java

@DataProvider(name = "dataSources")
public Object[][] createDataSources() throws IOException {
    Configuration config = new Configuration(Charsets.UTF_8);
    InputStream is = null;/* w w w .j  a va  2  s  .  c  o  m*/
    try {
        is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test-datasources.properties");
        config.load(is);
    } finally {
        IOUtils.closeQuietly(is);
    }
    ArchiveDataSource dsFromProps = new ArchiveDataSource(config);

    return new Object[][] { { dsFromProps } };
}

From source file:de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.StatisticsTableCreator.java

public static void saveTableToCsv(Table<String, String, Long> table, OutputStream outputStream) {
    PrintWriter pw = new PrintWriter(outputStream);
    pw.write(";");
    for (String columnKey : table.columnKeySet()) {
        pw.printf("%s;", columnKey);
    }//from  ww  w  .j a va 2s  .c  o m
    pw.println();

    for (String rowKey : table.rowKeySet()) {
        pw.printf("%s;", rowKey);
        for (String columnKey : table.columnKeySet()) {
            Long value = table.get(rowKey, columnKey);
            pw.printf("%d;", value != null ? value : 0);
        }
        pw.println();
    }

    IOUtils.closeQuietly(pw);
}

From source file:de.fhg.iais.commons.stream.AutoFileOutputStreamTest.java

@Test
public void testWriting() throws IOException {
    AutoFileOutputStream os = new AutoFileOutputStream(FILE_STRING, false);
    os.write(CONTENT);/*  w ww . ja  v  a2  s  . c  o m*/
    os.setCompleted();
    os.close();
    IOUtils.closeQuietly(os);

    checkContentAndRemoveFile(CONTENT);
}

From source file:de.weltraumschaf.registermachine.bytecode.ByteCodeWriter.java

/**
 * Write byte array to file./*from  ww w.  java  2 s  . c  om*/
 *
 * @param code byte code array
 * @throws IOException if, file I/O errors happened
 */
public void write(final byte[] code) throws IOException {
    IOUtils.write(code, output);
    IOUtils.closeQuietly(output);
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.export.ExcelExportTestUtils.java

public static void persistWorkbook(Workbook workbook, File file) throws IOException {
    FileOutputStream fos = null;/* w w  w .  ja  v  a 2 s  .  c o m*/
    try {
        fos = new FileOutputStream(file);
        workbook.write(fos);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:com.bsb.sonar.sample.plugin.implement.CheckStyleExtensionRepository.java

@Override
public List<Rule> createRules() {
    final InputStream input = CheckStyleExtensionRepository.class.getResourceAsStream(getFile());
    try {/*from  w w  w. j  a v a2 s .  c o m*/
        return xmlRuleParser.parse(input);
    } finally {
        IOUtils.closeQuietly(input);
    }
}

From source file:com.daphne.es.maintain.editor.web.controller.utils.CompressUtils.java

private static void addFilesToCompression(ZipArchiveOutputStream zaos, File file, String dir)
        throws IOException {

    ZipArchiveEntry zipArchiveEntry = new ZipArchiveEntry(file, dir + file.getName());
    zaos.putArchiveEntry(zipArchiveEntry);

    if (file.isFile()) {
        BufferedInputStream bis = null;
        try {//  w w  w .j a v  a  2  s . c  o  m
            bis = new BufferedInputStream(new FileInputStream(file));
            IOUtils.copy(bis, zaos);
            zaos.closeArchiveEntry();
        } catch (IOException e) {
            throw e;
        } finally {
            IOUtils.closeQuietly(bis);
        }
    } else if (file.isDirectory()) {
        zaos.closeArchiveEntry();

        for (File childFile : file.listFiles()) {
            addFilesToCompression(zaos, childFile, dir + file.getName() + File.separator);
        }
    }
}

From source file:io.apicurio.hub.core.storage.jdbc.DdlParser.java

/**
 * @param ddlFile/*from w  w w.  java 2 s  .c o  m*/
 */
public List<String> parse(File ddlFile) {
    InputStream is = null;
    try {
        is = new FileInputStream(ddlFile);
        return parse(is);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:com.discursive.jccook.io.CountingOutExample.java

public void start() {

    File test = new File("test.dat");
    CountingOutputStream countStream = null;

    try {/*from w ww  .  j a v a2 s  .c o m*/
        FileOutputStream fos = new FileOutputStream(test);
        countStream = new CountingOutputStream(fos);
        countStream.write("Hello".getBytes());
    } catch (IOException ioe) {
        System.out.println("Error writing bytes to file.");
    } finally {
        IOUtils.closeQuietly(countStream);
    }

    if (countStream != null) {
        int bytesWritten = countStream.getCount();
        System.out.println("Wrote " + bytesWritten + " bytes to test.dat");
    }

}

From source file:io.apiman.gateway.platforms.war.micro.Users.java

public static final List<User> getUsers() throws Exception {
    List<User> rval = new ArrayList<>();

    URL usersUrl = getUsersUrl();

    if (usersUrl != null) {
        System.out.println("Loading users from: " + usersUrl);
        InputStream in = null;/* w  w w  .  ja  va  2 s . c o m*/
        BufferedReader reader = null;
        try {
            in = usersUrl.openStream();
            reader = new BufferedReader(new InputStreamReader(in));
            String line = reader.readLine();
            while (line != null) {
                line = line.trim();
                if (line.length() == 0 || line.startsWith("#")) {
                    continue;
                }
                String[] split = line.split(",");
                User user = new User();
                user.setId(split[0]);
                user.setPassword(split[1]);
                user.getRoles().add("apipublisher");
                rval.add(user);
                System.out.println("  added user => " + user.getId());
                line = reader.readLine();
            }
        } catch (Throwable t) {
            throw new RuntimeException(t);
        } finally {
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(reader);
        }
    } else {
        System.out.println("Using default users.");
        User user = new User();
        user.setId("admin");
        user.setPassword("admin123!");
        user.getRoles().add("apiuser");
        user.getRoles().add("apiadmin");
        rval.add(user);
    }

    return rval;
}