Refine search
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); } }
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(); } }
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); } }
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(); } }
/** * 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; }
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();
@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(); }
/** * 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; }
/** * 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; }
/** * 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; }
@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(); }
/** * 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; }
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));
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); } }