Search in sources :

Example 1 with SwiftInternalStateException

use of org.apache.hadoop.fs.swift.exceptions.SwiftInternalStateException in project hadoop by apache.

the class SwiftRestClient method findObjects.

/**
   * Find objects in a location
   * @param location URI
   * @param requestHeaders optional request headers
   * @return the body of te response
   * @throws IOException IO problems
   */
private byte[] findObjects(String location, final Header[] requestHeaders) throws IOException {
    URI uri;
    preRemoteCommand("findObjects");
    try {
        uri = new URI(location);
    } catch (URISyntaxException e) {
        throw new SwiftException("Bad URI: " + location, e);
    }
    return perform("findObjects", uri, new GetMethodProcessor<byte[]>() {

        @Override
        public byte[] extractResult(GetMethod method) throws IOException {
            if (method.getStatusCode() == SC_NOT_FOUND) {
                //no result
                throw new FileNotFoundException("Not found " + method.getURI());
            }
            return method.getResponseBody();
        }

        @Override
        protected int[] getAllowedStatusCodes() {
            return new int[] { SC_OK, SC_NOT_FOUND };
        }

        @Override
        protected void setup(GetMethod method) throws SwiftInternalStateException {
            setHeaders(method, requestHeaders);
        }
    });
}
Also used : SwiftInternalStateException(org.apache.hadoop.fs.swift.exceptions.SwiftInternalStateException) GetMethod(org.apache.commons.httpclient.methods.GetMethod) FileNotFoundException(java.io.FileNotFoundException) SwiftException(org.apache.hadoop.fs.swift.exceptions.SwiftException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI)

Example 2 with SwiftInternalStateException

use of org.apache.hadoop.fs.swift.exceptions.SwiftInternalStateException in project hadoop by apache.

the class SwiftRestClient method findObjectsByPrefix.

/**
   * Find objects under a prefix
   *
   * @param path path prefix
   * @param requestHeaders optional request headers
   * @return byte[] file data or null if the object was not found
   * @throws IOException on IO Faults
   * @throws FileNotFoundException if nothing is at the end of the URI -that is,
   * the directory is empty
   */
public byte[] findObjectsByPrefix(SwiftObjectPath path, final Header... requestHeaders) throws IOException {
    preRemoteCommand("findObjectsByPrefix");
    URI uri;
    String dataLocationURI = getEndpointURI().toString();
    try {
        String object = path.getObject();
        if (object.startsWith("/")) {
            object = object.substring(1);
        }
        object = encodeUrl(object);
        dataLocationURI = dataLocationURI.concat("/").concat(path.getContainer()).concat("/?prefix=").concat(object);
        uri = new URI(dataLocationURI);
    } catch (URISyntaxException e) {
        throw new SwiftException("Bad URI: " + dataLocationURI, e);
    }
    return perform("findObjectsByPrefix", uri, new GetMethodProcessor<byte[]>() {

        @Override
        public byte[] extractResult(GetMethod method) throws IOException {
            if (method.getStatusCode() == SC_NOT_FOUND) {
                //no result
                throw new FileNotFoundException("Not found " + method.getURI());
            }
            return method.getResponseBody();
        }

        @Override
        protected int[] getAllowedStatusCodes() {
            return new int[] { SC_OK, SC_NOT_FOUND };
        }

        @Override
        protected void setup(GetMethod method) throws SwiftInternalStateException {
            setHeaders(method, requestHeaders);
        }
    });
}
Also used : SwiftInternalStateException(org.apache.hadoop.fs.swift.exceptions.SwiftInternalStateException) GetMethod(org.apache.commons.httpclient.methods.GetMethod) FileNotFoundException(java.io.FileNotFoundException) SwiftException(org.apache.hadoop.fs.swift.exceptions.SwiftException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 GetMethod (org.apache.commons.httpclient.methods.GetMethod)2 SwiftException (org.apache.hadoop.fs.swift.exceptions.SwiftException)2 SwiftInternalStateException (org.apache.hadoop.fs.swift.exceptions.SwiftInternalStateException)2