本文整理了Java中org.apache.commons.io.input.NullReader
类的一些代码示例,展示了NullReader
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NullReader
类的具体详情如下:
包路径:org.apache.commons.io.input.NullReader
类名称:NullReader
[英]A functional, light weight Reader that emulates a reader of a specified size.
This implementation provides a light weight object for testing with an Readerwhere the contents don't matter.
One use case would be for testing the handling of large Reader as it can emulate that scenario without the overhead of actually processing large numbers of characters - significantly speeding up test execution times.
This implementation returns a space from the method that reads a character and leaves the array unchanged in the read methods that are passed a character array. If alternative data is required the processChar()
and processChars()
methods can be implemented to generate data, for example:
public class TestReader extends NullReader {
public TestReader(int size) {
super(size);
}
protected char processChar() {
return ... // return required value here
}
protected void processChars(char[] chars, int offset, int length) {
for (int i = offset; i
}
}
}
[中]一种功能强大、重量轻的阅读器,模拟特定尺寸的阅读器。
这个实现提供了一个轻量级的对象,用于在内容无关紧要的情况下使用Reader进行测试。
一个用例将用于测试大型读取器的处理,因为它可以模拟该场景,而不需要实际处理大量字符的开销,从而显著加快测试执行时间。
此实现从读取字符的方法返回一个空格,并在传递字符数组的读取方法中保持数组不变。如果需要替代数据,processChar()
和processChars()
方法可用于生成数据,例如:
public class TestReader extends NullReader {
public TestReader(int size) {
super(size);
}
protected char processChar() {
return ... // return required value here
}
protected void processChars(char[] chars, int offset, int length) {
for (int i = offset; i
}
}
}
代码示例来源:origin: commons-io/commons-io
/**
* Read some characters into the specified array.
*
* @param chars The character array to read into
* @return The number of characters read or -1
* if the end of file has been reached and
* throwEofException
is set to {@code false}.
* @throws EOFException if the end of file is reached and
* throwEofException
is set to {@code true}.
* @throws IOException if trying to read past the end of file.
*/
@Override
public int read(final char[] chars) throws IOException {
return read(chars, 0, chars.length);
}
代码示例来源:origin: commons-io/commons-io
/**
* Read a character.
*
* @return Either The character value returned by processChar()
* or -1
if the end of file has been reached and
* throwEofException
is set to {@code false}.
* @throws EOFException if the end of file is reached and
* throwEofException
is set to {@code true}.
* @throws IOException if trying to read past the end of file.
*/
@Override
public int read() throws IOException {
if (eof) {
throw new IOException("Read after end of file");
}
if (position == size) {
return doEndOfFile();
}
position++;
return processChar();
}
代码示例来源:origin: commons-io/commons-io
/**
* Read the specified number characters into an array.
*
* @param chars The character array to read into.
* @param offset The offset to start reading characters into.
* @param length The number of characters to read.
* @return The number of characters read or -1
* if the end of file has been reached and
* throwEofException
is set to {@code false}.
* @throws EOFException if the end of file is reached and
* throwEofException
is set to {@code true}.
* @throws IOException if trying to read past the end of file.
*/
@Override
public int read(final char[] chars, final int offset, final int length) throws IOException {
if (eof) {
throw new IOException("Read after end of file");
}
if (position == size) {
return doEndOfFile();
}
position += length;
int returnLength = length;
if (position > size) {
returnLength = length - (int)(position - size);
position = size;
}
processChars(chars, offset, returnLength);
return returnLength;
}
代码示例来源:origin: commons-io/commons-io
/**
* Skip a specified number of characters.
*
* @param numberOfChars The number of characters to skip.
* @return The number of characters skipped or -1
* if the end of file has been reached and
* throwEofException
is set to {@code false}.
* @throws EOFException if the end of file is reached and
* throwEofException
is set to {@code true}.
* @throws IOException if trying to read past the end of file.
*/
@Override
public long skip(final long numberOfChars) throws IOException {
if (eof) {
throw new IOException("Skip after end of file");
}
if (position == size) {
return doEndOfFile();
}
position += numberOfChars;
long returnLength = numberOfChars;
if (position > size) {
returnLength = numberOfChars - (position - size);
position = size;
}
return returnLength;
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testCopy_readerToWriter_IO84() throws Exception {
final long size = (long)Integer.MAX_VALUE + (long)1;
final Reader reader = new NullReader(size);
final Writer writer = new NullWriter();
// Test copy() method
assertEquals(-1, IOUtils.copy(reader, writer));
// reset the input
reader.close();
// Test copyLarge() method
assertEquals("copyLarge()", size, IOUtils.copyLarge(reader, writer));
}
代码示例来源:origin: org.apache.commons/commons-io
/**
* Skip a specified number of characters.
*
* @param numberOfChars The number of characters to skip.
* @return The number of characters skipped or -1
* if the end of file has been reached and
* throwEofException
is set to false
.
* @throws EOFException if the end of file is reached and
* throwEofException
is set to true
.
* @throws IOException if trying to read past the end of file.
*/
public long skip(long numberOfChars) throws IOException {
if (eof) {
throw new IOException("Skip after end of file");
}
if (position == size) {
return doEndOfFile();
}
position += numberOfChars;
long returnLength = numberOfChars;
if (position > size) {
returnLength = numberOfChars - (position - size);
position = size;
}
return returnLength;
}
代码示例来源:origin: org.bitbucket.bradleysmithllc.etlunit/core
ScriptThread()
{
stdout = new NullInputStream();
stdoutreader = new BufferedReader(new NullReader(100));
pipout = null;
prout = null;
}
代码示例来源:origin: org.apache.commons/commons-io
/**
* Read a character.
*
* @return Either The character value returned by processChar()
* or -1
if the end of file has been reached and
* throwEofException
is set to false
.
* @throws EOFException if the end of file is reached and
* throwEofException
is set to true
.
* @throws IOException if trying to read past the end of file.
*/
public int read() throws IOException {
if (eof) {
throw new IOException("Read after end of file");
}
if (position == size) {
return doEndOfFile();
}
position++;
return processChar();
}
代码示例来源:origin: org.apache.commons/commons-io
/**
* Read the specified number characters into an array.
*
* @param chars The character array to read into.
* @param offset The offset to start reading characters into.
* @param length The number of characters to read.
* @return The number of characters read or -1
* if the end of file has been reached and
* throwEofException
is set to false
.
* @throws EOFException if the end of file is reached and
* throwEofException
is set to true
.
* @throws IOException if trying to read past the end of file.
*/
public int read(char[] chars, int offset, int length) throws IOException {
if (eof) {
throw new IOException("Read after end of file");
}
if (position == size) {
return doEndOfFile();
}
position += length;
int returnLength = length;
if (position > size) {
returnLength = length - (int)(position - size);
position = size;
}
processChars(chars, offset, returnLength);
return returnLength;
}
代码示例来源:origin: org.apache.commons/commons-io
/**
* Read some characters into the specified array.
*
* @param chars The character array to read into
* @return The number of characters read or -1
* if the end of file has been reached and
* throwEofException
is set to false
.
* @throws EOFException if the end of file is reached and
* throwEofException
is set to true
.
* @throws IOException if trying to read past the end of file.
*/
public int read(char[] chars) throws IOException {
return read(chars, 0, chars.length);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-io
/**
* Skip a specified number of characters.
*
* @param numberOfChars The number of characters to skip.
* @return The number of characters skipped or -1
* if the end of file has been reached and
* throwEofException
is set to false
.
* @throws EOFException if the end of file is reached and
* throwEofException
is set to true
.
* @throws IOException if trying to read past the end of file.
*/
public long skip(long numberOfChars) throws IOException {
if (eof) {
throw new IOException("Skip after end of file");
}
if (position == size) {
return doEndOfFile();
}
position += numberOfChars;
long returnLength = numberOfChars;
if (position > size) {
returnLength = numberOfChars - (position - size);
position = size;
}
return returnLength;
}
代码示例来源:origin: com.googlecode.etl-unit/etlunit-core
ScriptThread()
{
stdout = new NullInputStream();
stdoutreader = new BufferedReader(new NullReader(100));
pipout = null;
prout = null;
}
代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.io
/**
* Read a character.
*
* @return Either The character value returned by processChar()
* or -1
if the end of file has been reached and
* throwEofException
is set to false
.
* @throws EOFException if the end of file is reached and
* throwEofException
is set to true
.
* @throws IOException if trying to read past the end of file.
*/
public int read() throws IOException {
if (eof) {
throw new IOException("Read after end of file");
}
if (position == size) {
return doEndOfFile();
}
position++;
return processChar();
}
代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.io
/**
* Read the specified number characters into an array.
*
* @param chars The character array to read into.
* @param offset The offset to start reading characters into.
* @param length The number of characters to read.
* @return The number of characters read or -1
* if the end of file has been reached and
* throwEofException
is set to false
.
* @throws EOFException if the end of file is reached and
* throwEofException
is set to true
.
* @throws IOException if trying to read past the end of file.
*/
public int read(char[] chars, int offset, int length) throws IOException {
if (eof) {
throw new IOException("Read after end of file");
}
if (position == size) {
return doEndOfFile();
}
position += length;
int returnLength = length;
if (position > size) {
returnLength = length - (int)(position - size);
position = size;
}
processChars(chars, offset, returnLength);
return returnLength;
}
代码示例来源:origin: commons-io/commons-io
@Override
public int read(final char[] chars) throws IOException {
return chars == null ? 0 : super.read(chars);
}
@Override
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Skip a specified number of characters.
*
* @param numberOfChars The number of characters to skip.
* @return The number of characters skipped or -1
* if the end of file has been reached and
* throwEofException
is set to {@code false}.
* @throws EOFException if the end of file is reached and
* throwEofException
is set to {@code true}.
* @throws IOException if trying to read past the end of file.
*/
@Override
public long skip(final long numberOfChars) throws IOException {
if (eof) {
throw new IOException("Skip after end of file");
}
if (position == size) {
return doEndOfFile();
}
position += numberOfChars;
long returnLength = numberOfChars;
if (position > size) {
returnLength = numberOfChars - (position - size);
position = size;
}
return returnLength;
}
代码示例来源:origin: org.apache.flex.flexjs.compiler/compiler
private LineNumberReader createReader()
{
IFileSpecification fileSpec = workspace.getFileSpecification(fileName);
Reader reader;
try
{
reader = fileSpec.createReader();
}
catch (FileNotFoundException e)
{
reader = new NullReader(0);
}
return new LineNumberReader(reader);
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Read a character.
*
* @return Either The character value returned by processChar()
* or -1
if the end of file has been reached and
* throwEofException
is set to {@code false}.
* @throws EOFException if the end of file is reached and
* throwEofException
is set to {@code true}.
* @throws IOException if trying to read past the end of file.
*/
@Override
public int read() throws IOException {
if (eof) {
throw new IOException("Read after end of file");
}
if (position == size) {
return doEndOfFile();
}
position++;
return processChar();
}
代码示例来源:origin: org.onosproject/onlab-thirdparty
/**
* Read the specified number characters into an array.
*
* @param chars The character array to read into.
* @param offset The offset to start reading characters into.
* @param length The number of characters to read.
* @return The number of characters read or -1
* if the end of file has been reached and
* throwEofException
is set to {@code false}.
* @throws EOFException if the end of file is reached and
* throwEofException
is set to {@code true}.
* @throws IOException if trying to read past the end of file.
*/
@Override
public int read(char[] chars, int offset, int length) throws IOException {
if (eof) {
throw new IOException("Read after end of file");
}
if (position == size) {
return doEndOfFile();
}
position += length;
int returnLength = length;
if (position > size) {
returnLength = length - (int)(position - size);
position = size;
}
processChars(chars, offset, returnLength);
return returnLength;
}
代码示例来源:origin: commons-io/commons-io
@Override
public int read(final CharBuffer target) throws IOException {
return target == null ? 0 : super.read(target);
}
}