java.io.FilterWriter Java Examples

The following examples show how to use java.io.FilterWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FHIRJsonGenerator.java    From FHIR with Apache License 2.0 6 votes vote down vote up
/**
 * Temporary workaround for: https://github.com/eclipse-ee4j/jsonp/issues/190
 */
private Writer wrap(Writer writer) {
    return new FilterWriter(writer) {
        private boolean first = true;
        
        @Override
        public void write(char[] cbuf, int off, int len) throws IOException {
            if (first && cbuf.length > 1 && off == 0 && cbuf[0] == '\n') {
                first = false;
                out.write(cbuf, off + 1, len - 1);
                return;
            }
            out.write(cbuf, off, len);
        }
        
        @Override
        public void close() {
            // do nothing
        }
    };
}
 
Example #2
Source File: ToolBox.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Writer openWriter() {
    return new FilterWriter(new StringWriter()) {
        @Override
        public void close() throws IOException {
            out.close();
            String text = ((StringWriter) out).toString();
            save(location, name, new Content() {
                @Override
                public byte[] getBytes() {
                    return text.getBytes();
                }
                @Override
                public String getString() {
                    return text;
                }

            });
        }
    };
}
 
Example #3
Source File: JsonSupport.java    From FHIR with Apache License 2.0 5 votes vote down vote up
public static Writer nonClosingWriter(Writer writer) {
    return new FilterWriter(writer) {
        @Override
        public void close() {
            // do nothing
        }
    };
}
 
Example #4
Source File: Dom4JDriver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public HierarchicalStreamWriter createWriter(final Writer out) {
    final HierarchicalStreamWriter[] writer = new HierarchicalStreamWriter[1];
    final FilterWriter filter = new FilterWriter(out){
        public void close() {
            writer[0].close();
        }
    };
    writer[0] = new Dom4JXmlWriter(new XMLWriter(filter,  outputFormat), getNameCoder());
    return writer[0];
}
 
Example #5
Source File: OldFilterWriterTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_ConstructorLjava_io_Writer() {

        FilterWriter myWriter = null;

        called = true;

        try {
            myWriter = new MyFilterWriter(null);
            fail("NullPointerException expected.");
        } catch (NullPointerException e) {
            // expected
        }
    }