Search in sources :

Example 1 with Serializer

use of org.simpleframework.xml.Serializer in project syncany by syncany.

the class TransferSettingsTest method testDeserializeCorrectClass.

@Test
public void testDeserializeCorrectClass() throws Exception {
    Serializer serializer = new Persister();
    InitOperationOptions initOperationOptions = TestConfigUtil.createTestInitOperationOptions("syncanytest");
    // Always LocalTransferSettings
    serializer.write(initOperationOptions.getConfigTO(), tmpFile);
    ConfigTO confRestored = ConfigTO.load(tmpFile);
    assertEquals(LocalTransferSettings.class, confRestored.getTransferSettings().getClass());
    // Tear down
    FileUtils.deleteDirectory(initOperationOptions.getLocalDir());
    FileUtils.deleteDirectory(((LocalTransferSettings) initOperationOptions.getConfigTO().getTransferSettings()).getPath());
}
Also used : InitOperationOptions(org.syncany.operations.init.InitOperationOptions) Persister(org.simpleframework.xml.core.Persister) ConfigTO(org.syncany.config.to.ConfigTO) Serializer(org.simpleframework.xml.Serializer) Test(org.junit.Test)

Example 2 with Serializer

use of org.simpleframework.xml.Serializer in project syncany by syncany.

the class TransactionTO method save.

public void save(Transformer transformer, File transactionFile) throws Exception {
    PrintWriter out;
    if (transformer == null) {
        out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(transactionFile), "UTF-8"));
    } else {
        out = new PrintWriter(new OutputStreamWriter(transformer.createOutputStream(new FileOutputStream(transactionFile)), "UTF-8"));
    }
    Serializer serializer = new Persister();
    serializer.write(this, out);
    out.flush();
    out.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Persister(org.simpleframework.xml.core.Persister) PrintWriter(java.io.PrintWriter) Serializer(org.simpleframework.xml.Serializer)

Example 3 with Serializer

use of org.simpleframework.xml.Serializer in project syncany by syncany.

the class RepoTO method save.

public void save(File file, List<CipherSpec> cipherSpecs, SaltedSecretKey masterKey) throws ConfigException {
    try {
        ByteArrayOutputStream plaintextRepoOutputStream = new ByteArrayOutputStream();
        Serializer serializer = new Persister();
        serializer.write(this, plaintextRepoOutputStream);
        CipherUtil.encrypt(new ByteArrayInputStream(plaintextRepoOutputStream.toByteArray()), new FileOutputStream(file), cipherSpecs, masterKey);
    } catch (Exception e) {
        throw new ConfigException("Cannot write repoTO (encrypted) to file " + file, e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) ConfigException(org.syncany.config.ConfigException) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Persister(org.simpleframework.xml.core.Persister) ConfigException(org.syncany.config.ConfigException) Serializer(org.simpleframework.xml.Serializer)

Example 4 with Serializer

use of org.simpleframework.xml.Serializer in project syncany by syncany.

the class TestCliUtil method fixMachineName.

private static void fixMachineName(Map<String, String> client) throws Exception {
    File configFile = new File(client.get("localdir") + "/" + Config.DIR_APPLICATION + "/" + Config.FILE_CONFIG);
    Serializer serializer = new Persister();
    ConfigTO configTO = serializer.read(ConfigTO.class, configFile);
    configTO.setMachineName(client.get("machinename"));
    serializer.write(configTO, configFile);
}
Also used : Persister(org.simpleframework.xml.core.Persister) ConfigTO(org.syncany.config.to.ConfigTO) File(java.io.File) Serializer(org.simpleframework.xml.Serializer)

Example 5 with Serializer

use of org.simpleframework.xml.Serializer in project syncany by syncany.

the class ConnectOperation method verifyRepoFile.

private void verifyRepoFile(String repoFileStr) throws StorageException {
    try {
        Serializer serializer = new Persister();
        serializer.read(RepoTO.class, repoFileStr);
    } catch (Exception e) {
        throw new StorageException("Repo file corrupt.", e);
    }
}
Also used : Persister(org.simpleframework.xml.core.Persister) StorageException(org.syncany.plugins.transfer.StorageException) StorageException(org.syncany.plugins.transfer.StorageException) CipherException(org.syncany.crypto.CipherException) Serializer(org.simpleframework.xml.Serializer)

Aggregations

Serializer (org.simpleframework.xml.Serializer)7 Persister (org.simpleframework.xml.core.Persister)7 Test (org.junit.Test)3 ConfigTO (org.syncany.config.to.ConfigTO)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 InitOperationOptions (org.syncany.operations.init.InitOperationOptions)2 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 ConfigException (org.syncany.config.ConfigException)1 CipherException (org.syncany.crypto.CipherException)1 DummyTransferManager (org.syncany.plugins.dummy.DummyTransferManager)1 DummyTransferPlugin (org.syncany.plugins.dummy.DummyTransferPlugin)1 DummyTransferSettings (org.syncany.plugins.dummy.DummyTransferSettings)1 StorageException (org.syncany.plugins.transfer.StorageException)1 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)1 TransferSettings (org.syncany.plugins.transfer.TransferSettings)1