1 package com.fasterxml.jackson.core.testsupport; 2 3 import java.io.IOException; 4 import java.io.StringWriter; 5 import java.math.BigDecimal; 6 import java.math.BigInteger; 7 8 import com.fasterxml.jackson.core.JsonParser; 9 import com.fasterxml.jackson.core.JsonParser.NumberType; 10 import com.fasterxml.jackson.core.JsonStreamContext; 11 import com.fasterxml.jackson.core.JsonToken; 12 13 public abstract class AsyncReaderWrapper 14 { 15 protected final JsonParser _streamReader; 16 AsyncReaderWrapper(JsonParser sr)17 protected AsyncReaderWrapper(JsonParser sr) { 18 _streamReader = sr; 19 } 20 currentToken()21 public JsonToken currentToken() throws IOException { 22 return _streamReader.currentToken(); 23 } currentText()24 public String currentText() throws IOException { 25 return _streamReader.getText(); 26 } 27 currentTextViaCharacters()28 public String currentTextViaCharacters() throws IOException 29 { 30 char[] ch = _streamReader.getTextCharacters(); 31 int start = _streamReader.getTextOffset(); 32 int len = _streamReader.getTextLength(); 33 return new String(ch, start, len); 34 } 35 currentTextViaWriter()36 public String currentTextViaWriter() throws IOException 37 { 38 StringWriter sw = new StringWriter(); 39 int len = _streamReader.getText(sw); 40 String str = sw.toString(); 41 if (len != str.length()) { 42 throw new IllegalStateException(String.format( 43 "Reader.getText(Writer) returned %d, but wrote %d chars", 44 len, str.length())); 45 } 46 return str; 47 } 48 currentName()49 public String currentName() throws IOException { 50 return _streamReader.getCurrentName(); 51 } 52 parser()53 public JsonParser parser() { return _streamReader; } 54 nextToken()55 public abstract JsonToken nextToken() throws IOException; 56 getParsingContext()57 public JsonStreamContext getParsingContext() { 58 return _streamReader.getParsingContext(); 59 } 60 getIntValue()61 public int getIntValue() throws IOException { return _streamReader.getIntValue(); } getLongValue()62 public long getLongValue() throws IOException { return _streamReader.getLongValue(); } getFloatValue()63 public float getFloatValue() throws IOException { return _streamReader.getFloatValue(); } getDoubleValue()64 public double getDoubleValue() throws IOException { return _streamReader.getDoubleValue(); } getBigIntegerValue()65 public BigInteger getBigIntegerValue() throws IOException { return _streamReader.getBigIntegerValue(); } getDecimalValue()66 public BigDecimal getDecimalValue() throws IOException { return _streamReader.getDecimalValue(); } getBinaryValue()67 public byte[] getBinaryValue() throws IOException { return _streamReader.getBinaryValue(); } 68 getNumberValue()69 public Number getNumberValue() throws IOException { return _streamReader.getNumberValue(); } getNumberType()70 public NumberType getNumberType() throws IOException { return _streamReader.getNumberType(); } 71 close()72 public void close() throws IOException { _streamReader.close(); } 73 isClosed()74 public boolean isClosed() { 75 return _streamReader.isClosed(); 76 } 77 } 78