Example usage for java.nio.file AccessDeniedException AccessDeniedException

List of usage examples for java.nio.file AccessDeniedException AccessDeniedException

Introduction

In this page you can find the example usage for java.nio.file AccessDeniedException AccessDeniedException.

Prototype

public AccessDeniedException(String file, String other, String reason) 

Source Link

Document

Constructs an instance of this class.

Usage

From source file:de.tiqsolutions.hdfs.HadoopFileSystemProvider.java

static void rethrowRemoteException(RemoteException e, Path p1, Path p2) throws IOException {
    switch (e.getClassName()) {
    case "org.apache.hadoop.fs.PathIsNotEmptyDirectoryException":
        throw new DirectoryNotEmptyException(p1.toString());

    case "org.apache.hadoop.fs.PathExistsException":
    case "org.apache.hadoop.fs.FileAlreadyExistsException":
        throw new FileAlreadyExistsException(Objects.toString(p1), Objects.toString(p2),
                e.getLocalizedMessage());

    case "org.apache.hadoop.fs.PathPermissionException":
    case "org.apache.hadoop.fs.PathAccessDeniedException":
        throw new AccessDeniedException(Objects.toString(p1), Objects.toString(p2), e.getLocalizedMessage());

    case "org.apache.hadoop.fs.ParentNotDirectoryException":
    case "org.apache.hadoop.fs.DirectoryListingStartAfterNotFoundException":
    case "org.apache.hadoop.fs.PathIsNotDirectoryException":
        throw new NotDirectoryException(Objects.toString(p1));

    case "org.apache.hadoop.fs.PathIsDirectoryException":
    case "org.apache.hadoop.fs.InvalidPathException":
    case "org.apache.hadoop.fs.PathNotFoundException":
        throw new NoSuchFileException(Objects.toString(p1), Objects.toString(p2), e.getLocalizedMessage());

    case "org.apache.hadoop.fs.UnresolvedLinkException":
        throw new NotLinkException(Objects.toString(p1), Objects.toString(p2), e.getLocalizedMessage());

    case "org.apache.hadoop.fs.PathIOException":
    case "org.apache.hadoop.fs.ChecksumException":
    case "org.apache.hadoop.fs.InvalidRequestException":
    case "org.apache.hadoop.fs.UnsupportedFileSystemException":
    case "org.apache.hadoop.fs.ZeroCopyUnavailableException":

    }/*from  w ww  . j  av  a 2  s.c  o m*/

    throw new IOException(e.getLocalizedMessage(), e);
}

From source file:at.beris.virtualfile.client.sftp.SftpClient.java

private void handleJSchException(JSchException e, String path) throws IOException {
    if (e.getMessage().equals("Auth fail"))
        throw new AccessDeniedException(path, null, e.getMessage());
    else/*from  w  w w .  j  a v a2 s.c o  m*/
        throw new IOException(e);
}

From source file:org.modelio.vbasic.net.ApacheUriConnection.java

/**
 * Builds and throws a {@link FileSystemException} from {@link #res}.
 * <p>/* w ww  . j a  v  a 2  s .  c o  m*/
 * Adds as cause another exception whose message is the entity content. This may be the HTML message sent by the server.
 * @throws java.nio.file.FileSystemException the built exception
 */
@objid("4e25ec1d-3711-45cc-b742-0c77edf5e414")
private void handleConnectionFailure() throws FileSystemException {
    StatusLine statusLine = this.res.getStatusLine();
    String reason = statusLine.getReasonPhrase();

    Exception base = null;
    try {
        String s = EntityUtils.toString(this.res.getEntity());
        if (s != null)
            base = new HttpResponseException(statusLine.getStatusCode(), s);
    } catch (IOException e) {
        base = e;
    }

    FileSystemException error;

    int statusCode = statusLine.getStatusCode();
    if (statusCode == HttpStatus.SC_FORBIDDEN) {
        error = new AccessDeniedException(this.uri.toString(), null, reason);
    } else if (statusCode == HttpStatus.SC_UNAUTHORIZED
            || statusCode == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) {
        error = new UriAuthenticationException(this.uri.toString(), reason);
    } else if (statusCode == HttpStatus.SC_NOT_FOUND) {
        error = new NoSuchFileException(this.uri.toString(), null, reason);
    } else {
        error = new FileSystemException(this.uri.toString(), null, reason);
    }

    if (base != null)
        error.initCause(base);

    throw error;
}

From source file:org.apache.hadoop.fs.s3a.S3AUtils.java

/**
 * Translate an exception raised in an operation into an IOException.
 * The specific type of IOException depends on the class of
 * {@link AmazonClientException} passed in, and any status codes included
 * in the operation. That is: HTTP error codes are examined and can be
 * used to build a more specific response.
 * @param operation operation//from  ww  w .  j  av a  2s .c  o m
 * @param path path operated on (may be null)
 * @param exception amazon exception raised
 * @return an IOE which wraps the caught exception.
 */
@SuppressWarnings("ThrowableInstanceNeverThrown")
public static IOException translateException(String operation, String path, AmazonClientException exception) {
    String message = String.format("%s%s: %s", operation, path != null ? (" on " + path) : "", exception);
    if (!(exception instanceof AmazonServiceException)) {
        return new AWSClientIOException(message, exception);
    } else {

        IOException ioe;
        AmazonServiceException ase = (AmazonServiceException) exception;
        // this exception is non-null if the service exception is an s3 one
        AmazonS3Exception s3Exception = ase instanceof AmazonS3Exception ? (AmazonS3Exception) ase : null;
        int status = ase.getStatusCode();
        switch (status) {

        case 301:
            if (s3Exception != null) {
                if (s3Exception.getAdditionalDetails() != null
                        && s3Exception.getAdditionalDetails().containsKey(ENDPOINT_KEY)) {
                    message = String.format("Received permanent redirect response to "
                            + "endpoint %s.  This likely indicates that the S3 endpoint "
                            + "configured in %s does not match the AWS region containing " + "the bucket.",
                            s3Exception.getAdditionalDetails().get(ENDPOINT_KEY), ENDPOINT);
                }
                ioe = new AWSS3IOException(message, s3Exception);
            } else {
                ioe = new AWSServiceIOException(message, ase);
            }
            break;
        // permissions
        case 401:
        case 403:
            ioe = new AccessDeniedException(path, null, message);
            ioe.initCause(ase);
            break;

        // the object isn't there
        case 404:
        case 410:
            ioe = new FileNotFoundException(message);
            ioe.initCause(ase);
            break;

        // out of range. This may happen if an object is overwritten with
        // a shorter one while it is being read.
        case 416:
            ioe = new EOFException(message);
            break;

        default:
            // no specific exit code. Choose an IOE subclass based on the class
            // of the caught exception
            ioe = s3Exception != null ? new AWSS3IOException(message, s3Exception)
                    : new AWSServiceIOException(message, ase);
            break;
        }
        return ioe;
    }
}