Package net.i2p.data
Class Hash
java.lang.Object
net.i2p.data.SimpleDataStructure
net.i2p.data.Hash
- All Implemented Interfaces:
DataStructure
public class Hash extends SimpleDataStructure
Defines the hash as defined by the I2P data structure spec.
A hash is the SHA-256 of some data, taking up 32 bytes.
- Author:
- jrandom
-
Field Summary
Fields Modifier and Type Field Description static Hash
FAKE_HASH
static int
HASH_LENGTH
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description static void
clearCache()
static Hash
create(byte[] data)
Pull from cache or return new WARNING - If the SDS is found in the cache, the passed-in byte array will be returned to the SimpleByteCache for reuse.static Hash
create(byte[] data, int off)
Pull from cache or return newstatic Hash
create(InputStream in)
Pull from cache or return newint
hashCode()
a Hash is a hash, so just use the first 4 bytes for speedint
length()
The legal length of the byte array in this data structurevoid
readBytes(InputStream in)
Sets the data.void
setData(byte[] data)
Sets the data.String
toBase32()
For convenience.String
toBase64()
render the structure into modified base 64 notationMethods inherited from class net.i2p.data.SimpleDataStructure
calculateHash, equals, fromBase64, fromByteArray, getData, read, toByteArray, toString, writeBytes
-
Field Details
-
HASH_LENGTH
public static final int HASH_LENGTH- See Also:
- Constant Field Values
-
FAKE_HASH
-
-
Constructor Details
-
Hash
public Hash() -
Hash
public Hash(byte[] data)- Throws:
IllegalArgumentException
- if data is not 32 bytes (null is ok)
-
-
Method Details
-
create
Pull from cache or return new WARNING - If the SDS is found in the cache, the passed-in byte array will be returned to the SimpleByteCache for reuse. Do NOT save a reference to the passed-in data, or use or modify it, after this call. Ignore this warning and you WILL corrupt the cache or other data structures.- Throws:
IllegalArgumentException
- if data is not the correct number of bytes- Since:
- 0.8.3
-
create
Pull from cache or return new- Throws:
ArrayIndexOutOfBoundsException
- if not enough bytes- Since:
- 0.8.3
-
create
Pull from cache or return new- Throws:
IOException
- Since:
- 0.8.3
-
length
public int length()Description copied from class:SimpleDataStructure
The legal length of the byte array in this data structure- Specified by:
length
in classSimpleDataStructure
-
setData
public void setData(byte[] data)Description copied from class:SimpleDataStructure
Sets the data.- Overrides:
setData
in classSimpleDataStructure
- Parameters:
data
- of correct length, or null- Throws:
IllegalArgumentException
- if data is not 32 bytes (null is ok)
-
readBytes
Description copied from class:SimpleDataStructure
Sets the data.- Specified by:
readBytes
in interfaceDataStructure
- Overrides:
readBytes
in classSimpleDataStructure
- Parameters:
in
- the stream to read- Throws:
DataFormatException
- if the data is improperly formattedIOException
- if there was a problem reading the stream
-
hashCode
public int hashCode()a Hash is a hash, so just use the first 4 bytes for speed- Overrides:
hashCode
in classSimpleDataStructure
-
toBase64
Description copied from interface:DataStructure
render the structure into modified base 64 notation- Specified by:
toBase64
in interfaceDataStructure
- Overrides:
toBase64
in classSimpleDataStructure
- Returns:
- null on error
-
toBase32
For convenience.- Returns:
- "{52 chars}.b32.i2p" or null if data not set.
- Since:
- 0.9.25
-
clearCache
public static void clearCache()- Since:
- 0.9.17
-