private static HugeException incompatibleActionException( Action newAction, Action originAction) { return new HugeException("The action '%s' is incompatible with " + "action '%s'", newAction, originAction); }
@Override protected TextBackendEntry convertEntry(BackendEntry backendEntry) { if (!(backendEntry instanceof TextBackendEntry)) { throw new HugeException("The entry '%s' is not TextBackendEntry", backendEntry); } return (TextBackendEntry) backendEntry; }
public static String decode(byte[] bytes) { try { return new String(bytes, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new HugeException("Failed to decode string", e); } }
private static PropertiesConfiguration getRemoteConfig(URL url) { try { return new PropertiesConfiguration(url); } catch (ConfigurationException e) { throw new HugeException("Unable to load remote config file: %s", e, url); } } }
@Override protected HugeVertex clone() { try { return (HugeVertex) super.clone(); } catch (CloneNotSupportedException e) { throw new HugeException("Failed to clone HugeVertex", e); } }
public static byte[] encode(String value) { try { return value.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new HugeException("Failed to encode string", e); } }
@Override protected HugeEdge clone() { try { return (HugeEdge) super.clone(); } catch (CloneNotSupportedException e) { throw new HugeException("Failed to clone HugeEdge", e); } }
public static Object valueOf(Class<? extends Object> clazz, String number) { try { Method valueOf = clazz.getMethod("valueOf", String.class); return valueOf.invoke(null, number); } catch (NoSuchMethodException | SecurityException e) { throw new HugeException("Invalid number class: %s", e, clazz); } catch (Exception e) { throw new HugeException("Invalid value '%s' for number class: %s", e, number, clazz); } } }
private <V> V call(Callable<V> callable) { // Ensure all db operations are executed in dbExecutor thread(s) try { return this.dbExecutor.submit(callable).get(); } catch (Exception e) { throw new HugeException("Failed to update/query TaskStore", e); } }
@SuppressWarnings("unchecked") public static <V> TaskCallable<V> fromClass(String className) { try { Class<?> clazz = Class.forName(className); return (TaskCallable<V>) clazz.newInstance(); } catch (Exception e) { throw new HugeException("Failed to load task: %s", e, className); } }
private static Analyzer customizedAnalyzer(String name, String mode) { Class<? extends Analyzer> clazz = analyzers.get(name); if (clazz == null) { throw new HugeException("Not exists analyzer: %s", name); } assert Analyzer.class.isAssignableFrom(clazz); try { return clazz.getConstructor(String.class).newInstance(mode); } catch (Exception e) { throw new HugeException( "Failed to construct analyzer '%s' with mode '%s'", e, name, mode); } }
public static <T> T copy(T object, T clone) { try { return cloneObject(object, clone); } catch (Exception e) { throw new HugeException("Failed to clone object", e); } }
private static PropertiesConfiguration getLocalConfig(String path) { File file = new File(path); E.checkArgument(file.exists() && file.isFile() && file.canRead(), "Please specify a proper config file rather than: %s", file.toString()); try { return new PropertiesConfiguration(file); } catch (ConfigurationException e) { throw new HugeException("Unable to load config file: %s", e, path); } }
private String writeList(String label, List<?> list) { try (ByteArrayOutputStream out = new ByteArrayOutputStream(LBUF_SIZE)) { out.write(String.format("{\"%s\": ", label).getBytes(API.CHARSET)); this.writer.writeObject(out, list); out.write("}".getBytes(API.CHARSET)); return out.toString(API.CHARSET); } catch (Exception e) { throw new HugeException("Failed to serialize %s", e, label); } }
private void verifyOpened() { if (!this.isOpen()) { throw new HugeException("Transaction has not been opened"); } }
private String writeObject(Object object) { try (ByteArrayOutputStream out = new ByteArrayOutputStream(BUF_SIZE)) { this.writer.writeObject(out, object); return out.toString(API.CHARSET); } catch (Exception e) { throw new HugeException("Failed to serialize %s", e, object.getClass().getSimpleName()); } }
protected static <T> List<T> readList(String content, String key, Class<T> clazz) { try { JsonNode root = mapper.readTree(content); JsonNode element = root.get(key); if (element == null) { throw new HugeException(String.format( "Can't find value of the key: %s in json.", key)); } JavaType type = mapper.getTypeFactory() .constructParametricType(List.class, clazz); return mapper.readValue(element.toString(), type); } catch (IOException e) { throw new HugeException(String.format( "Failed to deserialize %s", content), e); } }
public static void main(String[] args) throws Exception { if (args.length != 1) { String msg = "HugeRestServer can only accept one config files"; LOG.error(msg); throw new HugeException(msg); } try { // Start HugeRestServer start(args[0]); } catch (Exception e) { LOG.error("HugeRestServer error:", e); throw e; } LOG.info("HugeRestServer stopped"); }
private static PropertiesConfiguration getConf() { String confFile = TestGraphProvider.class.getClassLoader() .getResource(CONF_PATH).getPath(); File file = new File(confFile); E.checkArgument( file.exists() && file.isFile() && file.canRead(), "Need to specify a readable config file rather than: %s", file.toString()); PropertiesConfiguration config; try { config = new PropertiesConfiguration(file); } catch (ConfigurationException e) { throw new HugeException("Unable to load config file: %s", e, confFile); } return config; }
public static void main(String[] args) throws Exception { if (args.length != 1) { LOG.error("RestServer need one config file, but given {}", Arrays.asList(args)); throw new HugeException("RestServer need one config file"); } try { RestServer.start(args[0]); Thread.currentThread().join(); } catch (Exception e) { LOG.error("RestServer error:", e); throw e; } LOG.info("RestServer stopped"); } }