Search in sources :

Example 1 with FilterReader

use of java.io.FilterReader in project guava by google.

the class MultiReaderTest method testOnlyOneOpen.

public void testOnlyOneOpen() throws Exception {
    String testString = "abcdefgh";
    final CharSource source = newCharSource(testString);
    final int[] counter = new int[1];
    CharSource reader = new CharSource() {

        @Override
        public Reader openStream() throws IOException {
            if (counter[0]++ != 0) {
                throw new IllegalStateException("More than one source open");
            }
            return new FilterReader(source.openStream()) {

                @Override
                public void close() throws IOException {
                    super.close();
                    counter[0]--;
                }
            };
        }
    };
    Reader joinedReader = CharSource.concat(reader, reader, reader).openStream();
    String result = CharStreams.toString(joinedReader);
    assertEquals(testString.length() * 3, result.length());
}
Also used : StringReader(java.io.StringReader) FilterReader(java.io.FilterReader) Reader(java.io.Reader) FilterReader(java.io.FilterReader)

Example 2 with FilterReader

use of java.io.FilterReader in project j2objc by google.

the class OldFilterReaderTest method test_ConstructorLjava_io_Reader.

public void test_ConstructorLjava_io_Reader() {
    FilterReader myReader = null;
    called = true;
    try {
        myReader = new MyFilterReader(null);
        fail("NullPointerException expected.");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : FilterReader(java.io.FilterReader)

Example 3 with FilterReader

use of java.io.FilterReader in project intellij-community by JetBrains.

the class ChainingFilterTransformer method doTransform.

private Reader doTransform(ResourceRootFilter filter, Reader original) {
    if ("RenamingCopyFilter".equals(filter.filterType)) {
        final Matcher matcher = (Matcher) filter.getProperties().get("matcher");
        final String replacement = (String) filter.getProperties().get("replacement");
        if (matcher == null || replacement == null)
            return original;
        matcher.reset(myOutputFileRef.get().getName());
        if (matcher.find()) {
            final String newFileName = matcher.replaceFirst(replacement);
            myOutputFileRef.set(new File(myOutputFileRef.get().getParentFile(), newFileName));
        }
        return original;
    }
    try {
        Class<?> clazz = Class.forName(filter.filterType);
        if (!FilterReader.class.isAssignableFrom(clazz)) {
            myContext.processMessage(new CompilerMessage(GradleResourcesBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, String.format("Error - Invalid filter specification for %s. It should extend java.io.FilterReader.", filter.filterType), null));
        }
        Constructor constructor = clazz.getConstructor(Reader.class);
        FilterReader result = (FilterReader) constructor.newInstance(original);
        final Map<Object, Object> properties = filter.getProperties();
        if (!properties.isEmpty()) {
            if (ExpandProperties.class.getName().equals(filter.filterType)) {
                final Map<Object, Object> antProps = new HashMap<>(properties);
                final Project project = new Project();
                for (Map.Entry<Object, Object> entry : antProps.entrySet()) {
                    project.setProperty(entry.getKey().toString(), entry.getValue().toString());
                }
                properties.clear();
                properties.put("project", project);
            }
            ConfigureUtil.configureByMap(properties, result);
        }
        return result;
    } catch (Throwable th) {
        myContext.processMessage(new CompilerMessage(GradleResourcesBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, String.format("Error - Failed to apply filter(%s): %s", filter.filterType, th.getMessage()), null));
    }
    return original;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) Matcher(java.util.regex.Matcher) Constructor(java.lang.reflect.Constructor) ExpandProperties(org.apache.tools.ant.filters.ExpandProperties) Project(org.apache.tools.ant.Project) File(java.io.File) FilterReader(java.io.FilterReader)

Example 4 with FilterReader

use of java.io.FilterReader in project guava by hceylan.

the class MultiReaderTest method testOnlyOneOpen.

public void testOnlyOneOpen() throws Exception {
    String testString = "abcdefgh";
    final InputSupplier<Reader> supplier = newReader(testString);
    final int[] counter = new int[1];
    InputSupplier<Reader> reader = new InputSupplier<Reader>() {

        @Override
        public Reader getInput() throws IOException {
            if (counter[0]++ != 0) {
                throw new IllegalStateException("More than one supplier open");
            }
            return new FilterReader(supplier.getInput()) {

                @Override
                public void close() throws IOException {
                    super.close();
                    counter[0]--;
                }
            };
        }
    };
    @SuppressWarnings("unchecked") Reader joinedReader = CharStreams.join(reader, reader, reader).getInput();
    String result = CharStreams.toString(joinedReader);
    assertEquals(testString.length() * 3, result.length());
}
Also used : StringReader(java.io.StringReader) FilterReader(java.io.FilterReader) Reader(java.io.Reader) FilterReader(java.io.FilterReader)

Example 5 with FilterReader

use of java.io.FilterReader in project robovm by robovm.

the class OldFilterReaderTest method test_ConstructorLjava_io_Reader.

public void test_ConstructorLjava_io_Reader() {
    FilterReader myReader = null;
    called = true;
    try {
        myReader = new MyFilterReader(null);
        fail("NullPointerException expected.");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : FilterReader(java.io.FilterReader)

Aggregations

FilterReader (java.io.FilterReader)5 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 File (java.io.File)1 Constructor (java.lang.reflect.Constructor)1 Matcher (java.util.regex.Matcher)1 Project (org.apache.tools.ant.Project)1 ExpandProperties (org.apache.tools.ant.filters.ExpandProperties)1 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)1