Example usage for org.apache.commons.io.output ClosedOutputStream CLOSED_OUTPUT_STREAM

List of usage examples for org.apache.commons.io.output ClosedOutputStream CLOSED_OUTPUT_STREAM

Introduction

In this page you can find the example usage for org.apache.commons.io.output ClosedOutputStream CLOSED_OUTPUT_STREAM.

Prototype

ClosedOutputStream CLOSED_OUTPUT_STREAM

To view the source code for org.apache.commons.io.output ClosedOutputStream CLOSED_OUTPUT_STREAM.

Click Source Link

Document

A singleton.

Usage

From source file:de.mklinger.commons.exec.CmdSettingsTest.java

@Override
protected Object createValue(final Type type) {
    if (type == OutputStream.class) {
        return ClosedOutputStream.CLOSED_OUTPUT_STREAM;
    }//w  w w  .j  a va 2 s  .  co m
    if (type == InputStream.class) {
        return ClosedInputStream.CLOSED_INPUT_STREAM;
    }
    if (type == File.class) {
        return new File(String.valueOf(getNextTestValue()));
    }
    if (type == Pingable.class) {
        return new Pingable() {
            @Override
            public void ping() {
            }
        };
    }
    if (type == ExecutorProvider.class) {
        return new DefaultExecutorProvider();
    }
    return super.createValue(type);
}

From source file:org.codice.ddf.configuration.migration.ExportMigrationContextImpl.java

@SuppressWarnings("PMD.DefaultPackage" /* designed to be called from ExportMigrationEntryImpl within this package */)
OutputStream getOutputStreamFor(ExportMigrationEntryImpl entry) {
    try {/*from   w  w w . j a  v a2  s  . c  o m*/
        close();
        // zip entries are always Unix style based on our convention
        final ZipEntry ze = new ZipEntry(id + '/' + entry.getName());

        ze.setTime(entry.getLastModifiedTime()); // save the current modified time
        zipOutputStream.putNextEntry(ze);
        final OutputStream oos = new ProxyOutputStream(zipOutputStream) {
            @Override
            public void close() throws IOException {
                if (!(super.out instanceof ClosedOutputStream)) {
                    super.out = ClosedOutputStream.CLOSED_OUTPUT_STREAM;
                    zipOutputStream.closeEntry();
                }
            }

            @Override
            protected void handleIOException(IOException e) throws IOException {
                super.handleIOException(new ExportIOException(e));
            }
        };

        CipherOutputStream cos = cipherUtils.getCipherOutputStream(oos);
        this.currentOutputStream = cos;
        return cos;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}