Fixed #354
diff --git a/release-notes/VERSION b/release-notes/VERSION
index 1c212b8..3f7e691 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -14,6 +14,10 @@
=== Releases ===
------------------------------------------------------------------------
+2.7.10 (not yet released)
+
+#354: Buffer size dependency in UTF8JsonGenerator writeRaw
+
2.7.9 (04-Feb-2017)
No changes since 2.7.8
diff --git a/src/main/java/com/fasterxml/jackson/core/json/UTF8JsonGenerator.java b/src/main/java/com/fasterxml/jackson/core/json/UTF8JsonGenerator.java
index 5524691..2b82fcf 100644
--- a/src/main/java/com/fasterxml/jackson/core/json/UTF8JsonGenerator.java
+++ b/src/main/java/com/fasterxml/jackson/core/json/UTF8JsonGenerator.java
@@ -530,9 +530,10 @@
public void writeRaw(String text, int offset, int len) throws IOException
{
final char[] buf = _charBuffer;
+ final int cbufLen = buf.length;
// minor optimization: see if we can just get and copy
- if (len <= buf.length) {
+ if (len <= cbufLen) {
text.getChars(offset, offset+len, buf, 0);
writeRaw(buf, 0, len);
return;
@@ -541,7 +542,8 @@
// If not, need segmented approach. For speed, let's also use input buffer
// size that is guaranteed to fit in output buffer; each char can expand to
// at most 3 bytes, so at most 1/3 of buffer size.
- final int maxChunk = (_outputEnd >> 2) + (_outputEnd >> 4); // == (1/4 + 1/16) == 5/16
+ final int maxChunk = Math.min(cbufLen,
+ (_outputEnd >> 2) + (_outputEnd >> 4)); // == (1/4 + 1/16) == 5/16
final int maxBytes = maxChunk * 3;
while (len > 0) {