本文整理汇总了Java中org.jclouds.blobstore.BlobStore.putBlob方法的典型用法代码示例。如果您正苦于以下问题:Java BlobStore.putBlob方法的具体用法?Java BlobStore.putBlob怎么用?Java BlobStore.putBlob使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jclouds.blobstore.BlobStore
的用法示例。
在下文中一共展示了BlobStore.putBlob方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerAddress
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
private void registerAddress(String cluster, InetSocketAddress address) throws HekateException {
try (BlobStoreContext ctx = createContext()) {
BlobStore store = ctx.getBlobStore();
String file = cluster + '/' + AddressUtils.toFileName(address);
try {
if (!store.blobExists(container, file)) {
Blob blob = store.blobBuilder(file)
.type(StorageType.BLOB)
.payload(new byte[]{1})
.build();
store.putBlob(container, blob);
if (log.isInfoEnabled()) {
log.info("Registered address to the cloud store [container={}, file={}]", container, file);
}
}
} catch (ResourceNotFoundException | HttpResponseException e) {
throw new HekateException("Failed to register the seed node address to the cloud store "
+ "[container=" + container + ", file=" + file + ']', e);
}
}
}
示例2: emulateCopyBlob
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
private String emulateCopyBlob(BlobStore blobStore, Response resp, BlobMetadata meta,
String destContainer, String destObject, CopyOptions options) {
Response.StatusType statusInfo = resp.getStatusInfo();
if (statusInfo.equals(Response.Status.OK)) {
ContentMetadata contentMetadata = meta.getContentMetadata();
Map<String, String> newMetadata = new HashMap<>();
newMetadata.putAll(meta.getUserMetadata());
newMetadata.putAll(options.userMetadata());
RESERVED_METADATA.forEach(s -> newMetadata.remove(s));
Blob blob = blobStore.blobBuilder(destObject)
.userMetadata(newMetadata)
.payload(new InputStreamPayload((InputStream) resp.getEntity()))
.contentLength(resp.getLength())
.contentDisposition(contentMetadata.getContentDisposition())
.contentEncoding(contentMetadata.getContentEncoding())
.contentType(contentMetadata.getContentType())
.contentLanguage(contentMetadata.getContentLanguage())
.build();
return blobStore.putBlob(destContainer, blob);
} else {
throw new ClientErrorException(statusInfo.getReasonPhrase(), statusInfo.getStatusCode());
}
}
示例3: 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.");
}
}
示例4: copyBlob
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
public static Blob copyBlob(BlobStore from, BlobStore to, String containerNameTo, Blob blobFrom, InputStream is)
throws IOException {
if (blobFrom == null || BounceLink.isLink(blobFrom.getMetadata())) {
return null;
}
ContentMetadata metadata = blobFrom.getMetadata().getContentMetadata();
PayloadBlobBuilder builder = to.blobBuilder(blobFrom.getMetadata().getName())
.userMetadata(blobFrom.getMetadata().getUserMetadata())
.payload(is);
copyToBlobBuilder(metadata, builder);
if (isSwiftBlobStore(to)) {
copySwiftBlob(from, to, containerNameTo, builder.build());
} else {
to.putBlob(containerNameTo, builder.build(), MULTIPART_PUT);
}
return blobFrom;
}
示例5: testListThreeTiers
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Test
public void testListThreeTiers() throws Exception {
BlobStore blobStore = app.getBlobStore(0);
String cacheBlobName = UtilsTest.createRandomBlobName();
Blob cacheBlob = UtilsTest.makeBlob(blobStore, cacheBlobName);
blobStore.putBlob(containerName, cacheBlob);
BounceService.BounceTaskStatus status = bounceService.bounce(containerName);
status.future().get();
assertStatus(status, status::getCopiedObjectCount).isEqualTo(2);
StorageMetadata metadata = policy.list(containerName).iterator().next();
assertThat(metadata).isInstanceOf(BounceStorageMetadata.class);
assertThat(((BounceStorageMetadata) metadata).getRegions()).isEqualTo(ImmutableSet.of(
BounceStorageMetadata.Region.FAR,
BounceStorageMetadata.Region.NEAR,
BounceStorageMetadata.Region.FARTHER));
}
示例6: testListContainer
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Test
public void testListContainer() throws Exception {
String containerName = Utils.createRandomContainerName();
String blobName = UtilsTest.createRandomBlobName();
BlobStore blobStore = app.getBlobStore(objectStoreId);
blobStore.createContainerInLocation(null, containerName);
Blob blob = UtilsTest.makeBlob(blobStore, blobName);
blobStore.putBlob(containerName, blob);
HttpURLConnection connection = UtilsTest.submitRequest(containerAPI + "/" + containerName,
HttpMethod.GET, null);
assertThat(connection.getResponseCode()).isEqualTo(Response.Status.OK.getStatusCode());
try (InputStream stream = connection.getInputStream()) {
ContainerResource.Container container = new ObjectMapper().readValue(stream,
ContainerResource.Container.class);
assertThat(container.objects).hasSize(1);
assertThat(container.objects.get(0).name).isEqualTo(blobName);
}
}
示例7: testRecursiveList
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Test
public void testRecursiveList() throws Exception {
String container = Utils.createRandomContainerName();
BlobStore blobStore = app.getBlobStore(objectStoreId);
blobStore.createContainerInLocation(null, container);
String blob = "foo/bar";
String blob2 = "foo/baz";
blobStore.putBlob(container, UtilsTest.makeBlob(blobStore, blob));
blobStore.putBlob(container, UtilsTest.makeBlob(blobStore, blob2));
HttpURLConnection connection = UtilsTest.submitRequest(containerAPI + "/" + container, HttpMethod.GET, null);
assertThat(connection.getResponseCode()).isEqualTo(Response.Status.OK.getStatusCode());
try (InputStream stream = connection.getInputStream()) {
ContainerResource.Container resultContainer = new ObjectMapper().readValue(stream,
ContainerResource.Container.class);
assertThat(resultContainer.objects).hasSize(2);
assertThat(resultContainer.objects.get(0).name).isEqualTo(blob);
assertThat(resultContainer.objects.get(1).name).isEqualTo(blob2);
}
}
示例8: testConfigMoveEverythingPolicy
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Test
public void testConfigMoveEverythingPolicy() throws Exception {
setTransientBackend();
app.getBlobStore(0).createContainerInLocation(null, containerName);
app.getBlobStore(1).createContainerInLocation(null, containerName);
BlobStore blobStore = app.getBlobStore(0);
blobStore.createContainerInLocation(null, containerName);
blobStore.putBlob(containerName,
UtilsTest.makeBlob(blobStore, UtilsTest.createRandomBlobName()));
configureMoveEverythingPolicy();
blobStore = app.getBlobStore(containerName);
blobStore.createContainerInLocation(null, containerName);
BounceService.BounceTaskStatus status = bounceService.bounce(containerName);
status.future().get();
assertStatus(status, status::getTotalObjectCount).isEqualTo(1);
assertStatus(status, status::getMovedObjectCount).isEqualTo(1);
assertStatus(status, status::getErrorObjectCount).isEqualTo(0);
}
示例9: createRawContent
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
/**
* As {@link #createRawContent(String, byte[])} except sets {@link BlobAccess} for the path also
* @param contentPath
* @param access
* @param content
*/
public final void createRawContent(String contentPath, BlobAccess access, byte[] content) {
// contentPaths.add(contentPath);
BlobStore blobStore = blobStoreContext.getBlobStore();
Blob blob = blobStore.blobBuilder(contentPath)
.payload(content)
.contentLength(content.length)
.contentType(MediaType.OCTET_STREAM.toString())
.build();
blobStore.putBlob(CONTAINER_NAME, blob);
if (access != null) {
blobStore.setBlobAccess(CONTAINER_NAME, contentPath, access);
}
}
示例10: writeBlob
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
/**
* Writes {@link Payload} to the the {@link BlobStore}.
*/
public static void writeBlob(BlobStore blobStore, String container, String blobName, Payload payload) {
if (blobName != null && payload != null) {
mkDirs(blobStore, container, blobName);
Blob blob = blobStore.blobBuilder(blobName).payload(payload).contentType(MediaType.APPLICATION_OCTET_STREAM).contentDisposition(blobName).build();
blobStore.putBlob(container, blob, multipart());
}
}
示例11: upload
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
@Override
public String upload(InputStream content, Blob blob) throws IOException {
BlobStore blobStore = this.blobStoreContext.getBlobStore();
blob.setPayload(content);
blobStore.putBlob(containerName, blob);
return "etag";
}
示例12: saveInputStream
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public long saveInputStream(String id, String root, String filePath, InputStream stream) throws IOException {
if(stream == null){
return 0L;
}
ContainerAndName can = getContainerAndName(id, root, filePath);
createContainerIfNotExist(can.container);
InputStream in = markableInputStream(stream);
long size = markableStreamLength(in);
Payload payload = Payloads.newInputStreamPayload(in);
try {
BlobStore store = getBlobStore();
String asciiID = Base64.encodeBase64String(id.getBytes("UTF8"));
Blob blob = store.blobBuilder(can.name)
.payload(payload)
.contentLength(size)
.userMetadata(ImmutableMap.of("id", asciiID, "path", filePath))
.build();
store.putBlob(can.container, blob);
} finally {
payload.release();
Closeables.close(stream, true);
Closeables.close(in, true);
}
return size;
}
示例13: putMetadataBlob
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
public static String putMetadataBlob(Map<String, String> metadata, BlobStore blobStore, String vault,
String archiveName) {
Gson gson = new Gson();
String jsonString = gson.toJson(metadata);
Blob metadataBlob = blobStore.blobBuilder(getMetadataBlobName(archiveName))
.payload(ByteSource.wrap(jsonString.getBytes())).build();
return blobStore.putBlob(vault, metadataBlob);
}
示例14: copySwiftBlob
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
private static void copySwiftBlob(BlobStore from, BlobStore to, String containerNameTo, Blob blob) {
// TODO: swift object semantic changes if we do multipart upload,
// if both sides are swift, we may want to just copy the individual parts
PutOptions options = PutOptions.NONE;
if (blob.getMetadata().getContentMetadata().getContentLength() > to.getMaximumMultipartPartSize()) {
options = MULTIPART_PUT;
}
to.putBlob(containerNameTo, blob, options);
}
示例15: uploadSourceBlob
import org.jclouds.blobstore.BlobStore; //导入方法依赖的package包/类
private void uploadSourceBlob() {
BlobStore blobStore = app.getBlobStore(0);
String blobName = UtilsTest.createRandomBlobName();
byte[] blobContent = "foo".getBytes();
blob = UtilsTest.makeBlob(blobStore, blobName, ByteSource.wrap(blobContent));
blobStore.createContainerInLocation(null, container);
blobStore.putBlob(container, blob);
}