/** * Creates a new instance of XML Encoder pre-configured for Violet beans serailization * * @param out * @return configured encoder */ private XMLEncoder getXMLEncoder(OutputStream out) { XMLEncoder encoder = new XMLEncoder(out); encoder.setExceptionListener( new ExceptionListener() { public void exceptionThrown(Exception ex) { ex.printStackTrace(); } }); configure(encoder); return encoder; }
public static boolean saveData(Object data, String filePath) { boolean result = false; try { if (log.isTraceEnabled()) log.trace("saveData(): data=" + data + ", filePath=" + filePath); filePath = StringUtil.checkFullPathLength(filePath); FileLockManager.startFileWrite(filePath); if (filePath != null) { File file = new File(filePath); if (!file.isDirectory()) { FileOutputStream os = new FileOutputStream(filePath); XMLEncoder encoder = new XMLEncoder(os); encoder.setExceptionListener( new ExceptionListener() { public void exceptionThrown(Exception exception) { log.error("readData(): error", exception); } }); encoder.writeObject(data); encoder.close(); result = true; } else { log.warn( "saveData(): attempted to save over directory, filePath=" + filePath + ", data=" + data); } } } catch (Error e) { log.error("saveData(): error", e); } catch (Exception e) { log.error("saveData(): xception", e); } finally { FileLockManager.endFileWrite(filePath); } if (log.isTraceEnabled()) log.trace("saveData(): done saving..."); return result; }