org.apache.shiro.util
Class SimpleByteSource

java.lang.Object
  extended by org.apache.shiro.util.SimpleByteSource
All Implemented Interfaces:
ByteSource

public class SimpleByteSource
extends Object
implements ByteSource

Very simple ByteSource implementation that maintains an internal byte[] array and uses the Hex and Base64 codec classes to support the toHex() and toBase64() implementations.

The constructors on this class accept the following implicit byte-backed data types and will convert them to a byte-array automatically:

Since:
1.0

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.shiro.util.ByteSource
ByteSource.Util
 
Constructor Summary
SimpleByteSource(byte[] bytes)
           
SimpleByteSource(ByteSource source)
          Creates an instance using the sources bytes directly - it does not create a copy of the argument's byte array.
SimpleByteSource(char[] chars)
          Creates an instance by converting the characters to a byte array (assumes UTF-8 encoding).
SimpleByteSource(File file)
          Creates an instance by converting the file to a byte array.
SimpleByteSource(InputStream stream)
          Creates an instance by converting the stream to a byte array.
SimpleByteSource(String string)
          Creates an instance by converting the String to a byte array (assumes UTF-8 encoding).
 
Method Summary
 boolean equals(Object o)
           
 byte[] getBytes()
          Returns the wrapped byte array.
 int hashCode()
           
static boolean isCompatible(Object o)
          Returns true if the specified object is a recognized data type that can be easily converted to bytes by instances of this class, false otherwise.
 boolean isEmpty()
          Returns true if the underlying wrapped byte array is null or empty (zero length), false otherwise.
 String toBase64()
          Returns the Base 64-formatted String representation of the underlying wrapped byte array.
 String toHex()
          Returns the Hex-formatted String representation of the underlying wrapped byte array.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleByteSource

public SimpleByteSource(byte[] bytes)

SimpleByteSource

public SimpleByteSource(char[] chars)
Creates an instance by converting the characters to a byte array (assumes UTF-8 encoding).

Parameters:
chars - the source characters to use to create the underlying byte array.
Since:
1.1

SimpleByteSource

public SimpleByteSource(String string)
Creates an instance by converting the String to a byte array (assumes UTF-8 encoding).

Parameters:
string - the source string to convert to a byte array (assumes UTF-8 encoding).
Since:
1.1

SimpleByteSource

public SimpleByteSource(ByteSource source)
Creates an instance using the sources bytes directly - it does not create a copy of the argument's byte array.

Parameters:
source - the source to use to populate the underlying byte array.
Since:
1.1

SimpleByteSource

public SimpleByteSource(File file)
Creates an instance by converting the file to a byte array.

Parameters:
file - the file from which to acquire bytes.
Since:
1.1

SimpleByteSource

public SimpleByteSource(InputStream stream)
Creates an instance by converting the stream to a byte array.

Parameters:
stream - the stream from which to acquire bytes.
Since:
1.1
Method Detail

isCompatible

public static boolean isCompatible(Object o)
Returns true if the specified object is a recognized data type that can be easily converted to bytes by instances of this class, false otherwise.

This implementation returns true IFF the specified object is an instance of one of the following types:

Parameters:
o - the object to test to see if it can be easily converted to bytes by instances of this class.
Returns:
true if the specified object can be easily converted to bytes by instances of this class, false otherwise.
Since:
1.2

getBytes

public byte[] getBytes()
Description copied from interface: ByteSource
Returns the wrapped byte array.

Specified by:
getBytes in interface ByteSource
Returns:
the wrapped byte array.

isEmpty

public boolean isEmpty()
Description copied from interface: ByteSource
Returns true if the underlying wrapped byte array is null or empty (zero length), false otherwise.

Specified by:
isEmpty in interface ByteSource
Returns:
true if the underlying wrapped byte array is null or empty (zero length), false otherwise.

toHex

public String toHex()
Description copied from interface: ByteSource
Returns the Hex-formatted String representation of the underlying wrapped byte array.

Specified by:
toHex in interface ByteSource
Returns:
the Hex-formatted String representation of the underlying wrapped byte array.

toBase64

public String toBase64()
Description copied from interface: ByteSource
Returns the Base 64-formatted String representation of the underlying wrapped byte array.

Specified by:
toBase64 in interface ByteSource
Returns:
the Base 64-formatted String representation of the underlying wrapped byte array.

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object


Copyright © 2004-2012 The Apache Software Foundation. All Rights Reserved.