forked from I2P_Developers/i2p.i2p
2004-10-23 jrandom
* Minor ministreaming lib refactoring to simplify integration of the full streaming lib. * Minor bugfixes to data structure serialization.
This commit is contained in:
@ -15,9 +15,8 @@ import java.io.Serializable;
|
||||
* Wrap up an array of bytes so that they can be compared and placed in hashes,
|
||||
* maps, and the like.
|
||||
*
|
||||
* @author jrandom
|
||||
*/
|
||||
public class ByteArray implements Serializable {
|
||||
public class ByteArray implements Serializable, Comparable {
|
||||
private byte[] _data;
|
||||
|
||||
public ByteArray() {
|
||||
@ -28,7 +27,7 @@ public class ByteArray implements Serializable {
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
public final byte[] getData() {
|
||||
return _data;
|
||||
}
|
||||
|
||||
@ -36,7 +35,7 @@ public class ByteArray implements Serializable {
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
public final boolean equals(Object o) {
|
||||
if (o == null) return false;
|
||||
if (o instanceof ByteArray) {
|
||||
return compare(getData(), ((ByteArray) o).getData());
|
||||
@ -50,15 +49,20 @@ public class ByteArray implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean compare(byte[] lhs, byte[] rhs) {
|
||||
private static final boolean compare(byte[] lhs, byte[] rhs) {
|
||||
return DataHelper.eq(lhs, rhs);
|
||||
}
|
||||
|
||||
public final int compareTo(Object obj) {
|
||||
if (obj.getClass() != getClass()) throw new ClassCastException("invalid object: " + obj);
|
||||
return DataHelper.compareTo(_data, ((ByteArray)obj).getData());
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
public final int hashCode() {
|
||||
return DataHelper.hashCode(getData());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
public final String toString() {
|
||||
return DataHelper.toString(getData(), 32);
|
||||
}
|
||||
}
|
@ -102,10 +102,11 @@ public class Destination extends DataStructureImpl {
|
||||
_signingKey = new SigningPublicKey();
|
||||
buf = new byte[SigningPublicKey.KEYSIZE_BYTES];
|
||||
System.arraycopy(source, cur, buf, 0, SigningPublicKey.KEYSIZE_BYTES);
|
||||
_signingKey.setData(buf);
|
||||
cur += SigningPublicKey.KEYSIZE_BYTES;
|
||||
|
||||
_certificate = new Certificate();
|
||||
cur += _certificate.readBytes(buf, cur);
|
||||
cur += _certificate.readBytes(source, cur);
|
||||
|
||||
return cur - offset;
|
||||
}
|
||||
|
Reference in New Issue
Block a user