Class RecyclableBuffers

java.lang.Object
com.amazonaws.xray.internal.RecyclableBuffers

public final class RecyclableBuffers
extends java.lang.Object
ThreadLocal buffers for use when creating new derived objects such as Strings. These buffers are reused within a single thread - it is _not safe_ to use the buffer to generate multiple derived objects at the same time because the same memory will be used. In general, you should get a temporary buffer, fill it with data, and finish by converting into the derived object within the same method to avoid multiple usages of the same buffer.
  • Method Summary

    Modifier and Type Method Description
    static byte[] bytes​(int length)
    A ThreadLocal byte[] of length length.
    static char[] chars​(int length)
    A ThreadLocal char[] of length length.
    static java.lang.StringBuilder stringBuilder()
    A ThreadLocal StringBuilder.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • stringBuilder

      public static java.lang.StringBuilder stringBuilder()
      A ThreadLocal StringBuilder. Take care when filling a large value into this buffer because the memory will remain for the lifetime of the thread.
    • chars

      public static char[] chars​(int length)
      A ThreadLocal char[] of length length. The array is not zeroed in any way - every character of a resulting String must be set explicitly. The array returned may be longer than length - always explicitly set the length when using the result, for example by calling String.valueOf(char[], int, int).
    • bytes

      public static byte[] bytes​(int length)
      A ThreadLocal byte[] of length length. The array is not zeroed in any way.