Write the contents of a JSONSerializable object out to a file on the local disk @param @param object @param output_path @throws IOException
(T object, String output_path)
| 157 | * @throws IOException |
| 158 | */ |
| 159 | public static <T extends JSONSerializable> void save(T object, String output_path) |
| 160 | throws IOException { |
| 161 | if (LOG.isDebugEnabled()) { |
| 162 | LOG.debug( |
| 163 | "Writing out contents of {} to '{}'", object.getClass().getSimpleName(), output_path); |
| 164 | } |
| 165 | File f = new File(output_path); |
| 166 | try { |
| 167 | FileUtil.makeDirIfNotExists(f.getParent()); |
| 168 | String json = object.toJSONString(); |
| 169 | FileUtil.writeStringToFile(f, format(json)); |
| 170 | } catch (Exception ex) { |
| 171 | LOG.error("Failed to serialize the {} file '{}'", object.getClass().getSimpleName(), f, ex); |
| 172 | throw new IOException(ex); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Load in a JSONSerialable stored in a file |
no test coverage detected