## net.i2p.data
Class Hash

    java.lang.Object
      net.i2p.data.DataStructureImpl
          net.i2p.data.SimpleDataStructure
              net.i2p.data.Hash

All Implemented Interfaces:
  DataStructure

Direct Known Subclasses:
  LocalHash

    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
`static Hash` `FAKE_HASH`
`static int` `HASH_LENGTH`

Fields inherited from class net.i2p.data.SimpleDataStructure
`_data, _length`

Constructor Summary
`Hash()`
`Hash(byte[] data)`

Method Summary
`static Hash` `create(byte[] data)` Pull from cache or return new
`static Hash` `create(byte[] data, int off)` Pull from cache or return new
`static Hash` `create(InputStream in)` Pull from cache or return new
`int` `hashCode()` a Hash is a hash, so just use the first 4 bytes for speed
`int` `length()` The legal length of the byte array in this data structure
`void` `readBytes(InputStream in)` Sets the data.
`void` `setData(byte[] data)` Sets the data.
`String` `toBase64()` render the structure into modified base 64 notation

Methods inherited from class net.i2p.data.SimpleDataStructure
`calculateHash, equals, fromBase64, fromByteArray, getData, toByteArray, toString, writeBytes`

Methods inherited from class net.i2p.data.DataStructureImpl
`read`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### HASH_LENGTH

    public static final int HASH_LENGTH

See Also:
  Constant Field Values

### FAKE_HASH

    public static final Hash FAKE_HASH

Constructor Detail

### Hash

    public Hash()

### Hash

    public Hash(byte[] data)

Throws:
  `IllegalArgumentException` - if data is not 32 bytes (null is ok)

Method Detail

### create

    public static Hash create(byte[] data)

  Pull from cache or return new

  Since:
    0.8.3

### create

    public static Hash create(byte[] data,
                              int off)

  Pull from cache or return new

  Since:
    0.8.3

### create

    public static Hash create(InputStream in)
                       throws IOException

  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 class `SimpleDataStructure`

### setData

    public void setData(byte[] data)

  Description copied from class: `SimpleDataStructure`
  Sets the data.

  Overrides:
    `setData` in class `SimpleDataStructure`
  Parameters:
    `data` - of correct length, or null
  Throws:
    `IllegalArgumentException` - if data is not 32 bytes (null is ok)

### readBytes

    public void readBytes(InputStream in)
                   throws DataFormatException,
                          IOException

  Description copied from class: `SimpleDataStructure`
  Sets the data.

  Specified by:
    `readBytes` in interface `DataStructure`
  Overrides:
    `readBytes` in class `SimpleDataStructure`
  Parameters:
    `in` - the stream to read
  Throws:
    `DataFormatException` - if the data is improperly formatted
    `IOException` - 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 class `SimpleDataStructure`

### toBase64

    public String toBase64()

  Description copied from interface: `DataStructure`
  render the structure into modified base 64 notation

  Specified by:
    `toBase64` in interface `DataStructure`
  Overrides:
    `toBase64` in class `SimpleDataStructure`
  Returns:
    null on error