本文整理汇总了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: executeMethod
@Override
public int executeMethod(HttpMethod httpMethod) {
numberOfCallsToExecuteMethod++;
if (failAlternateResponses && (numberOfCallsToExecuteMethod % 2 == 0)) {
return HttpStatus.SC_NOT_FOUND;
} else {
return httpStatus;
}
}
示例5: 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));
}
示例6: 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();
}
示例7: 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;
}
示例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);
}