use of com.fasterxml.jackson.core.util.BufferRecycler in project jackson-core by FasterXML.
the class TestIOContext method testAllocations.
public void testAllocations() throws Exception {
IOContext ctxt = new IOContext(new BufferRecycler(), "N/A", true);
/* I/O Read buffer */
// First succeeds:
assertNotNull(ctxt.allocReadIOBuffer());
// second fails
try {
ctxt.allocReadIOBuffer();
} catch (IllegalStateException e) {
verifyException(e, "second time");
}
// Also: can't succeed with different buffer
try {
ctxt.releaseReadIOBuffer(new byte[1]);
} catch (IllegalArgumentException e) {
verifyException(e, "smaller than original");
}
// but call with null is a NOP for convenience
ctxt.releaseReadIOBuffer(null);
/* I/O Write buffer */
assertNotNull(ctxt.allocWriteEncodingBuffer());
try {
ctxt.allocWriteEncodingBuffer();
} catch (IllegalStateException e) {
verifyException(e, "second time");
}
try {
ctxt.releaseWriteEncodingBuffer(new byte[1]);
} catch (IllegalArgumentException e) {
verifyException(e, "smaller than original");
}
ctxt.releaseWriteEncodingBuffer(null);
/* Token (read) buffer */
assertNotNull(ctxt.allocTokenBuffer());
try {
ctxt.allocTokenBuffer();
} catch (IllegalStateException e) {
verifyException(e, "second time");
}
try {
ctxt.releaseTokenBuffer(new char[1]);
} catch (IllegalArgumentException e) {
verifyException(e, "smaller than original");
}
ctxt.releaseTokenBuffer(null);
/* Concat (write?) buffer */
assertNotNull(ctxt.allocConcatBuffer());
try {
ctxt.allocConcatBuffer();
} catch (IllegalStateException e) {
verifyException(e, "second time");
}
try {
ctxt.releaseConcatBuffer(new char[1]);
} catch (IllegalArgumentException e) {
verifyException(e, "smaller than original");
}
ctxt.releaseConcatBuffer(null);
/* NameCopy (write?) buffer */
assertNotNull(ctxt.allocNameCopyBuffer(100));
try {
ctxt.allocNameCopyBuffer(100);
} catch (IllegalStateException e) {
verifyException(e, "second time");
}
try {
ctxt.releaseNameCopyBuffer(new char[1]);
} catch (IllegalArgumentException e) {
verifyException(e, "smaller than original");
}
ctxt.releaseNameCopyBuffer(null);
}
use of com.fasterxml.jackson.core.util.BufferRecycler in project jackson-core by FasterXML.
the class UTF8WriterTest method testFlushAfterClose.
public void testFlushAfterClose() throws Exception {
BufferRecycler rec = new BufferRecycler();
IOContext ctxt = new IOContext(rec, null, false);
ByteArrayOutputStream out = new ByteArrayOutputStream();
UTF8Writer w = new UTF8Writer(ctxt, out);
w.write('X');
char[] ch = { 'Y' };
w.write(ch);
w.close();
assertEquals(2, out.size());
// and this ought to be fine...
w.flush();
// as well as some more...
w.close();
w.flush();
}
use of com.fasterxml.jackson.core.util.BufferRecycler in project jackson-core by FasterXML.
the class TestUtf8Generator method testUtf8Issue462.
public void testUtf8Issue462() throws Exception {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
IOContext ioc = new IOContext(new BufferRecycler(), bytes, true);
JsonGenerator gen = new UTF8JsonGenerator(ObjectWriteContext.empty(), ioc, 0, bytes, JsonFactory.DEFAULT_ROOT_VALUE_SEPARATOR, null, null);
String str = "Natuurlijk is alles gelukt en weer een tevreden klant\uD83D\uDE04";
int length = 4000 - 38;
for (int i = 1; i <= length; ++i) {
gen.writeNumber(1);
}
gen.writeString(str);
gen.flush();
gen.close();
// Also verify it's parsable?
JsonParser p = JSON_F.createParser(ObjectReadContext.empty(), bytes.toByteArray());
for (int i = 1; i <= length; ++i) {
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(1, p.getIntValue());
}
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertEquals(str, p.getText());
assertNull(p.nextToken());
p.close();
}
use of com.fasterxml.jackson.core.util.BufferRecycler in project jackson-core by FasterXML.
the class UTF8DataInputJsonParserTest method test_readBinaryThrowsNullPointerException.
@Test
public void test_readBinaryThrowsNullPointerException() throws IOException {
byte[] byteArray = new byte[5];
byteArray[4] = (byte) 43;
IOContext ioContext = new IOContext(new BufferRecycler(), byteArray, false);
InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(), ioContext, 500, dataInputStream, byteQuadsCanonicalizer, 1);
try {
uTF8DataInputJsonParser._readBinary(null, null, byteArray);
fail("Expecting exception: NullPointerException");
} catch (NullPointerException e) {
assertEquals(UTF8DataInputJsonParser.class.getName(), e.getStackTrace()[0].getClassName());
}
}
use of com.fasterxml.jackson.core.util.BufferRecycler in project jackson-core by FasterXML.
the class UTF8DataInputJsonParserTest method testNextBooleanValueThrowsIOException.
@Test
public void testNextBooleanValueThrowsIOException() {
IOContext ioContext = new IOContext(new BufferRecycler(), this, false);
byte[] byteArray = new byte[12];
byteArray[4] = (byte) (-10);
InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(), ioContext, 100, dataInputStream, null, 11);
try {
uTF8DataInputJsonParser.nextBooleanValue();
fail("Expecting exception: IOException");
} catch (IOException e) {
assertEquals(JsonParser.class.getName(), e.getStackTrace()[0].getClassName());
}
}
Aggregations