本文整理汇总了Java中org.jclouds.blobstore.domain.Blob类的典型用法代码示例。如果您正苦于以下问题:Java Blob类的具体用法?Java Blob怎么用?Java Blob使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Blob类属于org.jclouds.blobstore.domain包,在下文中一共展示了Blob类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerAddress
import org.jclouds.blobstore.domain.Blob; //导入依赖的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: saveFileResourceContent
import org.jclouds.blobstore.domain.Blob; //导入依赖的package包/类
@Override
public String saveFileResourceContent( FileResource fileResource, byte[] bytes )
{
Blob blob = createBlob( fileResource, bytes );
if ( blob == null )
{
return null;
}
putBlob( blob );
log.debug( String.format( "File resource saved with key: %s", fileResource.getStorageKey() ) );
return fileResource.getStorageKey();
}
示例3: putBlob
import org.jclouds.blobstore.domain.Blob; //导入依赖的package包/类
private String putBlob( Blob blob )
{
String etag = null;
try
{
etag = blobStore.putBlob( config.container, blob );
}
catch ( RuntimeException rte )
{
Throwable cause = rte.getCause();
if ( cause != null && cause instanceof UserPrincipalNotFoundException )
{
// Intentionally ignored exception which occurs with JClouds (< 2.0.0) on localized Windows.
// See https://issues.apache.org/jira/browse/JCLOUDS-1015
log.debug( "Ignored UserPrincipalNotFoundException. Workaround for 'JCLOUDS-1015'." );
}
else
{
throw rte;
}
}
return etag;
}
示例4: get
import org.jclouds.blobstore.domain.Blob; //导入依赖的package包/类
@Override
public Reader get( EntityReference entityReference )
throws EntityStoreException
{
Blob blob = storeContext.getBlobStore().getBlob( container, entityReference.identity().toString() );
if( blob == null )
{
throw new EntityNotFoundException( entityReference );
}
Payload payload = blob.getPayload();
if( payload == null )
{
throw new EntityNotFoundException( entityReference );
}
try( InputStream input = payload.openStream() )
{
String state = new Scanner( input, StandardCharsets.UTF_8.name() ).useDelimiter( "\\Z" ).next();
return new StringReader( state );
}
catch( IOException ex )
{
throw new EntityStoreException( "Unable to read entity state for: " + entityReference, ex );
}
}
示例5: emulateCopyBlob
import org.jclouds.blobstore.domain.Blob; //导入依赖的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());
}
}
示例6: saveFileResourceContent
import org.jclouds.blobstore.domain.Blob; //导入依赖的package包/类
@Override
public String saveFileResourceContent( FileResource fileResource, File file )
{
Blob blob = createBlob( fileResource, file );
if ( blob == null )
{
return null;
}
putBlob( blob );
try
{
Files.deleteIfExists( file.toPath() );
}
catch ( IOException ioe )
{
// Intentionally ignored
log.warn( "Temporary file '" + file.toPath() + "' could not be deleted.", ioe );
}
return fileResource.getStorageKey();
}
示例7: getInputStream
import org.jclouds.blobstore.domain.Blob; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public InputStream getInputStream(String id, String root, String filePath) throws IOException {
ContainerAndName can = getContainerAndName(id, root, filePath);
Blob blob = getBlobStore().getBlob(can.container, can.name);
if (blob == null){
throw new IOException("No object found for " + id);
}
StorageMetadata metadata = blob.getMetadata();
Long size = metadata.getSize();
if (size != null && size.longValue() > maxBlobStreamSize) {
return streamFromTempFile(blob, size);
} else {
// SAK-30325: why can't we just send the stream straight back: blob.getPayload().openStream() ?
// Good question, but it doesn't work properly unless the stream is fully copied and re-streamed....
return new ByteArrayInputStream(FileCopyUtils.copyToByteArray(blob.getPayload().openStream()));
}
}
示例8: handleRetrieveArchiveJob
import org.jclouds.blobstore.domain.Blob; //导入依赖的package包/类
private void handleRetrieveArchiveJob(HttpExchange httpExchange, String vault, JsonObject job) throws IOException{
String blobName = job.get("ArchiveId").getAsString();
Blob blob = proxy.getBlobStore().getBlob(vault, blobName);
if (blob == null) {
Util.sendNotFound("archive", blobName, httpExchange);
return;
}
JsonObject metadata = Util.getMetadata(proxy.getBlobStore(), vault, blobName);
logger.debug("Job {}: Retrieve archive {}/{}", job.get("JobId"), vault, blobName);
long size = blob.getMetadata().getSize();
httpExchange.getResponseHeaders().put("Content-Length", ImmutableList.of(Long.toString(size)));
httpExchange.getResponseHeaders().put("x-amz-sha256-tree-hash",
ImmutableList.of(metadata.get(Archive.METADATA_TREE_HASH).getAsString()));
httpExchange.sendResponseHeaders(Response.Status.OK.getStatusCode(), size);
try (InputStream from = blob.getPayload().openStream()){
ByteStreams.copy(from, httpExchange.getResponseBody());
}
}
示例9: getMetadata
import org.jclouds.blobstore.domain.Blob; //导入依赖的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();
}
}
示例10: moveFile
import org.jclouds.blobstore.domain.Blob; //导入依赖的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.");
}
}
示例11: storeBlock
import org.jclouds.blobstore.domain.Blob; //导入依赖的package包/类
/**
* Uploads the block to the cloud service.
*/
@Override
protected void storeBlock(byte[] digest, int level, byte[] data) throws IOException {
Preconditions.checkNotNull(context);
String id = StringUtils.convertBytesToHex(digest);
cache.put(id, data);
org.jclouds.blobstore.BlobStore blobStore = context.getBlobStore();
if (!blobStore.blobExists(cloudContainer, id)) {
Map<String, String> metadata = Maps.newHashMap();
metadata.put("level", String.valueOf(level));
Blob blob = blobStore.blobBuilder(id)
.payload(data)
.userMetadata(metadata)
.build();
String etag = blobStore.putBlob(cloudContainer, blob, multipart());
LOG.debug("Blob " + id + " created with cloud tag : " + etag);
} else {
LOG.debug("Blob " + id + " already exists");
}
}
示例12: putBlob
import org.jclouds.blobstore.domain.Blob; //导入依赖的package包/类
@Override
public String putBlob(final String containerName, Blob blob,
final PutOptions options) {
final String nearName = blob.getMetadata().getName();
String nearETag = writeStore.putBlob(containerName, blob, options);
schedule(new Callable<String>() {
@Override
public String call() {
Blob nearBlob = writeStore.getBlob(containerName, nearName);
String farETag = delegate().putBlob(containerName,
nearBlob, options);
return farETag;
}
});
return nearETag;
}
示例13: putBlob
import org.jclouds.blobstore.domain.Blob; //导入依赖的package包/类
@Override
public String putBlob(String containerName, Blob blob, PutOptions options) {
BouncePolicy policy = getPolicyFromContainer(containerName);
if (blob.getMetadata().getName().equals(lastPutObject)) {
// drain bounce if this is an immediate overwrite, because
// we could be bouncing this object
drainBackgroundTasks();
}
Long length = blob.getMetadata().getContentMetadata().getContentLength();
lastPutObject = blob.getMetadata().getName();
String result = policy.putBlob(containerName, blob, options);
if (result == null) {
return null;
}
if (length != null) {
pendingBytes.getAndAdd(length);
}
pendingObjects.getAndIncrement();
return result;
}
示例14: testMoveEverythingTwice
import org.jclouds.blobstore.domain.Blob; //导入依赖的package包/类
@Test
public void testMoveEverythingTwice() throws Exception {
toggleMoveEverything();
String blobName = UtilsTest.createRandomBlobName();
policy.putBlob(containerName, UtilsTest.makeBlob(policy, blobName));
Blob blob = policy.getBlob(containerName, blobName);
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);
status = bounceService.bounce(containerName);
status.future().get();
assertStatus(status, status::getTotalObjectCount).isEqualTo(1);
assertStatus(status, status::getMovedObjectCount).isEqualTo(0);
assertStatus(status, status::getErrorObjectCount).isEqualTo(0);
UtilsTest.assertEqualBlobs(blob, policy.getBlob(containerName, blobName));
}
示例15: testUnbounce
import org.jclouds.blobstore.domain.Blob; //导入依赖的package包/类
@Test
public void testUnbounce() throws Exception {
String blobName = "blob";
Blob blob = UtilsTest.makeBlob(farBlobStore, blobName);
nearBlobStore.putBlob(containerName, blob);
Utils.copyBlobAndCreateBounceLink(nearBlobStore, farBlobStore,
containerName, blobName);
assertThat(nearBlobStore.blobExists(containerName, blobName)).isTrue();
assertThat(farBlobStore.blobExists(containerName, blobName)).isTrue();
Blob nearBlob = nearBlobStore.getBlob(containerName, blobName);
assertThat(BounceLink.isLink(nearBlob.getMetadata())).isTrue();
policy.getBlob(containerName, blobName, GetOptions.NONE);
assertThat(nearBlobStore.blobExists(containerName, blobName)).isTrue();
assertThat(farBlobStore.blobExists(containerName, blobName)).isTrue();
nearBlob = nearBlobStore.getBlob(containerName, blobName);
assertThat(BounceLink.isLink(nearBlob.getMetadata())).isFalse();
Blob farBlob = farBlobStore.getBlob(containerName, blobName);
UtilsTest.assertEqualBlobs(nearBlob, blob);
UtilsTest.assertEqualBlobs(farBlob, blob);
}