Class MemoryClearingBuffer

java.lang.Object
org.apache.directory.ldap.client.template.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 Summary

    Modifier and Type
    Method
    Description
    void
    Clears the buffer out, filling its cells with null.
    byte[]
    Returns the byte[] used to create this buffer, or getComputedBytes() if created with a char[].
    char[]
    Returns the char[] used to create this buffer, or getComputedChars() if created with a byte[].
    newInstance(byte[] bytes)
    Creates a new instance of MemoryClearingBuffer from a byte[].
    newInstance(char[] chars)
    Creates a new instance of MemoryClearingBuffer from a char[].
    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.

    Methods inherited from class Object

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

    • 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[]