@@ -54,17 +54,38 @@ public void call(JsonGenerator g, byte[] data, int offset, int len) throws Excep
54
54
g .writeBinary (data , offset , len );
55
55
}
56
56
};
57
-
57
+
58
+ private final ByteBackedOperation WRITE_RAW_UTF8_FROM_BYTES = new ByteBackedOperation () {
59
+ @ Override
60
+ public void call (JsonGenerator g , byte [] data , int offset , int len ) throws Exception {
61
+ g .writeRawUTF8String (data , offset , len );
62
+ }
63
+ };
64
+
65
+ private final ByteBackedOperation WRITE_UTF8_STRING_FROM_BYTES = new ByteBackedOperation () {
66
+ @ Override
67
+ public void call (JsonGenerator g , byte [] data , int offset , int len ) throws Exception {
68
+ g .writeUTF8String (data , offset , len );
69
+ }
70
+ };
71
+
58
72
public void testBoundsWithByteArrayInputFromBytes () throws Exception {
59
- // _testBoundsWithByteArrayInput(BYTE_GENERATOR_CREATOR);
73
+ _testBoundsWithByteArrayInput (BYTE_GENERATOR_CREATOR , true );
60
74
}
61
75
62
76
public void testBoundsWithByteArrayInputFromChars () throws Exception {
63
- // _testBoundsWithByteArrayInput(CHAR_GENERATOR_CREATOR);
77
+ _testBoundsWithByteArrayInput (CHAR_GENERATOR_CREATOR , false );
64
78
}
65
79
66
- private void _testBoundsWithByteArrayInput (GeneratorCreator genc ) throws Exception {
80
+ private void _testBoundsWithByteArrayInput (GeneratorCreator genc , boolean byteBacked )
81
+ throws Exception {
67
82
_testBoundsWithByteArrayInput (genc , WRITE_BINARY_FROM_BYTES );
83
+ // NOTE: byte[] writes of pre-encoded UTF-8 not supported for Writer-backed
84
+ // generator, so:
85
+ if (byteBacked ) {
86
+ _testBoundsWithByteArrayInput (genc , WRITE_RAW_UTF8_FROM_BYTES );
87
+ _testBoundsWithByteArrayInput (genc , WRITE_UTF8_STRING_FROM_BYTES );
88
+ }
68
89
}
69
90
70
91
private void _testBoundsWithByteArrayInput (GeneratorCreator genc ,
@@ -83,7 +104,7 @@ private void _testBoundsWithByteArrayInput(GeneratorCreator genc,
83
104
} catch (StreamWriteException e ) {
84
105
verifyException (e , "Invalid 'offset'" );
85
106
verifyException (e , "'len'" );
86
- verifyException (e , "arguments for String of length " +data .length );
107
+ verifyException (e , "arguments for `byte[]` of length " +data .length );
87
108
}
88
109
}
89
110
}
@@ -96,7 +117,21 @@ private void _testBoundsWithByteArrayInput(GeneratorCreator genc,
96
117
97
118
// // // Individual generator calls to check, char[]-backed
98
119
120
+ private final CharBackedOperation WRITE_NUMBER_FROM_CHARS = new CharBackedOperation () {
121
+ @ Override
122
+ public void call (JsonGenerator g , char [] data , int offset , int len ) throws Exception {
123
+ g .writeNumber (data , offset , len );
124
+ }
125
+ };
126
+
99
127
private final CharBackedOperation WRITE_RAW_FROM_CHARS = new CharBackedOperation () {
128
+ @ Override
129
+ public void call (JsonGenerator g , char [] data , int offset , int len ) throws Exception {
130
+ g .writeRaw (data , offset , len );
131
+ }
132
+ };
133
+
134
+ private final CharBackedOperation WRITE_RAWVALUE_FROM_CHARS = new CharBackedOperation () {
100
135
@ Override
101
136
public void call (JsonGenerator g , char [] data , int offset , int len ) throws Exception {
102
137
g .writeRawValue (data , offset , len );
@@ -112,7 +147,9 @@ public void testBoundsWithCharArrayInputFromChars() throws Exception {
112
147
}
113
148
114
149
private void _testBoundsWithCharArrayInput (GeneratorCreator genc ) throws Exception {
150
+ _testBoundsWithCharArrayInput (genc , WRITE_NUMBER_FROM_CHARS );
115
151
_testBoundsWithCharArrayInput (genc , WRITE_RAW_FROM_CHARS );
152
+ _testBoundsWithCharArrayInput (genc , WRITE_RAWVALUE_FROM_CHARS );
116
153
}
117
154
118
155
private void _testBoundsWithCharArrayInput (GeneratorCreator genc ,
0 commit comments