Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,9 @@ private final int _writeBytes(InputStream in, int bytesLeft) throws IOException
_flushBuffer();
room = _outputEnd - _outputTail;
}
if (room > bytesLeft) {
room = bytesLeft;
}
int count = in.read(_outputBuffer, _outputTail, room);
if (count < 0) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.Assert;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.dataformat.smile.SmileGenerator.Feature;

public class TestSmileGeneratorBinary extends SmileTestBase
{
Expand Down Expand Up @@ -60,6 +61,37 @@ public void testBinaryWithoutLength() throws Exception
jg.close();
}

public void testStreamingBinaryPartly() throws Exception {
_testStreamingBinaryPartly(true);
_testStreamingBinaryPartly(false);
}

private void _testStreamingBinaryPartly(boolean rawBinary) throws Exception
{
final SmileFactory f = new SmileFactory();
f.configure(Feature.ENCODE_BINARY_AS_7BIT, rawBinary);

final byte[] INPUT = TEXT4.getBytes("UTF-8");
ByteArrayInputStream in = new ByteArrayInputStream(INPUT);

ByteArrayOutputStream out = new ByteArrayOutputStream();
JsonGenerator jg = f.createGenerator(out);
jg.writeStartArray();
jg.writeBinary(in, 1);
jg.writeEndArray();
jg.close();
in.close();

JsonParser jp = f.createParser(out.toByteArray());
assertToken(JsonToken.START_ARRAY, jp.nextToken());
assertToken(JsonToken.VALUE_EMBEDDED_OBJECT, jp.nextToken());
byte[] b = jp.getBinaryValue();
assertToken(JsonToken.END_ARRAY, jp.nextToken());
jp.close();

assertEquals(1, b.length);
}

/*
/**********************************************************
/* Helper methods
Expand Down