本文整理匯總了Java中org.apache.commons.httpclient.HttpStatus.SC_NOT_FOUND屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatus.SC_NOT_FOUND屬性的具體用法?Java HttpStatus.SC_NOT_FOUND怎麽用?Java HttpStatus.SC_NOT_FOUND使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.commons.httpclient.HttpStatus
的用法示例。
在下文中一共展示了HttpStatus.SC_NOT_FOUND屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: listObjects
@Override
public ListObjectsResult listObjects(String bucketName, String prefix) {
ListObjectsResult result = new ListObjectsResult();
ArrayList<S3Object> list = new ArrayList<>();
Path path = Paths.get(this.baseDir, bucketName, prefix);
try {
if (Files.exists(path)) {
if (Files.isDirectory(path)) {
Files.list(path).forEach(file -> {
addFileAsObjectToList(file, list, bucketName);
});
} else {
addFileAsObjectToList(path, list, bucketName);
}
}
} catch (IOException e) {
throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
}
result.setObjects(list);
return result;
}
示例2: readObjectStream
@Override
public InputStream readObjectStream(String bucketName, String key, Range range) {
byte[] bytes = new byte[Math.toIntExact(range.getLast() + 1 - range.getFirst())];
Path path = Paths.get(this.baseDir, bucketName, key);
FileInputStream returnStream;
try {
returnStream = new FileInputStream(path.toFile());
if (range.getFirst() != 0) {
long bytesSkipped = 0;
do {
bytesSkipped += returnStream.skip(range.getFirst());
} while (bytesSkipped < range.getFirst());
}
StreamHelpers.readAll(returnStream, bytes, 0, bytes.length);
return new ByteArrayInputStream(bytes);
} catch (IOException e) {
throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
}
}
示例3: handleResponse
@Override
public T handleResponse(HttpResponse response) throws IOException {
int statusCode = response.getStatusLine().getStatusCode();
if (!isSuccessful(statusCode)) {
if (statusCode == HttpStatus.SC_NOT_FOUND && myIgnoreNotFound) {
return null;
}
throw RequestFailedException.forStatusCode(statusCode);
}
try {
if (LOG.isDebugEnabled()) {
String content = getResponseContentAsString(response);
TaskUtil.prettyFormatJsonToLog(LOG, content);
return myGson.fromJson(content, myClass);
}
else {
return myGson.fromJson(getResponseContentAsReader(response), myClass);
}
}
catch (JsonSyntaxException e) {
LOG.warn("Malformed server response", e);
return null;
}
}
示例4: copyPart
@Override
public CopyPartResult copyPart(CopyPartRequest request) {
Map<Integer, CopyPartRequest> partMap = multipartUploads.get(request.getKey());
if (partMap == null) {
throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
}
partMap.put(request.getPartNumber(), request);
CopyPartResult result = new CopyPartResult();
result.setPartNumber(request.getPartNumber());
result.setETag(request.getUploadId());
return result;
}
示例5: executeMethod
@Override
public int executeMethod(HttpMethod httpMethod) {
numberOfCallsToExecuteMethod++;
if (failAlternateResponses && (numberOfCallsToExecuteMethod % 2 == 0)) {
return HttpStatus.SC_NOT_FOUND;
} else {
return httpStatus;
}
}
示例6: setObjectAcl
@Synchronized
@Override
public void setObjectAcl(String bucketName, String key, AccessControlList acl) {
AclSize retVal = aclMap.get(key);
if (retVal == null) {
throw new S3Exception("NoObject", HttpStatus.SC_NOT_FOUND, "NoSuchKey", key);
}
aclMap.put(key, retVal.withAcl(acl));
}
示例7: getObjectAcl
@Override
public AccessControlList getObjectAcl(String bucketName, String key) {
AclSize retVal = aclMap.get(key);
if (retVal == null) {
throw new S3Exception("NoObject", HttpStatus.SC_NOT_FOUND, "NoSuchKey", key);
}
return retVal.getAcl();
}
示例8: getObjectMetadata
@Override
public S3ObjectMetadata getObjectMetadata(String bucketName, String key) {
S3ObjectMetadata metadata = new S3ObjectMetadata();
AclSize data = aclMap.get(key);
if (data == null) {
throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
}
metadata.setContentLength(data.getSize());
Path path = Paths.get(this.baseDir, bucketName, key);
metadata.setLastModified(new Date(path.toFile().lastModified()));
return metadata;
}
示例9: completeMultipartUpload
@Synchronized
@Override
public CompleteMultipartUploadResult completeMultipartUpload(CompleteMultipartUploadRequest request) {
Map<Integer, CopyPartRequest> partMap = multipartUploads.get(request.getKey());
if (partMap == null) {
throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
}
try {
partMap.forEach((index, copyPart) -> {
if (copyPart.getKey() != copyPart.getSourceKey()) {
Path sourcePath = Paths.get(this.baseDir, copyPart.getBucketName(), copyPart.getSourceKey());
Path targetPath = Paths.get(this.baseDir, copyPart.getBucketName(), copyPart.getKey());
try (FileChannel sourceChannel = FileChannel.open(sourcePath, StandardOpenOption.READ);
FileChannel targetChannel = FileChannel.open(targetPath, StandardOpenOption.WRITE)) {
targetChannel.transferFrom(sourceChannel, Files.size(targetPath),
copyPart.getSourceRange().getLast() + 1 - copyPart.getSourceRange().getFirst());
targetChannel.close();
AclSize aclMap = this.aclMap.get(copyPart.getKey());
this.aclMap.put(copyPart.getKey(), aclMap.withSize(Files.size(targetPath)));
} catch (IOException e) {
throw new S3Exception("NoSuchKey", 404, "NoSuchKey", "");
}
}
});
} finally {
multipartUploads.remove(request.getKey());
}
return new CompleteMultipartUploadResult();
}
示例10: copyPart
@Override
public CopyPartResult copyPart(CopyPartRequest request) {
if (aclMap.get(request.getKey()) == null) {
throw new S3Exception("NoObject", HttpStatus.SC_NOT_FOUND, "NoSuchKey", request.getKey());
}
return client.copyPart(request);
}