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());
}
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
}
}
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;
}
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());
}
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
}
}
Aggregations