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);
}
});
}
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);
}
});
}
Aggregations