Search in sources :

Example 31 with FilterOutputStream

use of java.io.FilterOutputStream in project voldemort by voldemort.

the class VoldemortAdminTool method writeAscii.

private static void writeAscii(File outputFile, Writable writable) throws IOException {
    Writer writer = null;
    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();
    }
}
Also used : FileWriter(java.io.FileWriter) OutputStreamWriter(java.io.OutputStreamWriter) FilterOutputStream(java.io.FilterOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter)

Example 32 with FilterOutputStream

use of java.io.FilterOutputStream in project voldemort by voldemort.

the class AdminCommandStream method writeAscii.

private static void writeAscii(File outputFile, Writable writable) throws IOException {
    Writer writer = null;
    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();
    }
}
Also used : FileWriter(java.io.FileWriter) OutputStreamWriter(java.io.OutputStreamWriter) FilterOutputStream(java.io.FilterOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter)

Example 33 with FilterOutputStream

use of java.io.FilterOutputStream in project nutz by nutzam.

the class Sender method getOutputStream.

protected OutputStream getOutputStream() throws IOException {
    OutputStream out = conn.getOutputStream();
    if (progressListener == null)
        return out;
    return new FilterOutputStream(out) {

        int count;

        public void write(byte[] b, int off, int len) throws IOException {
            super.write(b, off, len);
            count += len;
            progressListener.invoke(count);
        }
    };
}
Also used : OutputStream(java.io.OutputStream) FilterOutputStream(java.io.FilterOutputStream) FilterOutputStream(java.io.FilterOutputStream)

Example 34 with FilterOutputStream

use of java.io.FilterOutputStream in project lucene-solr by apache.

the class SerializedDVStrategy method createIndexableFields.

@Override
public Field[] createIndexableFields(Shape shape) {
    //50% headroom over last
    int bufSize = Math.max(128, (int) (this.indexLastBufSize * 1.5));
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream(bufSize);
    //receiver of byteStream's bytes
    final BytesRef bytesRef = new BytesRef();
    try {
        ctx.getBinaryCodec().writeShape(new DataOutputStream(byteStream), shape);
        //this is a hack to avoid redundant byte array copying by byteStream.toByteArray()
        byteStream.writeTo(new FilterOutputStream(null) {

            /*not used*/
            @Override
            public void write(byte[] b, int off, int len) throws IOException {
                bytesRef.bytes = b;
                bytesRef.offset = off;
                bytesRef.length = len;
            }
        });
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    //cache heuristic
    this.indexLastBufSize = bytesRef.length;
    return new Field[] { new BinaryDocValuesField(getFieldName(), bytesRef) };
}
Also used : BinaryDocValuesField(org.apache.lucene.document.BinaryDocValuesField) Field(org.apache.lucene.document.Field) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FilterOutputStream(java.io.FilterOutputStream) BinaryDocValuesField(org.apache.lucene.document.BinaryDocValuesField) Point(org.locationtech.spatial4j.shape.Point) BytesRef(org.apache.lucene.util.BytesRef)

Example 35 with FilterOutputStream

use of java.io.FilterOutputStream in project bnd by bndtools.

the class CombinedResource method write.

@Override
public void write(final OutputStream out) throws IOException, Exception {
    OutputStream unclosable = new FilterOutputStream(out) {

        @Override
        public void close() {
        // Ignore
        }
    };
    for (Resource r : resources) {
        r.write(unclosable);
        unclosable.flush();
    }
}
Also used : OutputStream(java.io.OutputStream) FilterOutputStream(java.io.FilterOutputStream) FilterOutputStream(java.io.FilterOutputStream)

Aggregations

FilterOutputStream (java.io.FilterOutputStream)36 IOException (java.io.IOException)27 Support_OutputStream (tests.support.Support_OutputStream)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 FileOutputStream (java.io.FileOutputStream)7 OutputStream (java.io.OutputStream)7 File (java.io.File)4 InputStream (java.io.InputStream)4 Test (org.junit.Test)4 BufferedOutputStream (java.io.BufferedOutputStream)3 DataOutputStream (java.io.DataOutputStream)3 FileInputStream (java.io.FileInputStream)3 FilterInputStream (java.io.FilterInputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ByteSink (com.google.common.io.ByteSink)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 Writer (java.io.Writer)2