public static <T> T deserializeFromFile(String fileName) throws Throwable { InputStream inputStream = FileUtils.getInputStream(fileName); return deserialize(inputStream); }
public static void serializeToFile(Serializable object, String fileName) throws IOException { OutputStream outputStream = FileUtils.getOutputStream(fileName); serialize(object, outputStream); }
@Override public String getInstance() { try { String prefix = jamonProperties.getProperty("jamonDataPersister.label.prefix"); String label = jamonProperties.getProperty("jamonDataPersister.label"); if ("".equals(label)) { label = jamonDataPersister.getInstance(); } return FileUtils.makeValidFileName(prefix+label); } catch (Throwable t) { MonitorFactory.addException(t); } return null; }
/** Get instances by looking in directory for any saved files and also add local in memory instance */ @Override public Set<String> getInstances() { Set<String> keys = new TreeSet<String>(); keys.addAll(super.getInstances()); File[] files = FileUtils.listFiles(getDirectoryName(), FILE_EXT); if(files == null || files.length == 0) { return keys; } keys.addAll(removeFileExtenstion(files)); return keys; }
@Override public MonitorComposite get(String instanceKey) { try { MonitorComposite monitorComposite = super.get(instanceKey); if (monitorComposite!=null) { return monitorComposite; } String fileName = getFileName(instanceKey); if (FileUtils.exists(fileName)) { monitorComposite = SerializationUtils.deserializeFromFile(fileName); return monitorComposite; } else { return null; } } catch (Throwable e) { throw new RuntimeException("Exception while trying to load jamondata", e); } }