/** * Read and consume the next character * * @param appendable * the read character is appended to appendable */ public final void pop(Appendable appendable) { try { appendable.append((char) pop()); } catch (IOException e) { throw new ChannelException(e.getMessage(), e); } }
/** * Read without consuming the next characters until a condition is reached (EndMatcher) * * @param matcher * the EndMatcher used to stop the reading * @param appendable * the read characters is appended to appendable */ public final void peekTo(EndMatcher matcher, Appendable appendable) { int index = 0; char nextChar = charAt(index); try { while (!matcher.match(nextChar) && nextChar != -1) { appendable.append(nextChar); nextChar = charAt(++index); } } catch (IOException e) { throw new ChannelException(e.getMessage(), e); } }
/** * @deprecated in 2.2, use {@link #popTo(Matcher matcher, Appendable appendable)} instead */ @Deprecated public final void popTo(EndMatcher matcher, Appendable appendable) { previousCursor = getCursor().clone(); try { do { appendable.append((char) pop()); } while (!matcher.match(peek()) && peek() != -1); } catch (IOException e) { throw new ChannelException(e.getMessage(), e); } }
throw new ChannelException("Unable to apply regular expression '" + matcher.pattern().pattern() + "' at line " + getCursor().getLine() + " and column " + getCursor().getColumn() + ", because it led to a stack overflow error." return -1; } catch (IOException e) { throw new ChannelException(e.getMessage(), e);
/** * Note that this constructor will read everything from reader and will close it. */ protected CodeBuffer(Reader initialCodeReader, CodeReaderConfiguration configuration) { Reader reader = null; try { lastChar = -1; cursor = new Cursor(); tabWidth = configuration.getTabWidth(); /* Setup the filters on the reader */ reader = initialCodeReader; for (CodeReaderFilter<?> codeReaderFilter : configuration.getCodeReaderFilters()) { reader = new Filter(reader, codeReaderFilter, configuration); } buffer = IOUtils.toCharArray(reader); } catch (IOException e) { throw new ChannelException(e.getMessage(), e); } finally { IOUtils.closeQuietly(reader); } }