本文整理汇总了Java中org.jclouds.blobstore.BlobStore.getBlob方法的典型用法代码示例。如果您正苦于以下问题:Java BlobStore.getBlob方法的具体用法?Java BlobStore.getBlob怎么用?Java BlobStore.getBlob使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jclouds.blobstore.BlobStore
的用法示例。
在下文中一共展示了BlobStore.getBlob方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMetadata
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
public static JsonObject getMetadata(BlobStore blobStore, String vault, String name) {
Blob blob;
try {
blob = blobStore.getBlob(vault, Util.getMetadataBlobName(name));
} catch (ContainerNotFoundException cnfe) {
return new JsonObject();
}
if (blob == null) {
return new JsonObject();
}
try (InputStream out = blob.getPayload().openStream()) {
JsonParser parser = new JsonParser();
return parser.parse(new InputStreamReader(out)).getAsJsonObject();
} catch (IOException io) {
return new JsonObject();
}
}
示例2: moveFile
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
/**
* Move a file from one AWS S3 folder to another.
*
* @param blobStore the blob store
* @param sourceKey the file source location
* @param destinationFolder the destination folder
* @return the destination key of the moved file
* @throws KeyNotFoundException if a key is not found
*/
@GuardedBy("ThreadLocal blobStore")
private String moveFile(final BlobStore blobStore, final String sourceKey,
final String destinationFolder) throws KeyNotFoundException {
final Blob blob = blobStore.getBlob(config.getS3().getBucket(), sourceKey);
if (blob != null) {
final String destinationKey = destinationFolder + "/"
+ sourceKey.substring(sourceKey.lastIndexOf('/') + 1);
blob.getMetadata().setName(destinationKey);
blobStore.putBlob(config.getS3().getBucket(), blob);
blobStore.removeBlob(config.getS3().getBucket(), sourceKey);
return destinationKey;
} else {
throw new KeyNotFoundException(sourceKey, config.getS3().getBucket(), "Error while moving file.");
}
}
示例3: readBlob
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
/**
* Reads from a {@link BlobStore}. It returns an Object.
*/
public static InputStream readBlob(BlobStore blobStore, String container, String blobName) throws IOException {
InputStream is = null;
if (!Strings.isNullOrEmpty(blobName)) {
Blob blob = blobStore.getBlob(container, blobName);
if (blob != null && blob.getPayload() != null) {
is = blobStore.getBlob(container, blobName).getPayload().openStream();
}
}
return is;
}
示例4: getBlob
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Override
public Blob getBlob(String container, String blobName, GetOptions options) {
for (BlobStore blobStore : getCheckedStores()) {
Blob blob = blobStore.getBlob(container, blobName, options);
if (blob != null) {
return blob;
}
}
return null;
}
示例5: copyBlob
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
public static Blob copyBlob(BlobStore from, BlobStore to,
String containerNameFrom, String containerNameTo, String blobName,
boolean saveSystemMetadata)
throws IOException {
Blob blobFrom = from.getBlob(containerNameFrom, blobName);
if (blobFrom == null) {
return null;
}
return copyBlob(from, to, containerNameTo, blobFrom, saveSystemMetadata);
}
示例6: assertEqualBlobStores
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
private void assertEqualBlobStores(BlobStore one, BlobStore two) throws Exception {
Iterator<StorageMetadata> iterFromOne = Utils.crawlBlobStore(one, containerName).iterator();
Iterator<StorageMetadata> iterFromTwo = Utils.crawlBlobStore(two, containerName).iterator();
while (iterFromOne.hasNext() && iterFromTwo.hasNext()) {
StorageMetadata refMeta = iterFromOne.next();
StorageMetadata policyMeta = iterFromTwo.next();
assertThat(Utils.equalsOtherThanTime(refMeta, policyMeta)).isTrue();
Blob blobOne = one.getBlob(containerName, refMeta.getName());
Blob blobTwo = two.getBlob(containerName, refMeta.getName());
UtilsTest.assertEqualBlobs(blobOne, blobTwo);
}
assertThat(iterFromOne.hasNext()).isEqualTo(iterFromTwo.hasNext());
}
示例7: deleteObject
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@DELETE
public Response deleteObject(@NotNull @PathParam("account") String account,
@NotNull @PathParam("container") String container,
@NotNull @Encoded @PathParam("object") String objectName,
@QueryParam("multipart-manifest") String multipartManifest,
@HeaderParam("X-Auth-Token") String authToken) throws IOException {
if (objectName.length() > InfoResource.CONFIG.swift.max_object_name_length) {
return badRequest();
}
BlobStore store = getBlobStore(authToken).get(container, objectName);
if ("delete".equals(multipartManifest)) {
Blob blob;
try {
blob = store.getBlob(container, objectName);
} catch (ContainerNotFoundException cnfe) {
blob = null;
}
if (blob == null) {
return Response.status(Response.Status.OK)
.entity("{\"Number Not Found\": 1" +
", \"Response Status\": \"404 Not Found\"" +
// TODO: JSON encode container and objectName
", \"Errors\": [[\"/" + container + "/" + objectName + "\", \"Not found\"]]" +
", \"Number Deleted\": 0" +
", \"Response Body\": \"\"}")
.build();
}
if (!blob.getMetadata().getUserMetadata().containsKey(STATIC_OBJECT_MANIFEST)) {
return Response.status(Response.Status.OK)
.entity("{\"Number Not Found\": 0" +
", \"Response Status\": \"400 Bad Request\"" +
// TODO: JSON encode container and objectName
", \"Errors\": [[\"/" + container + "/" + objectName + "\", \"Not an SLO manifest\"]]" +
", \"Number Deleted\": 0" +
", \"Response Body\": \"\"}")
.build();
}
ManifestEntry[] entries = readSLOManifest(blob.getPayload().openStream());
Arrays.stream(entries).parallel().forEach(e -> store.removeBlob(e.container, e.object));
store.removeBlob(container, objectName);
return Response.status(Response.Status.OK)
.entity("{\"Number Not Found\": 0" +
", \"Response Status\": \"200 OK\"" +
", \"Errors\": [[]]" +
", \"Number Deleted\": " + entries.length +
", \"Response Body\": \"\"}")
.build();
}
if (!store.containerExists(container)) {
return Response.status(Response.Status.NOT_FOUND).build();
}
BlobMetadata meta = store.blobMetadata(container, objectName);
if (meta == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
store.removeBlob(container, objectName);
return Response.noContent()
.type(meta.getContentMetadata().getContentType())
.build();
}
示例8: handleGetBlob
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
private void handleGetBlob(HttpServletRequest request,
HttpServletResponse response, BlobStore blobStore,
String containerName, String blobName)
throws IOException, S3Exception {
int status = HttpServletResponse.SC_OK;
GetOptions options = new GetOptions();
String ifMatch = request.getHeader(HttpHeaders.IF_MATCH);
if (ifMatch != null) {
options.ifETagMatches(ifMatch);
}
String ifNoneMatch = request.getHeader(HttpHeaders.IF_NONE_MATCH);
if (ifNoneMatch != null) {
options.ifETagDoesntMatch(ifNoneMatch);
}
long ifModifiedSince = request.getDateHeader(
HttpHeaders.IF_MODIFIED_SINCE);
if (ifModifiedSince != -1) {
options.ifModifiedSince(new Date(ifModifiedSince));
}
long ifUnmodifiedSince = request.getDateHeader(
HttpHeaders.IF_UNMODIFIED_SINCE);
if (ifUnmodifiedSince != -1) {
options.ifUnmodifiedSince(new Date(ifUnmodifiedSince));
}
String range = request.getHeader(HttpHeaders.RANGE);
if (range != null && range.startsWith("bytes=") &&
// ignore multiple ranges
range.indexOf(',') == -1) {
range = range.substring("bytes=".length());
String[] ranges = range.split("-", 2);
if (ranges[0].isEmpty()) {
options.tail(Long.parseLong(ranges[1]));
} else if (ranges[1].isEmpty()) {
options.startAt(Long.parseLong(ranges[0]));
} else {
options.range(Long.parseLong(ranges[0]),
Long.parseLong(ranges[1]));
}
status = HttpServletResponse.SC_PARTIAL_CONTENT;
}
Blob blob;
try {
blob = blobStore.getBlob(containerName, blobName, options);
} catch (IllegalArgumentException iae) {
// TODO: correct mapping?
throw new S3Exception(S3ErrorCode.INVALID_RANGE, iae);
}
if (blob == null) {
throw new S3Exception(S3ErrorCode.NO_SUCH_KEY);
}
response.setStatus(status);
if (corsAllowAll) {
response.addHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*");
}
addMetadataToResponse(request, response, blob.getMetadata());
// TODO: handles only a single range due to jclouds limitations
Collection<String> contentRanges =
blob.getAllHeaders().get(HttpHeaders.CONTENT_RANGE);
if (!contentRanges.isEmpty()) {
response.addHeader(HttpHeaders.CONTENT_RANGE,
contentRanges.iterator().next());
response.addHeader(HttpHeaders.ACCEPT_RANGES,
"bytes");
}
try (InputStream is = blob.getPayload().openStream();
OutputStream os = response.getOutputStream()) {
ByteStreams.copy(is, os);
os.flush();
}
}
示例9: testRandomOperations
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Test
public void testRandomOperations() throws Exception {
BlobStore reference = UtilsTest.createTransientBlobStore();
reference.createContainerInLocation(null, containerName);
final int baseNumTest = 100;
Random r = new Random();
if (System.getProperty("TEST_SEED") != null) {
r.setSeed(Long.valueOf(System.getProperty("TEST_SEED")));
} else {
long seed = new Random().nextLong();
logger.info("seed: {}", seed);
r.setSeed(seed);
}
int objectCount = baseNumTest + r.nextInt(baseNumTest);
ArrayList<String> blobNames = new ArrayList<>(objectCount);
for (int i = 0; i < objectCount; i++) {
blobNames.add("blob-" + r.nextInt(Integer.MAX_VALUE));
}
List<BlobStore> blobStores = ImmutableList.of(reference, policy);
int numBlobsInStore = 0;
int opsCount = baseNumTest + r.nextInt(baseNumTest);
for (int i = 0; i < opsCount; i++) {
String blobName = blobNames.get(r.nextInt(blobNames.size()));
int op = r.nextInt(3);
if (op == 0) {
// PUT
int blobLen = 1000 + r.nextInt(1000);
blobStores.forEach(b -> {
Blob blob = UtilsTest.makeBlob(b, blobName, ByteSource.wrap(new byte[blobLen]));
b.putBlob(containerName, blob);
});
numBlobsInStore++;
} else if (op == 1) {
// GET
Blob one = reference.getBlob(containerName, blobName);
Blob two = policy.getBlob(containerName, blobName);
UtilsTest.assertEqualBlobs(two, one);
} else if (op == 2) {
// DELETE
blobStores.forEach(b -> b.removeBlob(containerName, blobName));
}
}
assertEqualBlobStores(reference, policy);
BounceService.BounceTaskStatus status = runBounce(bounceService, containerName);
if (policy.getDestination() instanceof BouncePolicy) {
assertStatus(status, status::getTotalObjectCount).isLessThanOrEqualTo(numBlobsInStore * 2);
} else {
assertStatus(status, status::getTotalObjectCount).isLessThanOrEqualTo(numBlobsInStore);
}
numBlobsInStore = (int) status.getTotalObjectCount();
assertStatus(status, status::getCopiedObjectCount).isEqualTo(numBlobsInStore);
assertEqualBlobStores(reference, policy);
UtilsTest.advanceServiceClock(app, duration.plusSeconds(1));
status = runBounce(bounceService, containerName);
assertStatus(status, status::getTotalObjectCount).isEqualTo(numBlobsInStore);
assertThat(status.getLinkedObjectCount() + status.getMovedObjectCount()).isEqualTo(numBlobsInStore);
}
示例10: getContentAsLines
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
/**
* Directly retrieves content
* @param contentPath
* @return
* @throws IOException
*/
public final List<String> getContentAsLines(String contentPath) throws IOException {
BlobStore blobStore = blobStoreContext.getBlobStore();
Blob blob = blobStore.getBlob(CONTAINER_NAME, contentPath);
return IOUtils.readLines(blob.getPayload().openStream());
}