This commit is contained in:
wentch
2015-12-24 09:23:17 +08:00
parent 1ba02bb412
commit 9f6b4bde8a
4 changed files with 10 additions and 5 deletions

View File

@@ -36,7 +36,7 @@ public final class DLongSimpledCoder<R extends Reader, W extends Writer> extends
public DLong convertFrom(R in) {
byte[] bs = bsSimpledCoder.convertFrom(in);
if (bs == null) return null;
return new DLong(bs);
return DLong.create(bs);
}
}

View File

@@ -29,6 +29,6 @@ public class DLongJsonSimpledCoder extends JsonSimpledCoder<DLong> {
public DLong convertFrom(JsonReader in) {
final String str = in.readString();
if (str == null) return null;
return new DLong(Utility.hexToBin(str));
return DLong.create(Utility.hexToBin(str));
}
}

View File

@@ -95,7 +95,7 @@ public abstract class Sncp {
synchronized (md5) {
bytes = md5.digest(bytes);
}
return new DLong(bytes);
return DLong.create(bytes);
}
public static boolean isRemote(Service service) {

View File

@@ -27,7 +27,7 @@ public final class DLong extends Number implements Comparable<DLong> {
(byte) (v2 >> 24), (byte) (v2 >> 16), (byte) (v2 >> 8), (byte) v2};
}
public DLong(byte[] bytes) {
protected DLong(byte[] bytes) {
if (bytes == null || bytes.length != 16) throw new NumberFormatException("Not 16 length bytes");
this.bytes = bytes;
}
@@ -40,6 +40,11 @@ public final class DLong extends Number implements Comparable<DLong> {
return bytes;
}
public static DLong create(byte[] bytes) {
if (ZERO.equals(bytes)) return ZERO;
return new DLong(bytes);
}
public static DLong read(ByteBuffer buffer) {
byte[] bs = new byte[16];
buffer.get(bs);
@@ -71,7 +76,7 @@ public final class DLong extends Number implements Comparable<DLong> {
@Override
public String toString() {
if(this == ZERO) return "0";
if (this == ZERO) return "0";
return new String(Utility.binToHex(bytes));
}