@Override public byte[] serialize(Object obj) { try { return JSONValue.toJSONString(obj).getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
@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 byte[] toCompressedJsonConf(Map<String, Object> topoConf) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputStreamWriter out = new OutputStreamWriter(new GZIPOutputStream(bos)); JSONValue.writeJSONString(topoConf, out); out.close(); return bos.toByteArray(); } catch (IOException 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 static boolean isValidConf(Map<String, Object> stormConf) { return normalizeConf(stormConf).equals(normalizeConf((Map) JSONValue.parse(JSONValue.toJSONString(stormConf)))); }
public void childEvent(CuratorFramework framework, PathChildrenCacheEvent event) throws Exception { List<ChildData> childDataList = pathChildrenCache.getCurrentData(); if(event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED || event.getType() == PathChildrenCacheEvent.Type.CHILD_UPDATED) { if (childDataList != null && childDataList.size() > 0) { // update and reload single rule by businessScope in future List<Map<Object, Object>> zkDataList = new ArrayList<Map<Object, Object>>(); for (ChildData childData : childDataList) { LOG.info("==" + childData.getPath() + " changed," + new String(childData.getData(), "UTF-8")); String data = new String(childData.getData(), "UTF-8"); if(!StringUtils.isEmpty(data)) { System.out.println("==" + childData.getPath() + " changed," + new String(childData.getData(), "UTF-8")); Map<Object, Object> zkData = (Map<Object, Object>) JSONValue.parse(data); if(!zkData.containsKey("type")) { String childPath = childData.getPath(); zkData.put("type", childPath.substring(childPath.lastIndexOf("/") + 1)); } zkDataList.add(zkData); } } if(zkDataList.size() > 0) refresh(zkDataList); } } } }, pool);
String result = JSONValue.toJSONString(state.results); Map<String, Object> retMap; try { retMap = (Map<String, Object>) JSONValue.parseWithException(state.returnInfo); } catch (ParseException e) { collector.reportError(e);
public void childEvent(CuratorFramework framework, PathChildrenCacheEvent event) throws Exception { List<ChildData> childDataList = pathChildrenCache.getCurrentData(); if(event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED || event.getType() == PathChildrenCacheEvent.Type.CHILD_UPDATED) { if (childDataList != null && childDataList.size() > 0) { // update and reload single rule by businessScope in future List<Map<Object, Object>> zkDataList = new ArrayList<Map<Object, Object>>(); for (ChildData childData : childDataList) { LOG.info("==" + childData.getPath() + " changed," + new String(childData.getData(), "UTF-8")); String data = new String(childData.getData(), "UTF-8"); if(!StringUtils.isEmpty(data)) { System.out.println("==" + childData.getPath() + " changed," + new String(childData.getData(), "UTF-8")); Map<Object, Object> zkData = (Map<Object, Object>) JSONValue.parse(data); zkDataList.add(zkData); } } if(zkDataList.size() > 0) refresh(zkDataList); } } } }, pool);
private static String mergeIntoJson(Map<String, Object> into, Map<String, Object> newMap) { Map<String, Object> res = new HashMap<>(into); res.putAll(newMap); return JSONValue.toJSONString(res); }
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); } } }
String result = JSONValue.toJSONString(state.results); Map retMap = null; try { retMap = (Map) JSONValue.parseWithException(state.returnInfo); } catch (ParseException e) { collector.reportError(e);
public static byte[] toCompressedJsonConf(Map<String, Object> stormConf) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputStreamWriter out = new OutputStreamWriter(new GZIPOutputStream(bos)); JSONValue.writeJSONString(stormConf, out); out.close(); return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public String toJSONString() { Map<String, Object> obj = new HashMap<>(); obj.put("task->component", _taskToComponent); // TODO: jsonify StormTopology // at the minimum should send source info return JSONValue.toJSONString(obj); }
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); } }
@Override public byte[] serialize(OpaqueValue obj) { List toSer = new ArrayList(3); toSer.add(obj.currTxid); toSer.add(obj.curr); toSer.add(obj.prev); try { return JSONValue.toJSONString(toSer).getBytes("UTF-8"); } catch (UnsupportedEncodingException 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); } } }
private void writeMessage(Object msg) throws IOException { writeString(JSONValue.toJSONString(msg)); }
private Object readMessage() throws IOException, NoOutputException { try { return JSONValue.parseWithException(readString()); } catch (ParseException e) { throw new IOException(e); } }
@Override public byte[] serialize(TransactionalValue obj) { List toSer = new ArrayList(2); toSer.add(obj.getTxid()); toSer.add(obj.getVal()); try { return JSONValue.toJSONString(toSer).getBytes("UTF-8"); } catch (UnsupportedEncodingException 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); } }