use of com.baidu.hugegraph.exception.ToolsException in project incubator-hugegraph-toolchain by apache.
the class AuthBackupRestoreManager method readRestoreData.
private List<String> readRestoreData(HugeType type) {
List<String> resultList = Lists.newArrayList();
InputStream is = this.inputStream(type.string());
try (InputStreamReader isr = new InputStreamReader(is, API.CHARSET);
BufferedReader reader = new BufferedReader(isr)) {
String line;
while ((line = reader.readLine()) != null) {
resultList.add(line);
}
} catch (IOException e) {
throw new ToolsException("Failed to deserialize %s from %s", e, type.string(), resultList);
}
return resultList;
}
use of com.baidu.hugegraph.exception.ToolsException in project incubator-hugegraph-toolchain by apache.
the class AuthBackupRestoreManager method writeBackupData.
private long writeBackupData(HugeType type, List<?> list) {
long count = 0L;
try {
OutputStream os = this.outputStream(type.string(), false);
ByteArrayOutputStream baos = new ByteArrayOutputStream(LBUF_SIZE);
StringBuilder builder = new StringBuilder(LBUF_SIZE);
for (Object e : list) {
count++;
builder.append(JsonUtil.toJson(e)).append("\n");
}
baos.write(builder.toString().getBytes(API.CHARSET));
os.write(baos.toByteArray());
} catch (Throwable e) {
throw new ToolsException("Failed to serialize %s to %s", e, list, type.string());
}
return count;
}
use of com.baidu.hugegraph.exception.ToolsException in project incubator-hugegraph-toolchain by apache.
the class BackupRestoreBaseManager method write.
protected long write(String path, HugeType type, List<?> list, boolean compress) {
OutputStream os = this.outputStream(path, compress);
ByteArrayOutputStream baos = new ByteArrayOutputStream(LBUF_SIZE);
try {
String key = String.format("{\"%s\": ", type.string());
baos.write(key.getBytes(API.CHARSET));
this.client.mapper().writeValue(baos, list);
baos.write("}\n".getBytes(API.CHARSET));
os.write(baos.toByteArray());
} catch (Throwable e) {
throw new ToolsException("Failed to serialize %s to %s", e, type, path);
}
return list.size();
}
use of com.baidu.hugegraph.exception.ToolsException in project incubator-hugegraph-toolchain by apache.
the class FileUtil method writeTestRestoreData.
public static long writeTestRestoreData(String filePath, List<?> list) {
long count = 0L;
try (FileOutputStream os = new FileOutputStream(filePath);
ByteArrayOutputStream baos = new ByteArrayOutputStream(LBUF_SIZE)) {
StringBuilder builder = new StringBuilder(LBUF_SIZE);
for (Object e : list) {
count++;
builder.append(e).append("\n");
}
baos.write(builder.toString().getBytes(API.CHARSET));
os.write(baos.toByteArray());
} catch (IOException e) {
throw new ToolsException("Failed write file path is %s", e, filePath);
}
return count;
}
use of com.baidu.hugegraph.exception.ToolsException in project incubator-hugegraph-toolchain by apache.
the class BackupManager method readShards.
private List<Shard> readShards(File file) {
E.checkArgument(file.exists() && file.isFile() && file.canRead(), "Need to specify a readable filter file rather than:" + " %s", file.toString());
List<Shard> shards = new ArrayList<>();
try (InputStream is = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(is, API.CHARSET);
BufferedReader reader = new BufferedReader(isr)) {
String line;
while ((line = reader.readLine()) != null) {
shards.addAll(this.readList("shards", Shard.class, line));
}
} catch (IOException e) {
throw new ToolsException("IOException occur while reading %s", e, file.getName());
}
return shards;
}
Aggregations