Example usage for java.io FilterOutputStream FilterOutputStream

List of usage examples for java.io FilterOutputStream FilterOutputStream

Introduction

In this page you can find the example usage for java.io FilterOutputStream FilterOutputStream.

Prototype

public FilterOutputStream(OutputStream out) 

Source Link

Document

Creates an output stream filter built on top of the specified underlying output stream.

Usage

From source file:org.uberfire.java.nio.fs.jgit.JGitFileSystemProvider.java

@Override
public OutputStream newOutputStream(final Path path, final OpenOption... options)
        throws IllegalArgumentException, UnsupportedOperationException, IOException, SecurityException {
    checkNotNull("path", path);

    final JGitPathImpl gPath = toPathImpl(path);

    final Pair<PathType, ObjectId> result = checkPath(gPath.getFileSystem().gitRepo(), gPath.getRefTree(),
            gPath.getPath());/*from w  w  w . java 2 s .  co  m*/

    if (result.getK1().equals(PathType.DIRECTORY)) {
        throw new IOException();
    }

    try {
        final File file = File.createTempFile("gitz", "woot");
        return new FilterOutputStream(new FileOutputStream(file)) {
            public void close() throws java.io.IOException {
                super.close();

                commit(gPath, buildCommitInfo(null, Arrays.asList(options)),
                        new DefaultCommitContent(new HashMap<String, File>() {
                            {
                                put(gPath.getPath(), file);
                            }
                        }));
            }
        };
    } catch (java.io.IOException e) {
        throw new IOException(e);
    }
}

From source file:org.geotools.data.shapefile.ShpFiles.java

/**
 * Opens a output stream for the indicated file. A write lock is requested at the method call and
 * released on close.//from w w w. j ava  2 s .com
 * 
 * @param type
 *           the type of file to open the stream to.
 * @param requestor
 *           the object requesting the stream
 * @return an output stream
 * 
 * @throws IOException
 *            if a problem occurred opening the stream.
 */
public OutputStream getOutputStream(ShpFileType type, final FileWriter requestor) throws IOException {
    final URL url = acquireWrite(type, requestor);

    try {

        OutputStream out;
        if (isLocal()) {
            File file = DataUtilities.urlToFile(url);
            out = new FileOutputStream(file);
        } else {
            URLConnection connection = url.openConnection();
            connection.setDoOutput(true);
            out = connection.getOutputStream();
        }

        FilterOutputStream output = new FilterOutputStream(out) {

            private volatile boolean closed = false;

            @Override
            public void close() throws IOException {
                try {
                    super.close();
                } finally {
                    if (!closed) {
                        closed = true;
                        unlockWrite(url, requestor);
                    }
                }
            }

        };

        return output;
    } catch (Throwable e) {
        unlockWrite(url, requestor);
        if (e instanceof IOException) {
            throw (IOException) e;
        } else if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else if (e instanceof Error) {
            throw (Error) e;
        } else {
            throw new RuntimeException(e);
        }
    }
}

From source file:com.netscape.cmsutil.crypto.CryptoUtil.java

public static String base64Encode(byte[] bytes) throws IOException {
    // All this streaming is lame, but Base64OutputStream needs a
    // PrintStream
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    try (Base64OutputStream b64 = new Base64OutputStream(new PrintStream(new FilterOutputStream(output)))) {

        b64.write(bytes);/*from  w  ww .  ja  v  a 2  s  . c  o  m*/
        b64.flush();

        // This is internationally safe because Base64 chars are
        // contained within 8859_1
        return output.toString("8859_1");
    }
}

From source file:voldemort.VoldemortAdminTool.java

private static void writeBinary(File outputFile, Printable printable) throws IOException {
    OutputStream outputStream = null;
    if (outputFile == null) {
        outputStream = new FilterOutputStream(System.out) {

            @Override/*  ww w  .jav  a 2  s.  c  o m*/
            public void close() throws IOException {
                flush();
            }
        };
    } else {
        outputStream = new FileOutputStream(outputFile);
    }
    DataOutputStream dataOutputStream = new DataOutputStream(new BufferedOutputStream(outputStream));
    try {
        printable.printTo(dataOutputStream);
    } finally {
        dataOutputStream.close();
    }
}

From source file:voldemort.VoldemortAdminTool.java

private static void writeAscii(File outputFile, Writable writable) throws IOException {
    Writer writer = null;/* w  ww .  ja  v  a 2 s  .  c o m*/
    if (outputFile == null) {
        writer = new OutputStreamWriter(new FilterOutputStream(System.out) {

            @Override
            public void close() throws IOException {
                flush();
            }
        });
    } else {
        writer = new FileWriter(outputFile);
    }
    BufferedWriter bufferedWriter = new BufferedWriter(writer);
    try {
        writable.writeTo(bufferedWriter);
    } finally {
        bufferedWriter.close();
    }
}