use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class SerializeUtil method fromBytes.
public static <V extends Readable> List<V> fromBytes(byte[] bytes, Supplier<V> supplier) {
try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
int size = bai.readInt();
List<V> list = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
V obj = supplier.get();
obj.read(bai);
list.add(obj);
}
return list;
} catch (IOException e) {
throw new ComputerException("Failed to read from byte array", e);
}
}
use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class HgkvFileImpl method readFooter.
private void readFooter() throws IOException {
File file = new File(this.path);
// The footerLength occupied 4 bytes, versionLength 2 * 2 bytes
long versionOffset = file.length() - Short.BYTES * 2 - Integer.BYTES;
try (RandomAccessInput input = IOFactory.createFileInput(file)) {
input.seek(versionOffset);
// Read version
short majorVersion = input.readShort();
short minorVersion = input.readShort();
String version = version(majorVersion, minorVersion);
// Read footerLength
int footerLength = input.readFixedInt();
switch(version) {
case "1.0":
this.readFooterV1d0(input, file.length() - footerLength);
break;
default:
throw new ComputerException("Illegal HgkvFile version '%s'", version);
}
}
}
use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class EntriesUtil method subKvEntryFromInput.
public static KvEntry subKvEntryFromInput(RandomAccessInput input, RandomAccessInput userAccessInput, boolean useInlinePointer) {
try {
Pointer key, value;
if (useInlinePointer) {
byte[] keyBytes = input.readBytes(input.readFixedInt());
key = new InlinePointer(keyBytes);
byte[] valueBytes = input.readBytes(input.readFixedInt());
value = new InlinePointer(valueBytes);
} else {
int keyLength = input.readFixedInt();
key = new CachedPointer(userAccessInput, input.position(), keyLength);
input.skip(keyLength);
int valueLength = input.readFixedInt();
value = new CachedPointer(userAccessInput, input.position(), valueLength);
input.skip(valueLength);
}
return new DefaultKvEntry(key, value);
} catch (IOException e) {
throw new ComputerException(e.getMessage(), e);
}
}
use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class MockWorkerInputManager method loadEdgeInputSplitData.
public int loadEdgeInputSplitData() {
if (this.edgeInputSplit == null) {
throw new ComputerException("Should fetch edge input split meta " + "before load");
}
if (this.edgeInputSplit.equals(InputSplit.END_SPLIT)) {
throw new ComputerException("Can't load edge input split data, " + "because it has been exhausted");
}
EdgeFetcher edgeFetcher = this.fetcher.edgeFetcher();
edgeFetcher.prepareLoadInputSplit(this.edgeInputSplit);
int count = 0;
while (edgeFetcher.hasNext()) {
Edge edge = edgeFetcher.next();
// Write edge to buffer
Assert.assertNotNull(edge);
count++;
}
return count;
}
use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class MockWorkerInputManager method loadVertexInputSplitData.
public int loadVertexInputSplitData() {
if (this.vertexInputSplit == null) {
throw new ComputerException("Should fetch vertex input split " + "meta before load");
}
if (this.vertexInputSplit.equals(InputSplit.END_SPLIT)) {
throw new ComputerException("Can't load vertex input split data, " + "because it has been exhausted");
}
VertexFetcher vertexFetcher = this.fetcher.vertexFetcher();
vertexFetcher.prepareLoadInputSplit(this.vertexInputSplit);
int count = 0;
while (vertexFetcher.hasNext()) {
Vertex vertex = vertexFetcher.next();
// Write vertex to buffer
Assert.assertNotNull(vertex);
count++;
}
return count;
}
Aggregations