/** * First call will return the original Reader provided. */ @Override public Reader giveAClone() { if (original != null) { Reader rtn = original; original = null; // no longer hold a reference return rtn; } return new FastCharArrayReader(originalContent); }
/** * Tells whether this stream is ready to be read. Character-array readers * are always ready to be read. * * @throws IOException If an I/O error occurs */ @Override public boolean ready() throws IOException { ensureOpen(); return (count - pos) > 0; }
/** * Resets the stream to the most recent mark, or to the beginning if it has * never been marked. * * @throws IOException If an I/O error occurs */ @Override public void reset() throws IOException { ensureOpen(); pos = markedPos; }
public static int analyze(Analyzer analyzer, CharsRef toAnalyze, String field, TokenConsumer consumer) throws IOException { try (TokenStream ts = analyzer.tokenStream( field, new FastCharArrayReader(toAnalyze.chars, toAnalyze.offset, toAnalyze.length))) { return analyze(ts, consumer); } }
/** * Resets the stream to the most recent mark, or to the beginning if it has * never been marked. * * @throws IOException If an I/O error occurs */ @Override public void reset() throws IOException { ensureOpen(); pos = markedPos; }
public static int analyze(Analyzer analyzer, BytesRef toAnalyze, String field, TokenConsumer consumer, CharsRefBuilder spare) throws IOException { spare.copyUTF8Bytes(toAnalyze); CharsRef charsRef = spare.get(); try (TokenStream ts = analyzer.tokenStream( field, new FastCharArrayReader(charsRef.chars, charsRef.offset, charsRef.length))) { return analyze(ts, consumer); } }
/** * Resets the stream to the most recent mark, or to the beginning if it has * never been marked. * * @throws IOException If an I/O error occurs */ @Override public void reset() throws IOException { ensureOpen(); pos = markedPos; }
public TokenStream tokenStream(Analyzer analyzer, BytesRef query, CharsRefBuilder spare, String field) throws IOException { spare.copyUTF8Bytes(query); return analyzer.tokenStream(field, new FastCharArrayReader(spare.chars(), 0, spare.length())); }
/** * Tells whether this stream is ready to be read. Character-array readers * are always ready to be read. * * @throws IOException If an I/O error occurs */ @Override public boolean ready() throws IOException { ensureOpen(); return (count - pos) > 0; }
public TokenStream tokenStream(Analyzer analyzer, BytesRef query, CharsRefBuilder spare, String field) throws IOException { spare.copyUTF8Bytes(query); return analyzer.tokenStream(field, new FastCharArrayReader(spare.chars(), 0, spare.length())); }
/** * Tells whether this stream is ready to be read. Character-array readers * are always ready to be read. * * @throws IOException If an I/O error occurs */ @Override public boolean ready() throws IOException { ensureOpen(); return (count - pos) > 0; }
/** * Reads a single character. * * @throws IOException If an I/O error occurs */ @Override public int read() throws IOException { ensureOpen(); if (pos >= count) return -1; else return buf[pos++]; }
/** * Reads a single character. * * @throws IOException If an I/O error occurs */ @Override public int read() throws IOException { ensureOpen(); if (pos >= count) return -1; else return buf[pos++]; }
/** * Reads a single character. * * @throws IOException If an I/O error occurs */ @Override public int read() throws IOException { ensureOpen(); if (pos >= count) return -1; else return buf[pos++]; }
/** * Marks the present position in the stream. Subsequent calls to reset() * will reposition the stream to this point. * * @param readAheadLimit Limit on the number of characters that may be * read while still preserving the mark. Because * the stream's input comes from a character array, * there is no actual limit; hence this argument is * ignored. * @throws IOException If an I/O error occurs */ @Override public void mark(int readAheadLimit) throws IOException { ensureOpen(); markedPos = pos; }
/** * Marks the present position in the stream. Subsequent calls to reset() * will reposition the stream to this point. * * @param readAheadLimit Limit on the number of characters that may be * read while still preserving the mark. Because * the stream's input comes from a character array, * there is no actual limit; hence this argument is * ignored. * @throws IOException If an I/O error occurs */ @Override public void mark(int readAheadLimit) throws IOException { ensureOpen(); markedPos = pos; }
/** * Marks the present position in the stream. Subsequent calls to reset() * will reposition the stream to this point. * * @param readAheadLimit Limit on the number of characters that may be * read while still preserving the mark. Because * the stream's input comes from a character array, * there is no actual limit; hence this argument is * ignored. * @throws IOException If an I/O error occurs */ @Override public void mark(int readAheadLimit) throws IOException { ensureOpen(); markedPos = pos; }
/** * Skips characters. Returns the number of characters that were skipped. * <p> * The <code>n</code> parameter may be negative, even though the * <code>skip</code> method of the {@link Reader} superclass throws * an exception in this case. If <code>n</code> is negative, then * this method does nothing and returns <code>0</code>. * * @param n The number of characters to skip * @return The number of characters actually skipped * @throws IOException If the stream is closed, or an I/O error occurs */ @Override public long skip(long n) throws IOException { ensureOpen(); if (pos + n > count) { n = count - pos; } if (n < 0) { return 0; } pos += n; return n; }
/** * Skips characters. Returns the number of characters that were skipped. * <p> * The <code>n</code> parameter may be negative, even though the * <code>skip</code> method of the {@link Reader} superclass throws * an exception in this case. If <code>n</code> is negative, then * this method does nothing and returns <code>0</code>. * * @param n The number of characters to skip * @return The number of characters actually skipped * @throws IOException If the stream is closed, or an I/O error occurs */ @Override public long skip(long n) throws IOException { ensureOpen(); if (pos + n > count) { n = count - pos; } if (n < 0) { return 0; } pos += n; return n; }
/** * Skips characters. Returns the number of characters that were skipped. * <p> * The <code>n</code> parameter may be negative, even though the * <code>skip</code> method of the {@link Reader} superclass throws * an exception in this case. If <code>n</code> is negative, then * this method does nothing and returns <code>0</code>. * * @param n The number of characters to skip * @return The number of characters actually skipped * @throws IOException If the stream is closed, or an I/O error occurs */ @Override public long skip(long n) throws IOException { ensureOpen(); if (pos + n > count) { n = count - pos; } if (n < 0) { return 0; } pos += n; return n; }