@@ -109,9 +109,6 @@ public void setEncoding(JsonEncoding enc) {
109
109
_encoding = enc ;
110
110
}
111
111
112
- /**
113
- * @since 1.6
114
- */
115
112
public IOContext withEncoding (JsonEncoding enc ) {
116
113
_encoding = enc ;
117
114
return this ;
@@ -138,29 +135,54 @@ public TextBuffer constructTextBuffer() {
138
135
}
139
136
140
137
/**
138
+ * Method for recycling or allocation byte buffer of "read I/O" type.
141
139
*<p>
142
140
* Note: the method can only be called once during its life cycle.
143
141
* This is to protect against accidental sharing.
142
+ *
143
+ * @return Allocated or recycled byte buffer
144
144
*/
145
145
public byte [] allocReadIOBuffer () {
146
146
_verifyAlloc (_readIOBuffer );
147
147
return (_readIOBuffer = _bufferRecycler .allocByteBuffer (BufferRecycler .BYTE_READ_IO_BUFFER ));
148
148
}
149
149
150
150
/**
151
+ * Variant of {@link #allocReadIOBuffer()} that specifies smallest acceptable
152
+ * buffer size.
153
+ *
154
+ * @param minSize Minimum size of the buffer to recycle or allocate
155
+ *
156
+ * @return Allocated or recycled byte buffer
157
+ *
151
158
* @since 2.4
152
159
*/
153
160
public byte [] allocReadIOBuffer (int minSize ) {
154
161
_verifyAlloc (_readIOBuffer );
155
162
return (_readIOBuffer = _bufferRecycler .allocByteBuffer (BufferRecycler .BYTE_READ_IO_BUFFER , minSize ));
156
163
}
157
-
164
+
165
+ /**
166
+ * Method for recycling or allocation byte buffer of "write encoding" type.
167
+ *<p>
168
+ * Note: the method can only be called once during its life cycle.
169
+ * This is to protect against accidental sharing.
170
+ *
171
+ * @return Allocated or recycled byte buffer
172
+ */
158
173
public byte [] allocWriteEncodingBuffer () {
159
174
_verifyAlloc (_writeEncodingBuffer );
160
175
return (_writeEncodingBuffer = _bufferRecycler .allocByteBuffer (BufferRecycler .BYTE_WRITE_ENCODING_BUFFER ));
161
176
}
162
177
163
178
/**
179
+ * Variant of {@link #allocWriteEncodingBuffer()} that specifies smallest acceptable
180
+ * buffer size.
181
+ *
182
+ * @param minSize Minimum size of the buffer to recycle or allocate
183
+ *
184
+ * @return Allocated or recycled byte buffer
185
+ *
164
186
* @since 2.4
165
187
*/
166
188
public byte [] allocWriteEncodingBuffer (int minSize ) {
@@ -169,14 +191,26 @@ public byte[] allocWriteEncodingBuffer(int minSize) {
169
191
}
170
192
171
193
/**
172
- * @since 2.1
194
+ * Method for recycling or allocation byte buffer of "base 64 encode/decode" type.
195
+ *<p>
196
+ * Note: the method can only be called once during its life cycle.
197
+ * This is to protect against accidental sharing.
198
+ *
199
+ * @return Allocated or recycled byte buffer
173
200
*/
174
201
public byte [] allocBase64Buffer () {
175
202
_verifyAlloc (_base64Buffer );
176
203
return (_base64Buffer = _bufferRecycler .allocByteBuffer (BufferRecycler .BYTE_BASE64_CODEC_BUFFER ));
177
204
}
178
205
179
206
/**
207
+ * Variant of {@link #allocBase64Buffer()} that specifies smallest acceptable
208
+ * buffer size.
209
+ *
210
+ * @param minSize Minimum size of the buffer to recycle or allocate
211
+ *
212
+ * @return Allocated or recycled byte buffer
213
+ *
180
214
* @since 2.9
181
215
*/
182
216
public byte [] allocBase64Buffer (int minSize ) {
@@ -189,9 +223,7 @@ public char[] allocTokenBuffer() {
189
223
return (_tokenCBuffer = _bufferRecycler .allocCharBuffer (BufferRecycler .CHAR_TOKEN_BUFFER ));
190
224
}
191
225
192
- /**
193
- * @since 2.4
194
- */
226
+ // @since 2.4
195
227
public char [] allocTokenBuffer (int minSize ) {
196
228
_verifyAlloc (_tokenCBuffer );
197
229
return (_tokenCBuffer = _bufferRecycler .allocCharBuffer (BufferRecycler .CHAR_TOKEN_BUFFER , minSize ));
@@ -210,12 +242,13 @@ public char[] allocNameCopyBuffer(int minSize) {
210
242
/**
211
243
* Method to call when all the processing buffers can be safely
212
244
* recycled.
245
+ *
246
+ * @param buf Buffer instance to release (return for recycling)
213
247
*/
214
248
public void releaseReadIOBuffer (byte [] buf ) {
215
249
if (buf != null ) {
216
- /* Let's do sanity checks to ensure once-and-only-once release,
217
- * as well as avoiding trying to release buffers not owned
218
- */
250
+ // Let's do sanity checks to ensure once-and-only-once release,
251
+ // as well as avoiding trying to release buffers not owned
219
252
_verifyRelease (buf , _readIOBuffer );
220
253
_readIOBuffer = null ;
221
254
_bufferRecycler .releaseByteBuffer (BufferRecycler .BYTE_READ_IO_BUFFER , buf );
@@ -224,9 +257,8 @@ public void releaseReadIOBuffer(byte[] buf) {
224
257
225
258
public void releaseWriteEncodingBuffer (byte [] buf ) {
226
259
if (buf != null ) {
227
- /* Let's do sanity checks to ensure once-and-only-once release,
228
- * as well as avoiding trying to release buffers not owned
229
- */
260
+ // Let's do sanity checks to ensure once-and-only-once release,
261
+ // as well as avoiding trying to release buffers not owned
230
262
_verifyRelease (buf , _writeEncodingBuffer );
231
263
_writeEncodingBuffer = null ;
232
264
_bufferRecycler .releaseByteBuffer (BufferRecycler .BYTE_WRITE_ENCODING_BUFFER , buf );
@@ -268,9 +300,9 @@ public void releaseNameCopyBuffer(char[] buf) {
268
300
}
269
301
270
302
/*
271
- /**********************************************************
303
+ /**********************************************************************
272
304
/* Internal helpers
273
- /**********************************************************
305
+ /**********************************************************************
274
306
*/
275
307
276
308
protected final void _verifyAlloc (Object buffer ) {
0 commit comments