private byte[] getPlaintextStorageXml() throws Exception { ByteArrayOutputStream plaintextByteArrayOutputStream = new ByteArrayOutputStream(); DataOutputStream plaintextOutputStream = new DataOutputStream(plaintextByteArrayOutputStream); plaintextOutputStream.writeInt(transferSettings.getType().getBytes().length); plaintextOutputStream.write(transferSettings.getType().getBytes()); GZIPOutputStream plaintextGzipOutputStream = new GZIPOutputStream(plaintextOutputStream); new Persister(new Format(0)).write(transferSettings, plaintextGzipOutputStream); plaintextGzipOutputStream.close(); return plaintextByteArrayOutputStream.toByteArray(); } }
public void save(File file) throws ConfigException { try { new Persister().write(this, file); } catch (Exception e) { throw new ConfigException("Cannot write masterTO to file " + file, e); } }
public void save(File file) throws ConfigException { try { new Persister().write(this, file); } catch (Exception e) { throw new ConfigException("Config could not be written: " + file, e); } }
public void save(File file) throws ConfigException { try { new Persister().write(this, file); } catch (Exception e) { throw new ConfigException("Cannot write repoTO to file " + file, e); } }
@Override public void run() { try { logger.log(Level.INFO, "STARTING watch at" + config.getLocalDir()); watchOperationResult = null; // Write port to portFile File portFile = config.getPortFile(); portFile.createNewFile(); portFile.deleteOnExit(); new Persister().write(portTO, portFile); // Start operation (blocks!) watchOperationResult = watchOperation.execute(); logger.log(Level.INFO, "STOPPED watch at " + config.getLocalDir()); } catch (Exception e) { logger.log(Level.SEVERE, "ERROR while running watch at " + config.getLocalDir(), e); } } }, "WR/" + config.getLocalDir().getName());
public void save(File file) throws ConfigException { try { new Persister(new AnnotationStrategy()).write(this, file); } catch (Exception e) { throw new ConfigException("Cannot write user config to file " + file, e); } } }
public void save(File file) throws ConfigException { try { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter()); registry.bind(String.class, new EncryptedTransferSettingsConverter(transferSettings.getClass())); new Persister(strategy).write(this, file); } catch (Exception e) { throw new ConfigException("Cannot write config to file " + file, e); } }
public static Config createTestLocalConfig(String machineName, TransferSettings connection) throws Exception { File tempLocalDir = TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("client-" + machineName, connection)); tempLocalDir.mkdirs(); RepoTO repoTO = createRepoTO(); // Create config TO ConfigTO configTO = new ConfigTO(); configTO.setMachineName(machineName + CipherUtil.createRandomAlphabeticString(20)); // Get Masterkey SaltedSecretKey masterKey = getMasterKey(); configTO.setMasterKey(masterKey); LocalTransferSettings localConnection = (LocalTransferSettings) connection; // Create connection TO Map<String, String> localConnectionSettings = new HashMap<String, String>(); localConnectionSettings.put("path", localConnection.getPath().getAbsolutePath()); configTO.setTransferSettings(connection); // Create Config config = new Config(tempLocalDir, configTO, repoTO); config.setConnection(connection); config.getAppDir().mkdirs(); config.getCacheDir().mkdirs(); config.getDatabaseDir().mkdirs(); config.getLogDir().mkdirs(); config.getStateDir().mkdirs(); // Write to config folder (required for some tests) new Persister().write(configTO, new File(config.getAppDir() + "/" + Config.FILE_CONFIG)); new Persister().write(repoTO, new File(config.getAppDir() + "/" + Config.FILE_REPO)); return config; }
/** * This <code>write</code> method will traverse the provided object * checking for field annotations in order to compose the XML data. * This uses the <code>getClass</code> method on the object to * determine the class file that will be used to compose the schema. * If there is no <code>Root</code> annotation for the class then * this will throw an exception. The root annotation is the only * annotation required for an object to be serialized. * * @param source this is the object that is to be serialized * @param out this is where the serialized XML is written to * @param charset this is the character encoding to be used * * @throws Exception if the schema for the object is not valid */ public void write(Object source, OutputStream out, String charset) throws Exception { write(source, new OutputStreamWriter(out, charset)); }
public void write(Object payload, OutputStream stream, String charset) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(stream, charset); try { persister.write(payload, writer); } catch (Exception x) { if (x instanceof RuntimeException) { throw (RuntimeException) x; } else if (x instanceof IOException) { throw (IOException) x; } else { throw new IllegalArgumentException("Marshalling failed", x); } } }
/** * Serializes this collection of {@link AttributeValueSet}s to an XML stream. * * @param stream the stream to serialize this {@link AttributeValueSets} to. The stream * will <strong>not</strong> be closed. * @throws Exception in case of any problems with serialization */ public void serialize(OutputStream stream) throws Exception { new Persister().write(this, stream); }
@Override public String toString() { final Persister persister = new DFPersister(); try (StringWriter writer = new StringWriter()) { persister.write(this, writer); return writer.toString(); } catch (final Exception e) { throw new IllegalStateException(e.getMessage(), e); } } }
/** * Serializes this statistics object as XML stream. */ public void serialize(OutputStream stream) throws Exception { new Persister().write(this, stream); } }
/** * Serializes this component suite as an UTF-8 encoded XML. */ public void serialize(OutputStream stream) throws Exception { new Persister().write(this, stream); }
/** * Serializes this {@link ProcessingResult} to an XML string. */ public String serialize() { try { StringWriter sw = new StringWriter(); new Persister().write(this, sw); return sw.toString(); } catch (Exception e) { throw new RuntimeException(e); } }
private void dump(List<Report> report, File configDir, boolean debug) throws Exception { Persister persister = new Persister(); int count = report.size(); for(int i = 0; i < count; i++) { Report entry = report.get(i); if(entry.isError() || debug) { String output = String.format("report-%s.xml", i); File file = new File(configDir, output); persister.write(entry, file); } else if(debug){ System.out.printf("PASS: %s of %s - %s%n", i, count, entry.getStatusLine()); } } }
public void write(Object source, Writer writer, Map context) { try { createPersister(context).write(source, writer); } catch (XmlPersisterException exception) { throw exception; } catch (Exception exception) { throw new XmlPersisterException(exception); } }
@Override public byte[] objectTobytes(final Object obj) throws SerializeException { LOG.debug("Serialize object to xml on Simple"); try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); Persister serializer = new Persister(format); serializer.write(obj, byteArrayOutputStream, "UTF-8"); return byteArrayOutputStream.toByteArray(); } catch (Exception e) { throw new SerializeException(e); } }
public void write(Object source, OutputStream output, Map context) { try { createPersister(context).write(source, output); } catch (XmlPersisterException exception) { throw exception; } catch (Exception exception) { throw new XmlPersisterException(exception); } }
/** * Write the summary file, if requested. */ @Subscribe public void onQuit(AggregatedQuitEvent e) { if (summaryFile != null) { try { Persister persister = new Persister(); persister.write(new MavenFailsafeSummaryModel(summaryListener.getResult()), summaryFile); } catch (Exception x) { junit4.log("Could not serialize summary report.", x, Project.MSG_WARN); } } }