Class MemoryClearingBuffer


  • public final class MemoryClearingBuffer
    extends Object
    A buffer for storing sensitive information like passwords. It provides useful operations for characters such as character encoding/decoding, whitespace trimming, and lowercasing. It can be cleared out when operations are complete.
    Author:
    Apache Directory Project
    • Method Detail

      • newInstance

        public static MemoryClearingBuffer newInstance​(byte[] bytes)
        Creates a new instance of MemoryClearingBuffer from a byte[].
        Parameters:
        bytes - A byte[]
        Returns:
        A buffer
      • newInstance

        public static MemoryClearingBuffer newInstance​(char[] chars)
        Creates a new instance of MemoryClearingBuffer from a char[].
        Parameters:
        chars - A char[]
        Returns:
        A buffer
      • newInstance

        public static MemoryClearingBuffer newInstance​(char[] chars,
                                                       boolean trim,
                                                       boolean lowerCase)
        Creates a new instance of MemoryClearingBuffer from a char[], optionally performing whitespace trimming and conversion to lower case.
        Parameters:
        chars - A char[]
        trim - If true, whitespace will be trimmed off of both ends of the char[]
        lowerCase - If true, the characters will be converted to lower case
        Returns:
        A buffer
      • clear

        public void clear()
        Clears the buffer out, filling its cells with null.
      • getBytes

        public byte[] getBytes()
        Returns the byte[] used to create this buffer, or getComputedBytes() if created with a char[].
        Returns:
        A byte[]
      • getChars

        public char[] getChars()
        Returns the char[] used to create this buffer, or getComputedChars() if created with a byte[].
        Returns:
        A byte[]