Example usage for java.nio.file FileSystemException initCause

List of usage examples for java.nio.file FileSystemException initCause

Introduction

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

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

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

/**
 * Builds and throws a {@link FileSystemException} from {@link #res}.
 * <p>/*from w ww  .  j a v  a 2s.co 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;
}