本文整理了Java中java.io.Reader.reset
方法的一些代码示例,展示了Reader.reset
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Reader.reset
方法的具体详情如下:
包路径:java.io.Reader
类名称:Reader
方法名:reset
[英]Resets this reader's position to the last mark() location. Invocations of read() and skip() will occur from this new location. If this reader has not been marked, the behavior of reset() is implementation specific. This default implementation throws an IOException.
[中]将此读卡器的位置重置为最后一个标记()位置。将从这个新位置调用read()和skip()。如果未标记此读取器,则reset()的行为是特定于实现的。此默认实现引发IOException。
代码示例来源:origin: jersey/jersey
private static Reader ensureNonEmptyReader(Reader reader) throws XMLStreamException {
try {
Reader mr = reader.markSupported() ? reader : new BufferedReader(reader);
mr.mark(1);
if (mr.read() == -1) {
throw new XMLStreamException("JSON expression can not be empty!");
}
mr.reset();
return mr;
} catch (IOException ex) {
throw new XMLStreamException(ex);
}
}
代码示例来源:origin: pmd/pmd
public static Reader skipBOM(Reader source) {
Reader in = new BufferedReader(source);
try {
in.mark(1);
int firstCharacter = in.read();
if (firstCharacter != '\ufeff') {
in.reset();
}
} catch (IOException e) {
throw new RuntimeException("Error while trying to skip BOM marker", e);
}
return in;
}
代码示例来源:origin: com.h2database/h2
private void initRead() throws IOException {
if (input == null) {
try {
InputStream in = FileUtils.newInputStream(fileName);
in = new BufferedInputStream(in, Constants.IO_BUFFER_SIZE);
input = new InputStreamReader(in, characterSet);
} catch (IOException e) {
close();
throw e;
}
}
if (!input.markSupported()) {
input = new BufferedReader(input);
}
input.mark(1);
int bom = input.read();
if (bom != 0xfeff) {
// Microsoft Excel compatibility
// ignore pseudo-BOM
input.reset();
}
inputBuffer = new char[Constants.IO_BUFFER_SIZE * 2];
if (columnNames == null) {
readHeader();
}
}
代码示例来源:origin: org.jsoup/jsoup
private void bufferUp() {
if (bufPos < bufSplitPoint)
return;
try {
reader.skip(bufPos);
reader.mark(maxBufferLen);
final int read = reader.read(charBuf);
reader.reset();
if (read != -1) {
bufLength = read;
readerPos += bufPos;
bufPos = 0;
bufMark = 0;
bufSplitPoint = bufLength > readAheadLimit ? readAheadLimit : bufLength;
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
代码示例来源:origin: lealone/Lealone
private void initRead() throws IOException {
if (input == null) {
try {
InputStream in = FileUtils.newInputStream(fileName);
in = new BufferedInputStream(in, Constants.IO_BUFFER_SIZE);
input = new InputStreamReader(in, characterSet);
} catch (IOException e) {
close();
throw e;
}
}
if (!input.markSupported()) {
input = new BufferedReader(input);
}
input.mark(1);
int bom = input.read();
if (bom != 0xfeff) {
// Microsoft Excel compatibility
// ignore pseudo-BOM
input.reset();
}
inputBuffer = new char[Constants.IO_BUFFER_SIZE * 2];
if (columnNames == null) {
readHeader();
}
}
代码示例来源:origin: loklak/loklak_server
/**
* Determine if the source string still contains characters that next()
* can consume.
* @return true if not yet at the end of the source.
* @throws JSONException thrown if there is an error stepping forward
* or backward while checking for more data.
*/
public boolean more() throws JSONException {
if(this.usePrevious) {
return true;
}
try {
this.reader.mark(1);
} catch (IOException e) {
throw new JSONException("Unable to preserve stream position", e);
}
try {
// -1 is EOF, but next() can not consume the null character '\0'
if(this.reader.read() <= 0) {
this.eof = true;
return false;
}
this.reader.reset();
} catch (IOException e) {
throw new JSONException("Unable to read the next character from the stream", e);
}
return true;
}
代码示例来源:origin: groovy/groovy-core
while ((c = reader.read()) != -1) {
if (c == '<') {
reader.mark(1);
c = reader.read();
if (c != '%') {
sw.write('<');
reader.reset();
} else {
reader.mark(1);
c = reader.read();
if (c == '=') {
groovyExpression(reader, sw);
} else {
reader.reset();
groovySection(reader, sw);
reader.mark(1);
c = reader.read();
if (c != '{') {
sw.write('$');
reader.reset();
} else {
reader.mark(1);
c = reader.read();
if (c != '\n') {
reader.reset();
代码示例来源:origin: org.codehaus.groovy/groovy
char[] cbuf = new char[charBufferSize];
try {
input.mark(charBufferSize);
} catch (IOException e) {
input.reset();
input.skip(line.length() + skipLS);
return line.toString();
代码示例来源:origin: commons-io/commons-io
@Test
public void testMarkNotSupported() throws Exception {
final Reader reader = new TestNullReader(100, false, true);
assertFalse("Mark Should NOT be Supported", reader.markSupported());
try {
reader.mark(5);
fail("mark() should throw UnsupportedOperationException");
} catch (final UnsupportedOperationException e) {
assertEquals("mark() error message", "Mark not supported", e.getMessage());
}
try {
reader.reset();
fail("reset() should throw UnsupportedOperationException");
} catch (final UnsupportedOperationException e) {
assertEquals("reset() error message", "Mark not supported", e.getMessage());
}
reader.close();
}
代码示例来源:origin: Activiti/Activiti
/**
* Skip characters until the next character is the requested character. If the requested character is not found, no characters are skipped.
*
* @param to
* A character to skip to.
* @return The requested character, or zero if the requested character is not found.
*/
public char skipTo(char to) throws JSONException {
char c;
try {
int startIndex = this.index;
int startCharacter = this.character;
int startLine = this.line;
reader.mark(Integer.MAX_VALUE);
do {
c = next();
if (c == 0) {
reader.reset();
this.index = startIndex;
this.character = startCharacter;
this.line = startLine;
return c;
}
} while (c != to);
} catch (IOException exc) {
throw new JSONException(exc);
}
back();
return c;
}
代码示例来源:origin: commons-io/commons-io
reader.reset();
fail("Read limit exceeded, expected IOException ");
} catch (final IOException e) {
reader.mark(readlimit);
reader.reset();
reader.reset();
fail("Read limit exceeded, expected IOException ");
} catch (final IOException e) {
代码示例来源:origin: looly/hutool
/**
* Skip characters until the next character is the requested character. If the requested character is not found, no characters are skipped. 在遇到指定字符前,跳过其它字符。如果字符未找到,则不跳过任何字符。
*
* @param to 需要定位的字符
* @return 定位的字符,如果字符未找到返回0
*/
public char skipTo(char to) throws JSONException {
char c;
try {
long startIndex = this.index;
long startCharacter = this.character;
long startLine = this.line;
this.reader.mark(1000000);
do {
c = this.next();
if (c == 0) {
this.reader.reset();
this.index = startIndex;
this.character = startCharacter;
this.line = startLine;
return c;
}
} while (c != to);
} catch (IOException exception) {
throw new JSONException(exception);
}
this.back();
return c;
}
代码示例来源:origin: spullara/mustache.java
br.mark(1);
if (sm.length() == 1 || br.read() == sm.charAt(1)) {
br.mark(1);
c = br.read();
boolean delimiter = c == '=';
sb.append((char) c);
} else {
br.reset();
br.mark(1);
if (delimiter) {
if (c == '=') {
} else {
br.reset();
} else {
br.reset();
代码示例来源:origin: looly/hutool
/**
* Skip characters until the next character is the requested character. If the requested character is not found, no characters are skipped. 在遇到指定字符前,跳过其它字符。如果字符未找到,则不跳过任何字符。
*
* @param to 需要定位的字符
* @return 定位的字符,如果字符未找到返回0
*/
public char skipTo(char to) throws JSONException {
char c;
try {
long startIndex = this.index;
long startCharacter = this.character;
long startLine = this.line;
this.reader.mark(1000000);
do {
c = this.next();
if (c == 0) {
this.reader.reset();
this.index = startIndex;
this.character = startCharacter;
this.line = startLine;
return c;
}
} while (c != to);
} catch (IOException exception) {
throw new JSONException(exception);
}
this.back();
return c;
}
代码示例来源:origin: apache/hive
@Test
public void testMarkReset() throws IOException {
Reader reader = new ReusableStringReader();
if (reader.markSupported()) {
((ReusableStringReader)reader).set(fox);
assertTrue(reader.ready());
char[] cc = new char[6];
int read;
read = reader.read(cc);
assertEquals(6, read);
assertEquals("Quick ", new String(cc));
reader.mark(100);
read = reader.read(cc);
assertEquals(6, read);
assertEquals("brown ", new String(cc));
reader.reset();
read = reader.read(cc);
assertEquals(6, read);
assertEquals("brown ", new String(cc));
}
reader.close();
}
代码示例来源:origin: zzz40500/GsonFormat
/**
* Skip characters until the next character is the requested character.
* If the requested character is not found, no characters are skipped.
* @param to A character to skip to.
* @return The requested character, or zero if the requested character
* is not found.
*/
public char skipTo(char to) throws JSONException {
char c;
try {
long startIndex = this.index;
long startCharacter = this.character;
long startLine = this.line;
this.reader.mark(1000000);
do {
c = this.next();
if (c == 0) {
this.reader.reset();
this.index = startIndex;
this.character = startCharacter;
this.line = startLine;
return c;
}
} while (c != to);
} catch (IOException exception) {
throw new JSONException(exception);
}
this.back();
return c;
}
代码示例来源:origin: org.apache.commons/commons-lang3
reader = sb.asReader();
assertEquals('s', reader.read());
reader.mark(-1);
char[] array = new char[3];
assertEquals(3, reader.read(array, 0, 3));
assertEquals('m', array[1]);
assertEquals('e', array[2]);
reader.reset();
assertEquals(1, reader.read(array, 1, 1));
assertEquals('o', array[0]);
assertEquals(-1, reader.read(array, 0, 1));
reader.reset();
array = new char[30];
assertEquals(9, reader.read(array, 0, 30));
代码示例来源:origin: loklak/loklak_server
long startCharacter = this.character;
long startLine = this.line;
this.reader.mark(1000000);
do {
c = this.next();
this.reader.reset();
this.index = startIndex;
this.character = startCharacter;
this.reader.mark(1);
} catch (IOException exception) {
throw new JSONException(exception);
代码示例来源:origin: com.sun.jersey/jersey-json
private static Reader ensureNonEmptyReader(Reader reader) throws XMLStreamException {
try {
Reader mr = reader.markSupported() ? reader : new BufferedReader(reader);
mr.mark(1);
if (mr.read() == -1) {
throw new XMLStreamException("JSON expression can not be empty!");
}
mr.reset();
return mr;
} catch (IOException ex) {
throw new XMLStreamException(ex);
}
}
代码示例来源:origin: alibaba/mdrill
int startCharacter = this.character;
int startLine = this.line;
reader.mark(Integer.MAX_VALUE);
do {
c = next();
if (c == 0) {
reader.reset();
this.index = startIndex;
this.character = startCharacter;
内容来源于网络,如有侵权,请联系作者删除!