1
1
package com .fasterxml .jackson .dataformat .smile ;
2
2
3
3
import java .io .*;
4
- import java .lang .ref .SoftReference ;
5
4
import java .math .BigDecimal ;
6
5
import java .math .BigInteger ;
7
6
import java .util .Arrays ;
@@ -281,26 +280,16 @@ public SharedStringNode(String value, int index, SharedStringNode next)
281
280
282
281
/*
283
282
/**********************************************************************
284
- /* Thread-local recycling
283
+ /* Life-cycle
285
284
/**********************************************************************
286
285
*/
287
286
288
287
/**
289
- * This <code>ThreadLocal</code> contains a {@link java.lang.ref.SoftReference}
290
- * to a buffer recycler used to provide a low-cost
291
- * buffer recycling for Smile-specific buffers.
292
- */
293
- final protected static ThreadLocal <SoftReference <SmileBufferRecycler >> _smileRecyclerRef
294
- = new ThreadLocal <SoftReference <SmileBufferRecycler >>();
295
-
296
- /*
297
- /**********************************************************************
298
- /* Life-cycle
299
- /**********************************************************************
288
+ * @since 2.16
300
289
*/
301
-
302
290
public SmileGenerator (IOContext ioCtxt , int stdFeatures , int smileFeatures ,
303
- ObjectCodec codec , OutputStream out )
291
+ ObjectCodec codec , OutputStream out ,
292
+ SmileBufferRecycler sbr )
304
293
{
305
294
super (stdFeatures , codec , ioCtxt , /*WriteContext*/ null );
306
295
DupDetector dups = JsonGenerator .Feature .STRICT_DUPLICATE_DETECTION .enabledIn (stdFeatures )
@@ -310,7 +299,7 @@ public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
310
299
_streamWriteContext = SmileWriteContext .createRootContext (dups );
311
300
_formatFeatures = smileFeatures ;
312
301
_streamWriteConstraints = ioCtxt .streamWriteConstraints ();
313
- _smileBufferRecycler = _smileBufferRecycler () ;
302
+ _smileBufferRecycler = sbr ;
314
303
_out = out ;
315
304
_bufferRecyclable = true ;
316
305
_outputBuffer = ioCtxt .allocWriteEncodingBuffer ();
@@ -344,9 +333,13 @@ public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
344
333
}
345
334
}
346
335
336
+ /**
337
+ * @since 2.16
338
+ */
347
339
public SmileGenerator (IOContext ioCtxt , int stdFeatures , int smileFeatures ,
348
- ObjectCodec codec , OutputStream out , byte [] outputBuffer , int offset ,
349
- boolean bufferRecyclable )
340
+ ObjectCodec codec , OutputStream out ,
341
+ SmileBufferRecycler sbr ,
342
+ byte [] outputBuffer , int offset , boolean bufferRecyclable )
350
343
{
351
344
super (stdFeatures , codec , ioCtxt , null );
352
345
DupDetector dups = JsonGenerator .Feature .STRICT_DUPLICATE_DETECTION .enabledIn (stdFeatures )
@@ -356,7 +349,7 @@ public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
356
349
_streamWriteContext = SmileWriteContext .createRootContext (dups );
357
350
_formatFeatures = smileFeatures ;
358
351
_streamWriteConstraints = ioCtxt .streamWriteConstraints ();
359
- _smileBufferRecycler = _smileBufferRecycler () ;
352
+ _smileBufferRecycler = sbr ;
360
353
_out = out ;
361
354
_bufferRecyclable = bufferRecyclable ;
362
355
_outputTail = offset ;
@@ -391,6 +384,29 @@ public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
391
384
}
392
385
}
393
386
387
+ /**
388
+ * @deprecated Since 2.16
389
+ */
390
+ @ Deprecated // @since 2.16
391
+ public SmileGenerator (IOContext ioCtxt , int stdFeatures , int smileFeatures ,
392
+ ObjectCodec codec , OutputStream out )
393
+ {
394
+ this (ioCtxt , stdFeatures , smileFeatures , codec , out , new SmileBufferRecycler ());
395
+ }
396
+
397
+ /**
398
+ * @deprecated Since 2.16
399
+ */
400
+ @ Deprecated // @since 2.16
401
+ public SmileGenerator (IOContext ioCtxt , int stdFeatures , int smileFeatures ,
402
+ ObjectCodec codec , OutputStream out ,
403
+ byte [] outputBuffer , int offset , boolean bufferRecyclable )
404
+ {
405
+ this (ioCtxt , stdFeatures , smileFeatures ,
406
+ codec , out , new SmileBufferRecycler (),
407
+ outputBuffer , offset , bufferRecyclable );
408
+ }
409
+
394
410
/**
395
411
* Method that can be called to explicitly write Smile document header.
396
412
* Note that usually you do not need to call this for first document to output,
@@ -413,18 +429,6 @@ public void writeHeader() throws IOException
413
429
_writeBytes (HEADER_BYTE_1 , HEADER_BYTE_2 , HEADER_BYTE_3 , (byte ) last );
414
430
}
415
431
416
- protected final static SmileBufferRecycler _smileBufferRecycler ()
417
- {
418
- SoftReference <SmileBufferRecycler > ref = _smileRecyclerRef .get ();
419
- SmileBufferRecycler br = (ref == null ) ? null : ref .get ();
420
-
421
- if (br == null ) {
422
- br = new SmileBufferRecycler ();
423
- _smileRecyclerRef .set (new SoftReference <SmileBufferRecycler >(br ));
424
- }
425
- return br ;
426
- }
427
-
428
432
/*
429
433
/**********************************************************
430
434
/* Versioned
0 commit comments