@Override protected void logout() throws BackgroundException { try { client.disconnect(); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
@Override public BackgroundException map(final IOException failure) { final Throwable[] stack = ExceptionUtils.getThrowables(failure); for(Throwable t : stack) { if(t instanceof BackgroundException) { return (BackgroundException) t; } } if(failure instanceof SSLException) { return new SSLExceptionMappingService().map((SSLException) failure); } final StringBuilder buffer = new StringBuilder(); this.append(buffer, failure.getMessage()); for(Throwable cause : ExceptionUtils.getThrowableList(failure)) { if(!StringUtils.contains(failure.getMessage(), cause.getMessage())) { this.append(buffer, cause.getMessage()); } } return this.wrap(failure, buffer); } }
@Override public BackgroundException map(final IOException failure) { if(failure instanceof ConnectionClosedException) { final StringBuilder buffer = new StringBuilder(); this.append(buffer, failure.getMessage()); return new ConnectionRefusedException(buffer.toString(), failure); } return super.map(failure); } }
@Override public BackgroundException map(final IOException failure) { final StringBuilder buffer = new StringBuilder(); if(failure instanceof GoogleJsonResponseException) { final GoogleJsonResponseException error = (GoogleJsonResponseException) failure; this.append(buffer, error.getDetails().getMessage()); switch(error.getDetails().getCode()) { case HttpStatus.SC_FORBIDDEN: final List<GoogleJsonError.ErrorInfo> errors = error.getDetails().getErrors(); for(GoogleJsonError.ErrorInfo info : errors) { if("usageLimits".equals(info.getDomain())) { return new RetriableAccessDeniedException(buffer.toString(), Duration.ofSeconds(5), failure); } } break; } } if(failure instanceof HttpResponseException) { final HttpResponseException response = (HttpResponseException) failure; this.append(buffer, response.getStatusMessage()); return new HttpResponseExceptionMappingService().map(new org.apache.http.client .HttpResponseException(response.getStatusCode(), buffer.toString())); } return super.map(failure); } }
@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); } }
@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 public void close(final OutputStream out) throws BackgroundException { if(null == out) { return; } try { out.flush(); out.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.getExecutor().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; } }
public static InputStream skip(final InputStream in, final long offset) throws BackgroundException { try { long skipped = in.skip(offset); if(log.isInfoEnabled()) { log.info(String.format("Skipping %d bytes", skipped)); } if(skipped < offset) { throw new IOResumeException(String.format("Skipped %d bytes instead of %d", skipped, offset)); } return in; } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } }
@Override protected void logout() throws BackgroundException { try { ((DropboxCommonsHttpRequestExecutor) client.getRequestConfig().getHttpRequestor()).close(); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
@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); }
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); } } }
/** * Cancel large file upload with id */ public void delete(final String id) throws BackgroundException { if(log.isInfoEnabled()) { log.info(String.format("Delete multipart upload for fileid %s", id)); } try { session.getClient().cancelLargeFileUpload(id); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } }
throw new DefaultIOExceptionMappingService().map(e);
@Override public void delete(final List<Path> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException { for(Path file : files) { callback.delete(file); try { final OneDriveItem item = session.toItem(file); item.delete(); } catch(NotfoundException e) { logger.warn(String.format("Cannot delete %s. Not found.", file)); } catch(OneDriveAPIException e) { throw new GraphExceptionMappingService().map("Cannot delete {0}", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot delete {0}", e, file); } } }
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 login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { final OAuthTokens tokens = authorizationService.authorize(host, prompt, cancel); try { if(log.isInfoEnabled()) { log.info(String.format("Attempt authentication with %s", tokens)); } client.authenticate(new HubicAuthenticationRequest(tokens.getAccessToken()), new HubicAuthenticationResponseHandler()); } catch(GenericException e) { throw new SwiftExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
@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); } } }