Java 类java.io.FilterReader 实例源码

项目:Reer    文件:FilterChain.java   
public void add(final Class<? extends FilterReader> filterType, final Map<String, ?> properties) {
    transformers.add(new Transformer<Reader, Reader>() {
        public Reader transform(Reader original) {
            try {
                Constructor<? extends FilterReader> constructor = filterType.getConstructor(Reader.class);
                FilterReader result = constructor.newInstance(original);

                if (properties != null) {
                    ConfigureUtil.configureByMap(properties, result);
                }
                return result;
            } catch (Throwable th) {
                throw new InvalidUserDataException("Error - Invalid filter specification for " + filterType.getName(), th);
            }
        }
    });
}
项目:guava-mock    文件:CharStreamsTest.java   
/**
 * Returns a reader wrapping the given reader that only reads half of the maximum number of
 * characters that it could read in read(char[], int, int).
 */
private static Reader newNonBufferFillingReader(Reader reader) {
  return new FilterReader(reader) {
    @Override
    public int read(char[] cbuf, int off, int len) throws IOException {
      // if a buffer isn't being cleared correctly, this method will eventually start being called
      // with a len of 0 forever
      if (len <= 0) {
        fail("read called with a len of " + len);
      }
      // read fewer than the max number of chars to read
      // shouldn't be a problem unless the buffer is shrinking each call
      return in.read(cbuf, off, Math.max(len - 1024, 0));
    }
  };
}
项目:guava-mock    文件:MultiReaderTest.java   
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());
}
项目:googles-monorepo-demo    文件:CharStreamsTest.java   
/**
 * Returns a reader wrapping the given reader that only reads half of the maximum number of
 * characters that it could read in read(char[], int, int).
 */
private static Reader newNonBufferFillingReader(Reader reader) {
  return new FilterReader(reader) {
    @Override
    public int read(char[] cbuf, int off, int len) throws IOException {
      // if a buffer isn't being cleared correctly, this method will eventually start being called
      // with a len of 0 forever
      if (len <= 0) {
        fail("read called with a len of " + len);
      }
      // read fewer than the max number of chars to read
      // shouldn't be a problem unless the buffer is shrinking each call
      return in.read(cbuf, off, Math.max(len - 1024, 0));
    }
  };
}
项目:googles-monorepo-demo    文件:MultiReaderTest.java   
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());
}
项目:guava-libraries    文件:CharStreamsTest.java   
/**
 * Returns a reader wrapping the given reader that only reads half of the maximum number of
 * characters that it could read in read(char[], int, int).
 */
private static Reader newNonBufferFillingReader(Reader reader) {
  return new FilterReader(reader) {
    @Override
    public int read(char[] cbuf, int off, int len) throws IOException {
      // if a buffer isn't being cleared correctly, this method will eventually start being called
      // with a len of 0 forever
      if (len <= 0) {
        fail("read called with a len of " + len);
      }
      // read fewer than the max number of chars to read
      // shouldn't be a problem unless the buffer is shrinking each call
      return in.read(cbuf, off, Math.max(len - 1024, 0));
    }
  };
}
项目:guava-libraries    文件:MultiReaderTest.java   
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());
}
项目:In-the-Box-Fork    文件:FilterReaderTest.java   
/**
 * @tests java.io.FilterReader#FilterReader(java.io.Reader)
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "Verifies constructor FilterReader(java.io.Reader).",
    method = "FilterReader",
    args = {java.io.Reader.class}
)
public void test_ConstructorLjava_io_Reader() {

    FilterReader myReader = null;

    called = true;

    try {
        myReader = new MyFilterReader(null);
        fail("NullPointerException expected.");
    } catch (NullPointerException e) {
        // expected
    }
}
项目:guava    文件:CharStreamsTest.java   
/**
 * Returns a reader wrapping the given reader that only reads half of the maximum number of
 * characters that it could read in read(char[], int, int).
 */
private static Reader newNonBufferFillingReader(Reader reader) {
  return new FilterReader(reader) {
    @Override
    public int read(char[] cbuf, int off, int len) throws IOException {
      // if a buffer isn't being cleared correctly, this method will eventually start being called
      // with a len of 0 forever
      if (len <= 0) {
        fail("read called with a len of " + len);
      }
      // read fewer than the max number of chars to read
      // shouldn't be a problem unless the buffer is shrinking each call
      return in.read(cbuf, off, Math.max(len - 1024, 0));
    }
  };
}
项目:guava    文件:MultiReaderTest.java   
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());
}
项目:guava    文件:CharStreamsTest.java   
/**
 * Returns a reader wrapping the given reader that only reads half of the maximum number of
 * characters that it could read in read(char[], int, int).
 */
private static Reader newNonBufferFillingReader(Reader reader) {
  return new FilterReader(reader) {
    @Override
    public int read(char[] cbuf, int off, int len) throws IOException {
      // if a buffer isn't being cleared correctly, this method will eventually start being called
      // with a len of 0 forever
      if (len <= 0) {
        fail("read called with a len of " + len);
      }
      // read fewer than the max number of chars to read
      // shouldn't be a problem unless the buffer is shrinking each call
      return in.read(cbuf, off, Math.max(len - 1024, 0));
    }
  };
}
项目:guava    文件:MultiReaderTest.java   
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());
}
项目:spliceengine    文件:TemporaryClob.java   
/**
 * @see #getReader
 */
public Reader getInternalReader(long characterPosition)
        throws IOException, SQLException {
    if (this.internalReader == null) {
        // getCSD obtains a descriptor for the stream to allow the reader
        // to configure itself.
        this.internalReader = new UTF8Reader(getCSD(), conChild,
                conChild.getConnectionSynchronization());
        this.unclosableInternalReader =
                new FilterReader(this.internalReader) {
                    public void close() {
                        // Do nothing.
                        // Stream will be closed when the Clob is released.
                    }
                };
    }
    try {
        this.internalReader.reposition(characterPosition);
    } catch (StandardException se) {
        throw Util.generateCsSQLException(se);
    }
    return this.unclosableInternalReader;
}
项目:Reer    文件:DefaultCopySpec.java   
public CopySpec filter(final Class<? extends FilterReader> filterType) {
    appendCopyAction(new Action<FileCopyDetails>() {
        public void execute(FileCopyDetails fileCopyDetails) {
            fileCopyDetails.filter(filterType);
        }
    });
    return this;
}
项目:Reer    文件:DefaultCopySpec.java   
public CopySpec filter(final Map<String, ?> properties, final Class<? extends FilterReader> filterType) {
    appendCopyAction(new Action<FileCopyDetails>() {
        public void execute(FileCopyDetails fileCopyDetails) {
            fileCopyDetails.filter(properties, filterType);
        }
    });
    return this;
}
项目:incubator-netbeans    文件:JShellEnvironment.java   
public InputStream getInputStream() throws IOException {
    if (inputOutput == null) {
        throw new IllegalStateException("not started");
    }
    return new ReaderInputStream(
            new FilterReader(inputOutput.getIn()) {
                @Override
                public void close() throws IOException {
                    // do not close the input, JShell may be reset.
                }
            }, "UTF-8" // NOI18N
    );
}
项目:guava-mock    文件:LineBufferTest.java   
private static Reader getChunkedReader(String input, final int chunk) {
  return new FilterReader(new StringReader(input)) {
    @Override public int read(char[] cbuf, int off, int len)
        throws IOException {
      return super.read(cbuf, off, Math.min(chunk, len));
    }
  };
}
项目:googles-monorepo-demo    文件:LineBufferTest.java   
private static Reader getChunkedReader(String input, final int chunk) {
  return new FilterReader(new StringReader(input)) {
    @Override public int read(char[] cbuf, int off, int len)
        throws IOException {
      return super.read(cbuf, off, Math.min(chunk, len));
    }
  };
}
项目:intellij-ce-playground    文件:ChainingFilterTransformer.java   
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()) {
      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;
}
项目:j2objc    文件:OldFilterReaderTest.java   
public void test_ConstructorLjava_io_Reader() {

        FilterReader myReader = null;

        called = true;

        try {
            myReader = new MyFilterReader(null);
            fail("NullPointerException expected.");
        } catch (NullPointerException e) {
            // expected
        }
    }
项目:guava-libraries    文件:LineBufferTest.java   
private static Reader getChunkedReader(String input, final int chunk) {
  return new FilterReader(new StringReader(input)) {
    @Override public int read(char[] cbuf, int off, int len)
        throws IOException {
      return super.read(cbuf, off, Math.min(chunk, len));
    }
  };
}
项目:Pushjet-Android    文件:DefaultCopySpec.java   
public CopySpec filter(final Class<? extends FilterReader> filterType) {
    copyActions.add(new Action<FileCopyDetails>() {
        public void execute(FileCopyDetails fileCopyDetails) {
            fileCopyDetails.filter(filterType);
        }
    });
    return this;
}
项目:Pushjet-Android    文件:DefaultCopySpec.java   
public CopySpec filter(final Map<String, ?> properties, final Class<? extends FilterReader> filterType) {
    copyActions.add(new Action<FileCopyDetails>() {
        public void execute(FileCopyDetails fileCopyDetails) {
            fileCopyDetails.filter(properties, filterType);
        }
    });
    return this;
}
项目:Pushjet-Android    文件:DefaultCopySpec.java   
public CopySpec filter(final Class<? extends FilterReader> filterType) {
    actions.add(new Action<FileCopyDetails>() {
        public void execute(FileCopyDetails fileCopyDetails) {
            fileCopyDetails.filter(filterType);
        }
    });
    return this;
}
项目:Pushjet-Android    文件:DefaultCopySpec.java   
public CopySpec filter(final Map<String, ?> properties, final Class<? extends FilterReader> filterType) {
    actions.add(new Action<FileCopyDetails>() {
        public void execute(FileCopyDetails fileCopyDetails) {
            fileCopyDetails.filter(properties, filterType);
        }
    });
    return this;
}
项目:guava    文件:LineBufferTest.java   
private static Reader getChunkedReader(String input, final int chunk) {
  return new FilterReader(new StringReader(input)) {
    @Override
    public int read(char[] cbuf, int off, int len) throws IOException {
      return super.read(cbuf, off, Math.min(chunk, len));
    }
  };
}
项目:guava    文件:LineBufferTest.java   
private static Reader getChunkedReader(String input, final int chunk) {
  return new FilterReader(new StringReader(input)) {
    @Override
    public int read(char[] cbuf, int off, int len) throws IOException {
      return super.read(cbuf, off, Math.min(chunk, len));
    }
  };
}
项目:elasticsearch-analysis-german    文件:FilterReaderUnwrapper.java   
public Reader unwrap(FilterReader originalReader) throws IllegalArgumentException {
    try {
        return (Reader) internalField.get(originalReader);
    } catch (Exception ex) {
        throw new IllegalArgumentException("Could not access private \"in\" field of the given FilterReader (actual class: " + originalReader.getClass().getCanonicalName() + ")", ex);
    }
}
项目:confit    文件:Parseable.java   
private static Reader doNotClose(Reader input) {
    return new FilterReader(input) {
        @Override
        public void close() {
            // NOTHING.
        }
    };
}
项目:Reer    文件:AbstractCopyTask.java   
/**
 * {@inheritDoc}
 */
public AbstractCopyTask filter(Map<String, ?> properties, Class<? extends FilterReader> filterType) {
    getMainSpec().filter(properties, filterType);
    return this;
}
项目:Reer    文件:AbstractCopyTask.java   
/**
 * {@inheritDoc}
 */
public AbstractCopyTask filter(Class<? extends FilterReader> filterType) {
    getMainSpec().filter(filterType);
    return this;
}
项目:Reer    文件:CopySpecWrapper.java   
public CopySpec filter(Map<String, ?> properties, Class<? extends FilterReader> filterType) {
    delegate.filter(properties, filterType);
    return this;
}
项目:Reer    文件:CopySpecWrapper.java   
public CopySpec filter(Class<? extends FilterReader> filterType) {
    delegate.filter(filterType);
    return this;
}
项目:Reer    文件:FilterChain.java   
public void add(Class<? extends FilterReader> filterType) {
    add(filterType, null);
}
项目:Reer    文件:DelegatingCopySpecInternal.java   
public CopySpec filter(Map<String, ?> properties, Class<? extends FilterReader> filterType) {
    return getDelegateCopySpec().filter(properties, filterType);
}
项目:Reer    文件:DelegatingCopySpecInternal.java   
public CopySpec filter(Class<? extends FilterReader> filterType) {
    return getDelegateCopySpec().filter(filterType);
}
项目:Reer    文件:NormalizingCopyActionDecorator.java   
public ContentFilterable filter(Map<String, ?> properties, Class<? extends FilterReader> filterType) {
    throw new UnsupportedOperationException();
}
项目:Reer    文件:NormalizingCopyActionDecorator.java   
public ContentFilterable filter(Class<? extends FilterReader> filterType) {
    throw new UnsupportedOperationException();
}
项目:Pushjet-Android    文件:AbstractCopyTask.java   
/**
 * {@inheritDoc}
 */
public AbstractCopyTask filter(Map<String, ?> properties, Class<? extends FilterReader> filterType) {
    getMainSpec().filter(properties, filterType);
    return this;
}
项目:Pushjet-Android    文件:AbstractCopyTask.java   
/**
 * {@inheritDoc}
 */
public AbstractCopyTask filter(Class<? extends FilterReader> filterType) {
    getMainSpec().filter(filterType);
    return this;
}