@Override public void close(final InputStream in) throws BackgroundException { if(null == in) { return; } try { in.close(); } catch(IOException e) { if(e.getCause() instanceof BackgroundException) { throw (BackgroundException) e.getCause(); } throw new DefaultIOExceptionMappingService().map(e); } }
@Override protected void logout() throws BackgroundException { try { client.disconnect(); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
@Override protected void logout() throws BackgroundException { try { transport.shutdown(); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
@Override public void logout() throws BackgroundException { try { client.close(); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
private KeyFormat detectKeyFormat(final Local identity) throws BackgroundException { final KeyFormat format; try (InputStream is = identity.getInputStream()) { format = KeyProviderUtil.detectKeyFileFormat( new InputStreamReader(is, StandardCharsets.UTF_8), true); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } return format; } }
@Override public BackgroundException map(final IOException e) { final StringBuilder buffer = new StringBuilder(); this.append(buffer, e.getMessage()); if(e instanceof FTPConnectionClosedException) { return new ConnectionRefusedException(buffer.toString(), e); } if(e instanceof FTPException) { return this.handle((FTPException) e, buffer); } if(e instanceof MalformedServerReplyException) { return new InteroperabilityException(buffer.toString(), e); } return new DefaultIOExceptionMappingService().map(e); }
@Override protected void logout() throws BackgroundException { try { client.getExecutor().close(); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
public String read(final Path file) throws BackgroundException { final Read read = session._getFeature(Read.class); final InputStream in = read.read(file, new TransferStatus(), new DisabledConnectionCallback()); try { return IOUtils.toString(in, "UTF-8"); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } finally { IOUtils.closeQuietly(in); } } }
@Override protected void logout() throws BackgroundException { try { ((DropboxCommonsHttpRequestExecutor) client.getRequestConfig().getHttpRequestor()).close(); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
public void setFileKey(final TransferStatus status) throws BackgroundException { final FileKey fileKey = TripleCryptConverter.toSwaggerFileKey(Crypto.generateFileKey()); final ObjectWriter writer = session.getClient().getJSON().getContext(null).writerFor(FileKey.class); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { writer.writeValue(out, fileKey); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } status.setFilekey(ByteBuffer.wrap(out.toByteArray())); status.setEncryption(new Encryption.Algorithm("AES256", null)); }
@Override public void unlock(final Path file, final String token) throws BackgroundException { try { session.getClient().unlock(new DAVPathEncoder().encode(file), token); } catch(SardineException e) { throw new DAVExceptionMappingService().map("Failure to write attributes of {0}", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e, file); } } }
@Override public String lock(final Path file) throws BackgroundException { try { return session.getClient().lock(new DAVPathEncoder().encode(file)); } catch(SardineException e) { throw new DAVExceptionMappingService().map("Failure to write attributes of {0}", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e, file); } }
private String computeFingerprint(final FileKeyProvider provider) throws BackgroundException { try { return new SSHFingerprintGenerator().fingerprint(provider.getPublic()); } catch(PasswordException e) { throw new LoginCanceledException(e); } catch(EncryptionException e) { final StringAppender appender = new StringAppender(); appender.append(StringUtils.capitalize(e.getMessage())); throw new LoginFailureException(appender.toString(), e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
@Override protected Long operate(final PasswordCallback callback, final Path container) throws BackgroundException { try { return session.getClient().getContainerInfo(regionService.lookup(container), container.getName()).getTotalSize(); } catch(GenericException e) { throw new SwiftExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } }
@Override public void revert(final Path file) throws BackgroundException { final Ds3Client client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); final Path container = containerService.getContainer(file); try { client.undeleteObjectSpectraS3(new UndeleteObjectSpectraS3Request(container.getName(), containerService.getKey(file))); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot revert file", e, file); } }
@Override public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { try { final String accountId = host.getCredentials().getUsername(); final String applicationKey = host.getCredentials().getPassword(); // Save tokens for 401 error response when expired retryHandler.setTokens(accountId, applicationKey, client.authenticate(accountId, applicationKey).getAuthorizationToken()); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
@Override public void setPermission(final Path file, final Acl acl) throws BackgroundException { if(containerService.isContainer(file)) { try { BucketType bucketType = this.convert(acl); session.getClient().updateBucket(fileid.getFileid(containerService.getContainer(file), new DisabledListProgressListener()), bucketType); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Cannot change permissions of {0}", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } }
@Override public Path mkdir(final Path directory, final String region, final TransferStatus status) throws BackgroundException { final OneDriveFolder folder = session.toFolder(directory.getParent()); try { final OneDriveFolder.Metadata metadata = folder.create(directory.getName()); return new Path(directory.getParent(), directory.getName(), directory.getType(), new GraphAttributesFinderFeature(session).toAttributes(metadata)); } catch(OneDriveAPIException e) { throw new GraphExceptionMappingService().map("Cannot create folder {0}", e, directory); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot create folder {0}", e, directory); } }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { try { if(nodeid.isEncrypted(file)) { nodeid.setFileKey(status); } final StatusOutputStream<VersionId> out = writer.write(file, status, new DisabledConnectionCallback()); out.close(); return new Path(file.getParent(), file.getName(), file.getType(), new PathAttributes(file.attributes()).withVersionId(out.getStatus().id)); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot create file {0}", e, file); } }
@Override public BackgroundException map(final OneDriveAPIException failure) { if(failure.getResponseCode() > 0) { final StringAppender buffer = new StringAppender(); buffer.append(failure.getMessage()); buffer.append(failure.getErrorMessage()); return new HttpResponseExceptionMappingService().map(new HttpResponseException(failure.getResponseCode(), buffer.toString())); } if(ExceptionUtils.getRootCause(failure) instanceof IOException) { return new DefaultIOExceptionMappingService().map((IOException) ExceptionUtils.getRootCause(failure)); } return new InteroperabilityException(failure.getMessage(), failure); } }