/** * Converts this pipe into a {@link ParserReader}. * * @return The converted pipe. * @throws Exception */ public ParserReader getParserReader() throws Exception { if (input == null) return null; if (input instanceof ParserReader) parserReader = (ParserReader)input; else parserReader = new ParserReader(this); return parserReader; }
/** * Converts this pipe into a {@link ParserReader}. * * @return The converted pipe. * @throws Exception */ public ParserReader getParserReader() throws Exception { if (input == null) return null; if (input instanceof ParserReader) parserReader = (ParserReader)input; else parserReader = new ParserReader(this); return parserReader; }
/** * Converts this pipe into a {@link ParserReader}. * * @return The converted pipe. * @throws Exception */ public ParserReader getParserReader() throws Exception { if (input == null) return null; if (input instanceof ParserReader) parserReader = (ParserReader)input; else parserReader = new ParserReader(this); return parserReader; }
reader = new ParserReader(this); doClose = false; } else if (input instanceof InputStream || input instanceof byte[]) {
reader = new ParserReader(this); doClose = false; } else if (input instanceof InputStream || input instanceof byte[]) {
reader = new ParserReader(this); doClose = false; } else if (input instanceof InputStream || input instanceof byte[]) {
private ParserReader createParserReader(Object in) throws Exception { return new ParserReader(new ParserPipe(in)); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testParseNumberFromReader() throws Exception { ParserReader in; Number n; for (Class c : new Class[]{ Integer.class, Double.class, Float.class, Long.class, Short.class, Byte.class, BigInteger.class, BigDecimal.class, Number.class, AtomicInteger.class, AtomicLong.class}) { in = new ParserReader(new ParserPipe("123'")); n = parseNumber(in, c); assertTrue(c.isInstance(n)); assertEquals(123, n.intValue()); } }
@Test public void test() throws Exception { ParserReader r = new ParserReader(new ParserPipe("abc123")); try { assertEquals('a', r.read()); r.unread(); assertEquals('a', r.read()); assertEquals('b', r.read()); r.unread(); assertEquals("bc", r.read(2)); assertEquals('1', r.read()); r.unread(); r.read(); assertEquals('2', r.peek()); assertEquals('2', r.peek()); assertEquals('2', r.read()); assertEquals('3', r.read()); assertEquals(-1, r.read()); assertEquals(-1, r.read()); } finally { r.close(); } } }