public static synchronized void write(ReferenceLibrary data, Path dataPath) throws JsonProcessingException { CommonUtil.writeFile(dataPath, BatfishObjectMapper.writePrettyString(data)); } }
@Override public String toString() { try { return BatfishObjectMapper.writePrettyString(this); } catch (JsonProcessingException e) { throw new BatfishException("Cannot serialize to Json", e); } } }
public static boolean checkJsonEqual(Object a, Object b) { try { String aString = BatfishObjectMapper.writePrettyString(a); String bString = BatfishObjectMapper.writePrettyString(b); JSONAssert.assertEquals(aString, bString, false); return true; } catch (Exception e) { throw new BatfishException("JSON equality check failed", e); } catch (AssertionError err) { return false; } }
private String writeObject(T t) { try { String structureJson = BatfishObjectMapper.writePrettyString(t); return structureJson; } catch (JsonProcessingException e) { throw new BatfishException("Could not write named structure as JSON", e); } } }
public String prettyPrint() { try { return BatfishObjectMapper.writePrettyString(this); } catch (JsonProcessingException e) { throw new BatfishException("Failed to pretty-print question", e); } }
public String prettyPrint() { try { return BatfishObjectMapper.writePrettyString(this); } catch (JsonProcessingException e) { throw new BatfishException("Failed to pretty print answer element", e); } }
@Override public String toString() { try { return BatfishObjectMapper.writePrettyString(this); } catch (JsonProcessingException e) { throw new BatfishException("Cannot serialize to Json", e); } } }
@Override public void storeSnapshotMetadata( SnapshotMetadata snapshotMetadata, NetworkId networkId, SnapshotId snapshotId) throws IOException { FileUtils.writeStringToFile( getSnapshotMetadataPath(networkId, snapshotId).toFile(), BatfishObjectMapper.writePrettyString(snapshotMetadata), UTF_8); }
@Override public String toString() { try { return BatfishObjectMapper.writePrettyString(this); } catch (JsonProcessingException e) { throw new BatfishException("Cannot serialize to Json", e); } } }
@Override public String toString() { try { return BatfishObjectMapper.writePrettyString(this); } catch (JsonProcessingException e) { throw new BatfishException("Cannot serialize to Json", e); } } }
@Override public void storeAnalysisMetadata( AnalysisMetadata analysisMetadata, NetworkId networkId, AnalysisId analysisId) throws IOException { FileUtils.writeStringToFile( getAnalysisMetadataPath(networkId, analysisId).toFile(), BatfishObjectMapper.writePrettyString(analysisMetadata), UTF_8); }
@Override public void storeTopology(Topology topology, NetworkId networkId, SnapshotId snapshotId) throws IOException { Path path = getEnvTopologyPath(networkId, snapshotId); path.getParent().toFile().mkdirs(); FileUtils.writeStringToFile( path.toFile(), BatfishObjectMapper.writePrettyString(topology), UTF_8); }
@Override public String toJsonString() { try { return BatfishObjectMapper.writePrettyString(this); } catch (JsonProcessingException e) { throw new BatfishException("Failed to convert question to JSON string", e); } } }
@Override public void storeNodeRoles(NodeRolesData nodeRolesData, NodeRolesId nodeRolesId) throws IOException { FileUtils.write( getNodeRolesPath(nodeRolesId).toFile(), BatfishObjectMapper.writePrettyString(nodeRolesData), UTF_8); }
@Override public void storePojoTopology( org.batfish.datamodel.pojo.Topology topology, NetworkId networkId, SnapshotId snapshotId) throws IOException { Path path = getPojoTopologyPath(networkId, snapshotId); path.getParent().toFile().mkdirs(); FileUtils.writeStringToFile( path.toFile(), BatfishObjectMapper.writePrettyString(topology), UTF_8); }
@VisibleForTesting /* Helper method to add the specified collection to the serialized list at the specified path. */ static <T> void addToSerializedList( Path serializedObjectPath, @Nullable Collection<T> addition, TypeReference<List<T>> type) throws IOException { if (addition == null || addition.isEmpty()) { return; } List<T> baseList; if (serializedObjectPath.toFile().exists()) { baseList = BatfishObjectMapper.mapper().readValue(CommonUtil.readFile(serializedObjectPath), type); baseList.addAll(addition); } else { baseList = ImmutableList.copyOf(addition); } CommonUtil.writeFile(serializedObjectPath, BatfishObjectMapper.writePrettyString(baseList)); }
@GET @Path(BfConsts.SVC_KILL_TASK_RSC) @Produces(MediaType.APPLICATION_JSON) public JSONArray killTask(@QueryParam(BfConsts.SVC_TASKID_KEY) String taskId) { _logger.infof("BFS:killTask %s\n", taskId); try { if (Strings.isNullOrEmpty(taskId)) { return new JSONArray(Arrays.asList(BfConsts.SVC_FAILURE_KEY, "taskid not supplied")); } Task task = Driver.killTask(taskId); String taskStr = BatfishObjectMapper.writePrettyString(task); return new JSONArray(Arrays.asList(BfConsts.SVC_SUCCESS_KEY, taskStr)); } catch (Exception e) { return new JSONArray(Arrays.asList(BfConsts.SVC_FAILURE_KEY, e.getMessage())); } }
@Override public void storeAnswerMetadata(AnswerMetadata answerMetadata, AnswerId answerId) { String metricsStr; try { metricsStr = BatfishObjectMapper.writePrettyString(answerMetadata); } catch (JsonProcessingException e) { throw new BatfishException("Could not write answer metrics", e); } Path answerMetadataPath = getAnswerMetadataPath(answerId); mkdirs(answerMetadataPath.getParent()); CommonUtil.writeFile(answerMetadataPath, metricsStr); }
@Test public void serializationCheck() throws IOException { String serialized = BatfishObjectMapper.writePrettyString(FAILURE_SPECIFIER); assertThat( BatfishObjectMapper.mapper().readValue(serialized, DispositionSpecifier.class), equalTo(FAILURE_SPECIFIER)); }
@Test public void testSerialization() throws IOException { String serialized = BatfishObjectMapper.writePrettyString(RoutingProtocolSpecifier.ALL_PROTOCOLS_SPECIFIER); assertThat( BatfishObjectMapper.mapper().readValue(serialized, RoutingProtocolSpecifier.class), equalTo(RoutingProtocolSpecifier.ALL_PROTOCOLS_SPECIFIER)); }