@Override public Object deserialize(byte[] b) { try { return JSONValue.parseWithException(new String(b, "UTF-8")); } catch (UnsupportedEncodingException | ParseException e) { throw new RuntimeException(e); } }
public static Map<String, Object> parseJson(String json) { if (json == null) { return new HashMap<>(); } else { try { return (Map<String, Object>) JSONValue.parseWithException(json); } catch (ParseException e) { throw new RuntimeException(e); } } }
public static Map<String, Object> fromCompressedJsonConf(byte[] serialized) { try { ByteArrayInputStream bis = new ByteArrayInputStream(serialized); InputStreamReader in = new InputStreamReader(new GZIPInputStream(bis)); Object ret = JSONValue.parseWithException(in); in.close(); return (Map<String, Object>) ret; } catch (IOException | ParseException e) { throw new RuntimeException(e); } }
public Map<String, File> parseArtifactsProperties(String prop) { try { Map<String, String> parsed = (Map<String, String>) JSONValue.parseWithException(prop); Map<String, File> packages = new LinkedHashMap<>(parsed.size()); for (Map.Entry<String, String> artifactToFilePath : parsed.entrySet()) { packages.put(artifactToFilePath.getKey(), new File(artifactToFilePath.getValue())); } return packages; } catch (ParseException e) { throw new RuntimeException(e); } } }
@Override public TransactionalValue deserialize(byte[] b) { try { String s = new String(b, "UTF-8"); List deser = (List) JSONValue.parseWithException(s); return new TransactionalValue((Long) deser.get(0), deser.get(1)); } catch (UnsupportedEncodingException | ParseException e) { throw new RuntimeException(e); } }
private Object readMessage() throws IOException, NoOutputException { try { return JSONValue.parseWithException(readString()); } catch (ParseException e) { throw new IOException(e); } }
@Override public OpaqueValue deserialize(byte[] b) { try { String s = new String(b, "UTF-8"); List deser = (List) JSONValue.parseWithException(s); return new OpaqueValue((Long) deser.get(0), deser.get(1), deser.get(2)); } catch (UnsupportedEncodingException | ParseException e) { throw new RuntimeException(e); } }
public static Map<String, Object> readCommandLineOpts() { Map<String, Object> ret = new HashMap<>(); String commandOptions = System.getProperty("storm.options"); if (commandOptions != null) { /* Below regex uses negative lookahead to not split in the middle of json objects '{}' or json arrays '[]'. This is needed to parse valid json object/arrays passed as options via 'storm.cmd' in windows. This is not an issue while using 'storm.py' since it url-encodes the options and the below regex just does a split on the commas that separates each option. Note:- This regex handles only valid json strings and could produce invalid results if the options contain un-encoded invalid json or strings with unmatched '[, ], { or }'. We can replace below code with split(",") once 'storm.cmd' is fixed to send url-encoded options. */ String[] configs = commandOptions.split(",(?![^\\[\\]{}]*(]|}))"); for (String config : configs) { config = URLDecoder.decode(config); String[] options = config.split("=", 2); if (options.length == 2) { Object val = options[1]; try { val = JSONValue.parseWithException(options[1]); } catch (ParseException ignored) { //fall back to string, which is already set } ret.put(options[0], val); } } } return ret; }
@SuppressWarnings("unchecked") public static Map<String, Object> componentConf(Object component) { try { Map<String, Object> conf = new HashMap<>(); ComponentCommon common = getComponentCommon(component); String jconf = common.get_json_conf(); if (jconf != null) { conf.putAll((Map<String, Object>) JSONValue.parseWithException(jconf)); } return conf; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void execute(TridentTuple input, TridentCollector collector) { try { String args = input.getString(0); List<List<Object>> tuples = (List) JSONValue.parseWithException(args); for (List<Object> tuple : tuples) { collector.emit(tuple); } } catch (ParseException e) { throw new RuntimeException(e); } } }
if (specJsonConf != null) { try { componentConf = (Map<String, Object>) JSONValue.parseWithException(specJsonConf); } catch (ParseException e) { throw new RuntimeException(e);
@SuppressWarnings("unchecked") public static boolean isValidConf(Map<String, Object> topoConfIn) { Map<String, Object> origTopoConf = normalizeConf(topoConfIn); try { Map<String, Object> deserTopoConf = normalizeConf( (Map<String, Object>) JSONValue.parseWithException(JSONValue.toJSONString(topoConfIn))); return isValidConf(origTopoConf, deserTopoConf); } catch (ParseException e) { LOG.error("Json serialized config could not be deserialized", e); } return false; }
public Object getData(String path) { path = "/" + path; try { Object data; if (_curator.checkExists().forPath(path) != null) { // Use parseWithException instead of parse so we can capture deserialization errors in the log. // They are likely to be bugs in the spout code. try { data = JSONValue.parseWithException(new String(_curator.getData().forPath(path), "UTF-8")); } catch (ParseException e) { LOG.warn("Failed to deserialize zookeeper data for path {}", path, e); data = null; } } else { data = null; } LOG.debug("Get. [path = {}] => [data = {}]", path, data); return data; } catch (Exception e) { throw new RuntimeException(e); } }
public int maxTopologyMessageTimeout() { Integer max = ObjectReader.getInt(_topoConf.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS)); for (String spout : getRawTopology().get_spouts().keySet()) { ComponentCommon common = getComponentCommon(spout); String jsonConf = common.get_json_conf(); if (jsonConf != null) { try { Map<String, Object> conf = (Map) JSONValue.parseWithException(jsonConf); Object comp = conf.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS); max = Math.max(ObjectReader.getInt(comp, max), max); } catch (ParseException e) { throw new RuntimeException(e); } } } return max; }
Map<String, Object> retMap; try { retMap = (Map<String, Object>) JSONValue.parseWithException(state.returnInfo); } catch (ParseException e) { collector.reportError(e);
Map<String, Object> retMap; try { retMap = (Map<String, Object>) JSONValue.parseWithException(returnInfo); } catch (ParseException e) { LOG.error("Parseing returnInfo failed", e);
private static Map parseJson(String json) { if (json==null) { return new HashMap(); } else { try { return (Map) JSONValue.parseWithException(json); } catch (ParseException e) { throw new RuntimeException(e); } } }
public static Map<String, Object> fromCompressedJsonConf(byte[] serialized) { try { ByteArrayInputStream bis = new ByteArrayInputStream(serialized); InputStreamReader in = new InputStreamReader(new GZIPInputStream(bis)); Object ret = JSONValue.parseWithException(in); in.close(); return (Map<String,Object>)ret; } catch (IOException | ParseException e) { throw new RuntimeException(e); } }
private Object readMessage() throws IOException, NoOutputException { try { return JSONValue.parseWithException(readString()); } catch (ParseException e) { throw new IOException(e); } }
@Override public void execute(TridentTuple input, TridentCollector collector) { try { String args = input.getString(0); List<List<Object>> tuples = (List) JSONValue.parseWithException(args); for (List<Object> tuple: tuples) { collector.emit(tuple); } } catch (ParseException e) { throw new RuntimeException(e); } } }