use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class MappingUtil method write.
public static void write(LoadMapping mapping, String path) {
File file = FileUtils.getFile(path);
String json = JsonUtil.toJson(mapping);
try {
FileUtils.write(file, json, Constants.CHARSET);
} catch (IOException e) {
throw new LoadException("Failed to write mapping %s to file '%s'", e, mapping, file);
}
}
use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class GraphStructV1 method of.
public static GraphStructV1 of(LoadContext context) {
LoadOptions options = context.options();
File file = FileUtils.getFile(options.file);
try {
String json = FileUtils.readFileToString(file, Constants.CHARSET);
GraphStructV1 struct = JsonUtil.fromJson(json, GraphStructV1.class);
struct.check();
return struct;
} catch (IOException | IllegalArgumentException e) {
throw new LoadException("Failed to parse graph mapping description file '%s'", e, options.file);
}
}
use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class FileLineFetcher method createCompressReader.
private static Reader createCompressReader(InputStream stream, FileSource source) throws Exception {
Compression compression = source.compression();
String charset = source.charset();
switch(compression) {
case NONE:
return new InputStreamReader(stream, charset);
case SNAPPY_RAW:
Configuration config = new Configuration();
CompressionCodec codec = ReflectionUtils.newInstance(SnappyCodec.class, config);
CompressionInputStream sis = codec.createInputStream(stream, codec.createDecompressor());
return new InputStreamReader(sis, charset);
case GZIP:
case BZ2:
case XZ:
case LZMA:
case SNAPPY_FRAMED:
case Z:
case DEFLATE:
case LZ4_BLOCK:
case LZ4_FRAMED:
CompressorStreamFactory factory = new CompressorStreamFactory();
CompressorInputStream cis = factory.createCompressorInputStream(compression.string(), stream);
return new InputStreamReader(cis, charset);
default:
throw new LoadException("Unsupported compression format '%s'", compression);
}
}
use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class FileLineFetcher method openReader.
@Override
public void openReader(Readable readable) {
InputStream stream = null;
try {
stream = readable.open();
this.reader = createBufferedReader(stream, this.source());
} catch (IOException e) {
throw new LoadException("Failed to open stream for '%s'", e, readable);
} catch (Exception e) {
if (stream != null) {
try {
stream.close();
} catch (IOException ignored) {
LOG.warn("Failed to close stream of '{}'", readable);
}
}
throw new LoadException("Failed to create reader for '%s'", e, readable);
}
// Mark as fresh
this.resetStatus();
}
use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class JDBCUtil method escapePostgresql.
public static String escapePostgresql(String value) {
StringBuilder builder = new StringBuilder(8 + value.length());
builder.append('\'');
try {
Utils.escapeLiteral(builder, value, false);
} catch (SQLException e) {
throw new LoadException("Failed to escape '%s'", e, value);
}
builder.append('\'');
return builder.toString();
}
Aggregations