Package cloudsync.exceptions

Examples of cloudsync.exceptions.CloudsyncException


      allowedKeyLength = Cipher.getMaxAllowedKeyLength("AES");
    } catch (final NoSuchAlgorithmException e) {
      // e.printStackTrace();
    }
    if (allowedKeyLength < Integer.MAX_VALUE) {
      throw new CloudsyncException("Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are not installed");
    }

    Security.addProvider(new BouncyCastleProvider());
  }
View Full Code Here


     
      final PGPLiteralData ld = (PGPLiteralData) pgpFact.nextObject();

      return Streams.readAll(ld.getInputStream());
    } catch (Exception e) {
      throw new CloudsyncException("can't encrypt data", e);
    } finally {

      try {
        if (in != null) {
          in.close();
        }
      } catch (IOException e) {
        throw new CloudsyncException("can't decrypt data", e);
      }
    }
  }
View Full Code Here

      encOut.write(compressedData);
      encOut.close();

      return bOut.toByteArray();
    } catch (Exception e) {
      throw new CloudsyncException("can't encrypt data", e);
    } finally {

      if (armor) {
        try {
          out.close();
        } catch (IOException e) {
          throw new CloudsyncException("can't encrypt data", e);
        }
      }
    }
  }
View Full Code Here

    remoteConnector = prop.getProperty("REMOTE_CONNECTOR");

    passphrase = prop.getProperty("PASSPHRASE");
    if (StringUtils.isEmpty(passphrase)) {
      throw new CloudsyncException("'PASSPHRASE' is not configured");
    }
    String value = getOptionValue(cmd, "followlinks", LinkType.EXTERNAL.getName());
    followlinks = LinkType.fromName(value);
    value = getOptionValue(cmd, "duplicate", SyncType.CLEAN.equals(type) ? DuplicateType.RENAME.getName() : DuplicateType.STOP.getName());
    duplicate = DuplicateType.fromName(value);
View Full Code Here

      final Path parentPath = Paths.get(localPath + Item.SEPARATOR + parentItem.getPath());

      try {
        Files.createDirectories(parentPath);
      } catch (IOException e) {
        throw new CloudsyncException("Can't create " + parentItem.getTypeName() + " '" + parentItem.getPath() + "'", e);
      }
    }
  }
View Full Code Here

    final Path path = Paths.get(_path);

    if (exists(path)) {

      if (!duplicateFlag.equals(DuplicateType.UPDATE)) {
        throw new CloudsyncException("Item '" + item.getPath() + "' already exists. Try to specify another '--duplicate' behavior.");
      }

      if ((!item.isType(ItemType.FOLDER) || !isDir(path))) {

        try {
          Files.delete(path);
        } catch (final IOException e) {
          throw new CloudsyncException("Can't clear " + item.getTypeName() + " on '" + item.getPath() + "'", e);
        }
      }
    }

    if (item.isType(ItemType.FOLDER)) {

      if (!exists(path)) {

        try {
          Files.createDirectory(path);
        } catch (final IOException e) {
          throw new CloudsyncException("Can't create " + item.getTypeName() + " '" + item.getPath() + "'", e);
        }
      }
    } else {

      if (item.getParent() != null) {

        final Path parentPath = Paths.get(localPath + Item.SEPARATOR + item.getParent().getPath());

        if (!isDir(parentPath)) {

          throw new CloudsyncException("Parent directory of " + item.getTypeName() + " '" + item.getPath() + "' is missing.");
        }
      }

      if (item.isType(ItemType.LINK)) {

        try {

          final byte[] data = handler.getRemoteDecryptedBinary(item);
          // if (!createChecksum(data).equals(item.getChecksum())) {
          // throw new
          // CloudsyncException("restored filechecksum differs from the original filechecksum");
          // }
          final String link = new String(data);
          Files.createSymbolicLink(path, Paths.get(link));

        } catch (final IOException e) {

          throw new CloudsyncException("Unexpected error during local update of " + item.getTypeName() + " '" + item.getPath() + "'", e);
        }
      } else if (item.isType(ItemType.FILE)) {

        try {
          final byte[] data = handler.getRemoteDecryptedBinary(item);
          if (!createChecksum(data).equals(item.getChecksum())) {
            throw new CloudsyncException("restored filechecksum differs from the original filechecksum");
          }
          if (item.getFilesize() != data.length) {
            throw new CloudsyncException("restored filesize differs from the original filesize");
          }
          final FileOutputStream fos = new FileOutputStream(path.toFile());
          try {
            fos.write(data);
          } finally {
            fos.close();
          }
        } catch (final IOException e) {

          throw new CloudsyncException("Unexpected error during local update of " + item.getTypeName() + " '" + item.getPath() + "'", e);
        }
      } else {
        throw new CloudsyncException("Unsupported type " + item.getTypeName() + "' on '" + item.getPath() + "'");
      }
    }

    try {
      if (item.isType(ItemType.LINK)) {
        // Files.setLastModifiedTime(path, item.getModifyTime());
      } else {
        Files.getFileAttributeView(path, BasicFileAttributeView.class, LinkOption.NOFOLLOW_LINKS).setTimes(item.getModifyTime(), item.getAccessTime(), item.getCreationTime());
      }
    } catch (final IOException e) {
      throw new CloudsyncException("Can't set create, modify and access time of " + item.getTypeName() + " '" + item.getPath() + "'", e);
    }

    if (permissionType.equals(PermissionType.SET) || permissionType.equals(PermissionType.TRY)) {

      final UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();

      Map<String, String[]> attributes = item.getAttributes();
      for (String type : attributes.keySet()) {

        GroupPrincipal group;
        UserPrincipal principal;

        try {
          String[] values = attributes.get(type);

          switch (type) {
          case Item.ATTRIBUTE_POSIX:
            PosixFileAttributeView posixView = Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
            if (posixView != null) {
              group = lookupService.lookupPrincipalByGroupName(values[0]);
              posixView.setGroup(group);
              principal = lookupService.lookupPrincipalByName(values[1]);
              posixView.setOwner(principal);
              if (values.length > 2)
                posixView.setPermissions(toPermissions(Integer.parseInt(values[2])));
            } else {
              String msg = "Can't restore 'posix' permissions on '" + item.getPath() + "'. They are not supported.";
              if (permissionType.equals(PermissionType.TRY))
                LOGGER.log(Level.WARNING, msg);
              else
                throw new CloudsyncException(msg + "\n  try to run with '--permissions try'");
            }
            break;
          case Item.ATTRIBUTE_DOS:
            DosFileAttributeView dosView = Files.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
            if (dosView != null) {
              dosView.setArchive(Boolean.parseBoolean(values[0]));
              dosView.setHidden(Boolean.parseBoolean(values[1]));
              dosView.setReadOnly(Boolean.parseBoolean(values[2]));
              dosView.setSystem(Boolean.parseBoolean(values[3]));
            } else {
              String msg = "Can't restore 'dos' permissions on '" + item.getPath() + "'. They are not supported.";
              if (permissionType.equals(PermissionType.TRY))
                LOGGER.log(Level.WARNING, msg);
              else
                throw new CloudsyncException(msg + "\n  try to run with '--permissions try'");
            }
            break;
          case Item.ATTRIBUTE_ACL:
            AclFileAttributeView aclView = Files.getFileAttributeView(path, AclFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
            if (aclView != null) {
              List<AclEntry> acls = aclView.getAcl();
              for (int i = 0; i < values.length; i = i + 4) {

                Builder aclEntryBuilder = AclEntry.newBuilder();

                aclEntryBuilder.setType(AclEntryType.valueOf(values[i]));
                aclEntryBuilder.setPrincipal(lookupService.lookupPrincipalByName(values[i + 1]));

                Set<AclEntryFlag> flags = new HashSet<AclEntryFlag>();
                for (String flag : StringUtils.splitPreserveAllTokens(values[i + 2], ",")) {
                  flags.add(AclEntryFlag.valueOf(flag));
                }
                if (flags.size() > 0)
                  aclEntryBuilder.setFlags(flags);

                Set<AclEntryPermission> aclPermissions = new HashSet<AclEntryPermission>();
                for (String flag : StringUtils.splitPreserveAllTokens(values[i + 3], ",")) {
                  aclPermissions.add(AclEntryPermission.valueOf(flag));
                }
                if (aclPermissions.size() > 0)
                  aclEntryBuilder.setPermissions(aclPermissions);
                acls.add(aclEntryBuilder.build());
              }
              aclView.setAcl(acls);
            } else {
              String msg = "Can't restore 'acl' permissions on '" + item.getPath() + "'. They are not supported.";
              if (permissionType.equals(PermissionType.TRY))
                LOGGER.log(Level.WARNING, msg);
              else
                throw new CloudsyncException(msg + "\n  try to run with '--permissions try'");
            }
            break;
          case Item.ATTRIBUTE_OWNER:
            FileOwnerAttributeView ownerView = Files.getFileAttributeView(path, FileOwnerAttributeView.class, LinkOption.NOFOLLOW_LINKS);
            if (ownerView != null) {
              principal = lookupService.lookupPrincipalByName(values[0]);
              ownerView.setOwner(principal);
            } else {
              String msg = "Can't restore 'owner' permissions on '" + item.getPath() + "'. They are not supported.";
              if (permissionType.equals(PermissionType.TRY))
                LOGGER.log(Level.WARNING, msg);
              else
                throw new CloudsyncException(msg + "\n  try to run with '--permissions try'");
            }
            break;
          }
        } catch (final UserPrincipalNotFoundException e) {
          if (!LocalFilesystemConnector.principal_state.containsKey(e.getName())) {
            LocalFilesystemConnector.principal_state.put(e.getName(), true);
            LOGGER.log(Level.WARNING, "principal with name '" + e.getName() + "' not exists");
          }
          String msg = "Principal '" + e.getName() + "' on '" + item.getPath() + "' not found.";
          if (permissionType.equals(PermissionType.TRY))
            LOGGER.log(Level.WARNING, msg);
          else
            throw new CloudsyncException(msg + "\n  try to run with '--permissions try'");
        } catch (final IOException e) {
          String msg = "Can't set permissions of '" + item.getPath() + "'.";
          if (permissionType.equals(PermissionType.TRY))
            LOGGER.log(Level.WARNING, msg);
          else
            throw new CloudsyncException(msg + "\n  try to run with '--permissions try'");
        }
      }
    }
  }
View Full Code Here

      throw e;

    } catch (final IOException e) {

      throw new CloudsyncException("Can't read attributes of '" + file.getAbsolutePath() + "'", e);
    }
  }
View Full Code Here

        return data;
      }
      return null;
    } catch (final IOException e) {

      throw new CloudsyncException("Can't read data of '" + file.getAbsolutePath() + "'", e);
    }
  }
View Full Code Here

        }
        fh = new LogfileHandler(logpath);
        fh.setFormatter(new LogfileFormatter());
        logger.addHandler(fh);
      } catch (SecurityException e) {
        throw new CloudsyncException("Unexpected error on logfile creation", e);
      } catch (IOException e) {
        throw new CloudsyncException("Unexpected error on logfile creation", e);
      }
    }

    String name = options.getName();

    final LocalFilesystemConnector localConnection = new LocalFilesystemConnector(options.getPath());

    Handler handler = null;

    try {

      String remoteConnectorName = options.getRemoteConnector();
      RemoteConnector remoteConnector = null;
      try {
        remoteConnector = (RemoteConnector) Class.forName("cloudsync.connector.Remote" + remoteConnectorName + "Connector").newInstance();
      } catch (IllegalAccessException e) {
      } catch (InstantiationException e) {
      } catch (ClassNotFoundException e) {
        throw new CloudsyncException("Remote connector '" + remoteConnectorName + "' not found", e);
      }

      remoteConnector.init(name, options);

      final long start = System.currentTimeMillis();
View Full Code Here

      }

      credential.setFromTokenResponse(clientToken);

    } catch (final IOException e) {
      throw new CloudsyncException("Can't init remote google drive connector", e);
    }
  }
View Full Code Here

TOP

Related Classes of cloudsync.exceptions.CloudsyncException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.