本文整理了Java中org.apache.gobblin.util.guid.Guid.<init>()
方法的一些代码示例,展示了Guid.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Guid.<init>()
方法的具体详情如下:
包路径:org.apache.gobblin.util.guid.Guid
类名称:Guid
方法名:<init>
[英]Creates a Guid by computing the sha of the input bytes.
[中]通过计算输入字节的sha来创建Guid。
代码示例来源:origin: apache/incubator-gobblin
/**
* Generate a {@link Guid} for an array of byte arrays.
* @param byteArrays array of byte arrays.
* @return a single {@link Guid} for the array.
* @throws IOException
*/
public static Guid fromByteArrays(byte[]... byteArrays) throws IOException {
if (byteArrays == null || byteArrays.length == 0) {
throw new IOException("Attempting to compute guid for an empty array.");
}
if (byteArrays.length == 1) {
return new Guid(byteArrays[0]);
}
byte[] tmp = new byte[0];
for (byte[] arr : byteArrays) {
tmp = ArrayUtils.addAll(tmp, arr);
}
return new Guid(tmp);
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Generate a {@link Guid} for an array of Strings.
* @param strings array of Strings.
* @return a single {@link Guid} for the array.
* @throws IOException
*/
public static Guid fromStrings(String... strings) throws IOException {
if (strings == null || strings.length == 0) {
throw new IOException("Attempting to compute guid for an empty array.");
}
return new Guid(StringUtils.join(strings).getBytes(Charsets.UTF_8));
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Reverse of {@link #toString}. Deserializes a {@link Guid} from a previously serialized one.
* @param str Serialized {@link Guid}.
* @return deserialized {@link Guid}.
* @throws IOException
*/
public static Guid deserialize(String str) throws IOException {
if (str.length() != 2 * GUID_LENGTH) {
throw new IOException("String is not an encoded guid.");
}
try {
return new Guid(Hex.decodeHex(str.toCharArray()), true);
} catch (DecoderException de) {
throw new IOException(de);
}
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testUniqueReplicable() {
Random random = new Random();
byte[] b = new byte[10];
random.nextBytes(b);
Assert.assertEquals(new Guid(b), new Guid(b));
byte[] other = new byte[10];
for (int i = 0; i < 1000; i++) {
random.nextBytes(other);
Assert.assertNotEquals(new Guid(b), new Guid(other));
}
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testLength() {
Assert.assertEquals(new Guid(new byte[0]).sha.length, Guid.GUID_LENGTH);
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testFromHasGuid() throws IOException {
Random random = new Random();
byte[] b = new byte[10];
random.nextBytes(b);
Guid guid = new Guid(b);
HasGuid hasGuid = new Guid.SimpleHasGuid(guid);
Assert.assertEquals(hasGuid.guid(), guid);
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testSerDe() throws Exception {
Random random = new Random();
byte[] b = new byte[10];
random.nextBytes(b);
Guid guid = new Guid(b);
Assert.assertEquals(guid.toString().length(), 2 * Guid.GUID_LENGTH);
Assert.assertEquals(guid, Guid.deserialize(guid.toString()));
}
代码示例来源:origin: org.apache.gobblin/gobblin-utility
/**
* Generate a {@link Guid} for an array of Strings.
* @param strings array of Strings.
* @return a single {@link Guid} for the array.
* @throws IOException
*/
public static Guid fromStrings(String... strings) throws IOException {
if (strings == null || strings.length == 0) {
throw new IOException("Attempting to compute guid for an empty array.");
}
return new Guid(StringUtils.join(strings).getBytes(Charsets.UTF_8));
}
代码示例来源:origin: org.apache.gobblin/gobblin-utility
/**
* Generate a {@link Guid} for an array of byte arrays.
* @param byteArrays array of byte arrays.
* @return a single {@link Guid} for the array.
* @throws IOException
*/
public static Guid fromByteArrays(byte[]... byteArrays) throws IOException {
if (byteArrays == null || byteArrays.length == 0) {
throw new IOException("Attempting to compute guid for an empty array.");
}
if (byteArrays.length == 1) {
return new Guid(byteArrays[0]);
}
byte[] tmp = new byte[0];
for (byte[] arr : byteArrays) {
tmp = ArrayUtils.addAll(tmp, arr);
}
return new Guid(tmp);
}
代码示例来源:origin: org.apache.gobblin/gobblin-utility
/**
* Reverse of {@link #toString}. Deserializes a {@link Guid} from a previously serialized one.
* @param str Serialized {@link Guid}.
* @return deserialized {@link Guid}.
* @throws IOException
*/
public static Guid deserialize(String str) throws IOException {
if (str.length() != 2 * GUID_LENGTH) {
throw new IOException("String is not an encoded guid.");
}
try {
return new Guid(Hex.decodeHex(str.toCharArray()), true);
} catch (DecoderException de) {
throw new IOException(de);
}
}
内容来源于网络,如有侵权,请联系作者删除!