Package org.apache.shiro.lang.util
Class SimpleByteSource
java.lang.Object
org.apache.shiro.lang.util.SimpleByteSource
- All Implemented Interfaces:
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:
- byte[]
- char[]
- String
ByteSourceFileInputStream
- Since:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.shiro.lang.util.ByteSource
ByteSource.Util -
Constructor Summary
ConstructorsConstructorDescriptionSimpleByteSource(byte[] bytes) 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).SimpleByteSource(ByteSource source) Creates an instance using the sources bytes directly - it does not create a copy of the argument's byte array. -
Method Summary
Modifier and TypeMethodDescriptionstatic ByteSourceempty()booleanbyte[]getBytes()Returns the wrapped byte array.inthashCode()static booleanReturnstrueif the specified object is a recognized data type that can be easily converted to bytes by instances of this class,falseotherwise.booleanisEmpty()Returnstrueif the underlying wrapped byte array is null or empty (zero length),falseotherwise.toBase64()Returns the Base 64-formatted String representation of the underlying wrapped byte array.toHex()Returns the Hex-formatted String representation of the underlying wrapped byte array.toString()
-
Constructor Details
-
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
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
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
Creates an instance by converting the file to a byte array.- Parameters:
file- the file from which to acquire bytes.- Since:
- 1.1
-
SimpleByteSource
Creates an instance by converting the stream to a byte array.- Parameters:
stream- the stream from which to acquire bytes.- Since:
- 1.1
-
-
Method Details
-
isCompatible
Returnstrueif the specified object is a recognized data type that can be easily converted to bytes by instances of this class,falseotherwise. This implementation returnstrueIFF the specified object is an instance of one of the following types:byte[]char[]ByteSourceStringFile
InputStream- Parameters:
o- the object to test to see if it can be easily converted to bytes by instances of this class.- Returns:
trueif the specified object can be easily converted to bytes by instances of this class,falseotherwise.- Since:
- 1.2
-
empty
-
getBytes
public byte[] getBytes()Description copied from interface:ByteSourceReturns the wrapped byte array.- Specified by:
getBytesin interfaceByteSource- Returns:
- the wrapped byte array.
-
isEmpty
public boolean isEmpty()Description copied from interface:ByteSourceReturnstrueif the underlying wrapped byte array is null or empty (zero length),falseotherwise.- Specified by:
isEmptyin interfaceByteSource- Returns:
trueif the underlying wrapped byte array is null or empty (zero length),falseotherwise.
-
toHex
Description copied from interface:ByteSourceReturns the Hex-formatted String representation of the underlying wrapped byte array.- Specified by:
toHexin interfaceByteSource- Returns:
- the Hex-formatted String representation of the underlying wrapped byte array.
-
toBase64
Description copied from interface:ByteSourceReturns the Base 64-formatted String representation of the underlying wrapped byte array.- Specified by:
toBase64in interfaceByteSource- Returns:
- the Base 64-formatted String representation of the underlying wrapped byte array.
-
toString
-
hashCode
public int hashCode() -
equals
-