Class ByteSource.Util

java.lang.Object
org.apache.shiro.lang.util.ByteSource.Util
Enclosing interface:
ByteSource

public static final class ByteSource.Util extends Object
Utility class that can construct ByteSource instances. This is slightly nicer than needing to know the ByteSource implementation class to use.
Since:
1.2
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static ByteSource
    bytes(byte[] bytes)
    Returns a new ByteSource instance representing the specified byte array.
    static ByteSource
    bytes(char[] chars)
    Returns a new ByteSource instance representing the specified character array's bytes.
    static ByteSource
    bytes(File file)
    Returns a new ByteSource instance representing the specified File's bytes.
    static ByteSource
    Returns a new ByteSource instance representing the specified InputStream's bytes.
    static ByteSource
    bytes(Object source)
    Returns a ByteSource instance representing the specified byte source argument.
    static ByteSource
    bytes(String string)
    Returns a new ByteSource instance representing the specified string's bytes.
    static ByteSource
    bytes(ByteSource source)
    Returns a new ByteSource instance representing the specified ByteSource.
    static boolean
    Returns true if the specified object can be easily represented as a ByteSource using the ByteSource.Util's default heuristics, false otherwise.

    Methods inherited from class java.lang.Object

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

    • Util

      public Util()
  • Method Details

    • bytes

      public static ByteSource bytes(byte[] bytes)
      Returns a new ByteSource instance representing the specified byte array.
      Parameters:
      bytes - the bytes to represent as a ByteSource instance.
      Returns:
      a new ByteSource instance representing the specified byte array.
    • bytes

      public static ByteSource bytes(char[] chars)
      Returns a new ByteSource instance representing the specified character array's bytes. The byte array is obtained assuming UTF-8 encoding.
      Parameters:
      chars - the character array to represent as a ByteSource instance.
      Returns:
      a new ByteSource instance representing the specified character array's bytes.
    • bytes

      public static ByteSource bytes(String string)
      Returns a new ByteSource instance representing the specified string's bytes. The byte array is obtained assuming UTF-8 encoding.
      Parameters:
      string - the string to represent as a ByteSource instance.
      Returns:
      a new ByteSource instance representing the specified string's bytes.
    • bytes

      public static ByteSource bytes(ByteSource source)
      Returns a new ByteSource instance representing the specified ByteSource.
      Parameters:
      source - the ByteSource to represent as a new ByteSource instance.
      Returns:
      a new ByteSource instance representing the specified ByteSource.
    • bytes

      public static ByteSource bytes(File file)
      Returns a new ByteSource instance representing the specified File's bytes.
      Parameters:
      file - the file to represent as a ByteSource instance.
      Returns:
      a new ByteSource instance representing the specified File's bytes.
    • bytes

      public static ByteSource bytes(InputStream stream)
      Returns a new ByteSource instance representing the specified InputStream's bytes.
      Parameters:
      stream - the InputStream to represent as a ByteSource instance.
      Returns:
      a new ByteSource instance representing the specified InputStream's bytes.
    • isCompatible

      public static boolean isCompatible(Object source)
      Returns true if the specified object can be easily represented as a ByteSource using the ByteSource.Util's default heuristics, false otherwise.

      This implementation merely returns SimpleByteSource.isCompatible(source).

      Parameters:
      source - the object to test to see if it can be easily converted to ByteSource instances using default heuristics.
      Returns:
      true if the specified object can be easily represented as a ByteSource using the ByteSource.Util's default heuristics, false otherwise.
    • bytes

      public static ByteSource bytes(Object source) throws IllegalArgumentException
      Returns a ByteSource instance representing the specified byte source argument. If the argument cannot be easily converted to bytes (as is indicated by the isCompatible(Object) JavaDoc), this method will throw an IllegalArgumentException.
      Parameters:
      source - the byte-backed instance that should be represented as a ByteSource instance.
      Returns:
      a ByteSource instance representing the specified byte source argument.
      Throws:
      IllegalArgumentException - if the argument cannot be easily converted to bytes (as indicated by the isCompatible(Object) JavaDoc)