use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class AsyncTokenFilterTest method testSkipChildrenFailOnSplit.
public void testSkipChildrenFailOnSplit() {
NonBlockingJsonParser nbParser = _nonBlockingParser();
FilteringParserDelegate filteredParser = new FilteringParserDelegate(nbParser, TOKEN_FILTER, Inclusion.INCLUDE_ALL_AND_PATH, true);
nbParser.feedInput(INPUT_BYTES, 0, 5);
assertToken(JsonToken.START_OBJECT, nbParser.nextToken());
try {
nbParser.skipChildren();
fail("Should not pass!");
} catch (StreamReadException e) {
verifyException(e, "not enough content available");
verifyException(e, "skipChildren()");
}
filteredParser.close();
nbParser.close();
}
use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class ArrayParsingTest method _testMissingValueNotEnablingFeature.
private void _testMissingValueNotEnablingFeature(boolean useStream) throws Exception {
final String DOC = "[ \"a\",,\"abc\"] ";
JsonFactory f = new JsonFactory();
JsonParser p = useStream ? createParserUsingStream(f, DOC, "UTF-8") : createParserUsingReader(f, DOC);
assertToken(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals("a", p.getValueAsString());
try {
assertToken(JsonToken.VALUE_STRING, p.nextToken());
fail("Expecting exception here");
} catch (StreamReadException ex) {
verifyException(ex, "expected a valid value", "expected a value");
}
p.close();
}
use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class NonStandardAposQuotedNamesTest method _testSingleQuotesDefault.
/*
/****************************************************************
/* Secondary test methods
/****************************************************************
*/
/**
* Test to verify that the default parser settings do not
* accept single-quotes for String values (field names,
* textual values)
*/
private void _testSingleQuotesDefault(int mode) throws Exception {
// First, let's see that by default they are not allowed
String JSON = "[ 'text' ]";
try (JsonParser p = createParser(STD_F, mode, JSON)) {
assertToken(JsonToken.START_ARRAY, p.nextToken());
p.nextToken();
fail("Expected exception");
} catch (StreamReadException e) {
verifyException(e, "Unexpected character ('''");
}
JSON = "{ 'a':1 }";
try (JsonParser p = createParser(STD_F, mode, JSON)) {
assertToken(JsonToken.START_OBJECT, p.nextToken());
p.nextToken();
fail("Expected exception");
} catch (StreamReadException e) {
verifyException(e, "Unexpected character ('''");
}
}
use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class ParserErrorHandlingTest method doTestInvalidKeyword1.
private void doTestInvalidKeyword1(int mode, String value) {
String doc = "{ \"key1\" : " + value + " }";
JsonParser p = createParser(mode, doc);
assertToken(JsonToken.START_OBJECT, p.nextToken());
// get the exception early or late...
try {
assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
p.nextToken();
fail("Expected an exception for malformed value keyword");
} catch (StreamReadException jex) {
verifyException(jex, "Unrecognized token");
verifyException(jex, value);
} finally {
p.close();
}
// Try as root-level value as well:
// may need space after for DataInput
doc = value + " ";
p = createParser(mode, doc);
try {
p.nextToken();
fail("Expected an exception for malformed value keyword");
} catch (StreamReadException jex) {
verifyException(jex, "Unrecognized token");
verifyException(jex, value);
} finally {
p.close();
}
}
use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class AsyncReaderWrapperForByteArray method nextToken.
@Override
public JsonToken nextToken() {
JsonToken token;
while ((token = _streamReader.nextToken()) == JsonToken.NOT_AVAILABLE) {
ByteArrayFeeder feeder = (ByteArrayFeeder) _streamReader.nonBlockingInputFeeder();
if (!feeder.needMoreInput()) {
throw new StreamReadException(null, "Got NOT_AVAILABLE, could not feed more input");
}
int amount = Math.min(_bytesPerFeed, _end - _offset);
if (amount < 1) {
// end-of-input?
feeder.endOfInput();
} else {
// padding?
if (_padding == 0) {
feeder.feedInput(_doc, _offset, _offset + amount);
} else {
byte[] tmp = new byte[amount + _padding + _padding];
System.arraycopy(_doc, _offset, tmp, _padding, amount);
feeder.feedInput(tmp, _padding, _padding + amount);
}
_offset += amount;
}
}
return token;
}
Aggregations