本文整理了Java中org.apache.gobblin.util.guid.Guid
类的一些代码示例,展示了Guid
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Guid
类的具体详情如下:
包路径:org.apache.gobblin.util.guid.Guid
类名称:Guid
[英]Class wrapping a byte array representing a guid. A Guid is intended to uniquely identify objects in a replicable way.
[中]类包装表示guid的字节数组。Guid用于以可复制的方式唯一标识对象。
代码示例来源:origin: apache/incubator-gobblin
@Override
public String getStateStoreNameFromDatasetUrn(String datasetUrn)
throws IOException {
if (!this.sanitizedNameToDatasetURNMap.inverse().containsKey(datasetUrn)) {
String guid = Guid.fromStrings(datasetUrn).toString();
this.sanitizedNameToDatasetURNMap.put(guid, datasetUrn);
}
return this.sanitizedNameToDatasetURNMap.inverse().get(datasetUrn);
}
}
代码示例来源:origin: apache/incubator-gobblin
private static String computeGuid(State state, CopyEntity file) throws IOException {
Optional<Guid> stateGuid = CopySource.getWorkUnitGuid(state);
if (stateGuid.isPresent()) {
return Guid.combine(file.guid(), stateGuid.get()).toString();
}
throw new IOException("State does not contain a 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: apache/incubator-gobblin
private static void computeAndSetWorkUnitGuid(WorkUnit workUnit)
throws IOException {
Guid guid = Guid.fromStrings(workUnit.contains(ConfigurationKeys.CONVERTER_CLASSES_KEY) ? workUnit
.getProp(ConfigurationKeys.CONVERTER_CLASSES_KEY) : "");
setWorkUnitGuid(workUnit, guid.append(deserializeCopyEntity(workUnit)));
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public Guid guid() throws IOException {
return Guid.fromStrings(toString());
}
代码示例来源: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
/**
* Set a unique, replicable guid for this work unit. Used for recovering partially successful work units.
* @param state {@link State} where guid should be written.
* @param guid A byte array guid.
*/
public static void setWorkUnitGuid(State state, Guid guid) {
state.setProp(WORK_UNIT_GUID, guid.toString());
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Creates a new {@link Guid} which is a unique, replicable representation of the pair (this, guids). Equivalent to
* combine(this, guid1, guid2, ...)
* @param guids an array of {@link Guid}.
* @return a new {@link Guid}.
* @throws IOException
*/
public Guid append(Guid... guids) throws IOException {
if (guids == null || guids.length == 0) {
return this;
}
return combine(ArrayUtils.add(guids, this));
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Creates a new {@link Guid} which is a unique, replicable representation of the pair (this, objs).
* @param objs an array of {@link HasGuid}.
* @return a new {@link Guid}.
* @throws IOException
*/
public Guid append(HasGuid... objs) throws IOException {
if (objs == null || objs.length == 0) {
return this;
}
return fromHasGuid(ArrayUtils.add(objs, new SimpleHasGuid(this)));
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Combine multiple {@link Guid}s into a single {@link Guid}.
* @throws IOException
*/
public static Guid combine(Guid... guids) throws IOException {
byte[][] byteArrays = new byte[guids.length][];
for (int i = 0; i < guids.length; i++) {
byteArrays[i] = guids[i].sha;
}
return fromByteArrays(byteArrays);
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Get guid in this state if available. This is the reverse operation of {@link #setWorkUnitGuid}.
* @param state State from which guid should be extracted.
* @return A byte array guid.
* @throws IOException
*/
public static Optional<Guid> getWorkUnitGuid(State state)
throws IOException {
if (state.contains(WORK_UNIT_GUID)) {
return Optional.of(Guid.deserialize(state.getProp(WORK_UNIT_GUID)));
}
return Optional.absent();
}
代码示例来源:origin: apache/incubator-gobblin
/**
* @param bytes byte array.
* @param isSha true if bytes are already a sha.
*/
private Guid(byte[] bytes, boolean isSha) {
if (isSha) {
this.sha = bytes;
} else {
this.sha = computeGuid(bytes);
}
}
代码示例来源:origin: apache/incubator-gobblin
Guid newGuid = oldGuid.append(Guid.fromStrings(serializedSplit));
代码示例来源:origin: apache/incubator-gobblin
/**
* Generates a replicable guid to uniquely identify the origin of this {@link CopyableFile}.
* @return a guid uniquely identifying the origin file.
*/
@Override
public Guid guid() throws IOException {
StringBuilder uniqueString = new StringBuilder();
uniqueString.append(getFileStatus().getModificationTime());
uniqueString.append(getFileStatus().getLen());
uniqueString.append(getFileStatus().getPath());
return Guid.fromStrings(uniqueString.toString());
}
代码示例来源: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: org.apache.gobblin/gobblin-data-management
/**
* Set a unique, replicable guid for this work unit. Used for recovering partially successful work units.
* @param state {@link State} where guid should be written.
* @param guid A byte array guid.
*/
public static void setWorkUnitGuid(State state, Guid guid) {
state.setProp(WORK_UNIT_GUID, guid.toString());
}
代码示例来源:origin: org.apache.gobblin/gobblin-utility
/**
* Creates a new {@link Guid} which is a unique, replicable representation of the pair (this, guids). Equivalent to
* combine(this, guid1, guid2, ...)
* @param guids an array of {@link Guid}.
* @return a new {@link Guid}.
* @throws IOException
*/
public Guid append(Guid... guids) throws IOException {
if (guids == null || guids.length == 0) {
return this;
}
return combine(ArrayUtils.add(guids, this));
}
代码示例来源:origin: apache/incubator-gobblin
CopyConfiguration.builder(fs, state.getProperties()).preserve(PreserveAttributes.fromMnemonicString("")).build()).build();
CopySource.setWorkUnitGuid(state, Guid.fromHasGuid(copyableFile));
代码示例来源:origin: apache/incubator-gobblin
/**
* Creates a new {@link Guid} which is a unique, replicable representation of the pair (this, byteArrays).
* @param byteArrays an array of byte arrays.
* @return a new {@link Guid}.
* @throws IOException
*/
public Guid append(byte[]... byteArrays) throws IOException {
if (byteArrays == null || byteArrays.length == 0) {
return this;
}
return fromByteArrays(ArrayUtils.add(byteArrays, this.sha));
}
代码示例来源:origin: org.apache.gobblin/gobblin-data-management
/**
* Get guid in this state if available. This is the reverse operation of {@link #setWorkUnitGuid}.
* @param state State from which guid should be extracted.
* @return A byte array guid.
* @throws IOException
*/
public static Optional<Guid> getWorkUnitGuid(State state)
throws IOException {
if (state.contains(WORK_UNIT_GUID)) {
return Optional.of(Guid.deserialize(state.getProp(WORK_UNIT_GUID)));
}
return Optional.absent();
}
内容来源于网络,如有侵权,请联系作者删除!