Search in sources :

Example 11 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class PluginOperation method getRemotePluginInfo.

private PluginInfo getRemotePluginInfo(String pluginId) throws Exception {
    String remoteListStr = getRemoteListStr(pluginId);
    PluginListResponse pluginListResponse = new Persister().read(PluginListResponse.class, remoteListStr);
    if (pluginListResponse.getPlugins().size() > 0) {
        return pluginListResponse.getPlugins().get(0);
    } else {
        return null;
    }
}
Also used : Persister(org.simpleframework.xml.core.Persister)

Example 12 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class ConfigTO method save.

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);
    }
}
Also used : SaltedSecretKeyConverter(org.syncany.crypto.SaltedSecretKeyConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) ConfigException(org.syncany.config.ConfigException) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) EncryptedTransferSettingsConverter(org.syncany.plugins.transfer.EncryptedTransferSettingsConverter) ConfigException(org.syncany.config.ConfigException)

Example 13 with Persister

use of org.simpleframework.xml.core.Persister 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 14 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class ConfigHelper method loadEncryptedRepoTO.

private static RepoTO loadEncryptedRepoTO(File repoFile, ConfigTO configTO) throws Exception {
    logger.log(Level.INFO, "Loading encrypted repo file from {0} ...", repoFile);
    SaltedSecretKey masterKey = configTO.getMasterKey();
    if (masterKey == null) {
        throw new ConfigException("Repo file is encrypted, but master key not set in config file.");
    }
    String repoFileStr = new String(CipherUtil.decrypt(new FileInputStream(repoFile), masterKey));
    return new Persister().read(RepoTO.class, repoFileStr);
}
Also used : SaltedSecretKey(org.syncany.crypto.SaltedSecretKey) Persister(org.simpleframework.xml.core.Persister) FileInputStream(java.io.FileInputStream)

Example 15 with Persister

use of org.simpleframework.xml.core.Persister 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)

Aggregations

Persister (org.simpleframework.xml.core.Persister)30 File (java.io.File)11 Test (org.junit.Test)11 StorageException (org.syncany.plugins.transfer.StorageException)8 Serializer (org.simpleframework.xml.Serializer)7 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)6 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)5 TransactionTO (org.syncany.plugins.transfer.to.TransactionTO)5 IOException (java.io.IOException)4 ConfigException (org.syncany.config.ConfigException)4 ConfigTO (org.syncany.config.to.ConfigTO)4 TestClient (org.syncany.tests.util.TestClient)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)3 Subscribe (com.google.common.eventbus.Subscribe)2 User (com.lonepulse.robozombie.model.User)2 FileOutputStream (java.io.FileOutputStream)2 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)2 BuildException (org.apache.tools.ant.BuildException)2