Exemplo n.º 1
0
 public boolean execute(String containerName, Object value, ListContainerOptions options) {
   try {
     byte[] toSearch = objectMD5.apply(value);
     for (BlobMetadata metadata : getAllBlobMetadata.execute(containerName, options)) {
       BlobProperties properties = client.getBlobProperties(containerName, metadata.getName());
       if (Arrays.equals(toSearch, properties.getContentMD5())) return true;
     }
     return false;
   } catch (Exception e) {
     Throwables.propagateIfPossible(e, BlobRuntimeException.class);
     throw new BlobRuntimeException(
         String.format(
             "Error searching for ETAG of value: [%2$s] in container:%1$s", containerName, value),
         e);
   }
 }
 @Override
 public String execute(StorageMetadata metadata) {
   switch (metadata.getType()) {
     case CONTAINER:
     case FOLDER:
     case RELATIVE_PATH:
       return metadata.getName();
     case BLOB:
       BlobMetadata blobMd = (BlobMetadata) metadata;
       for (String suffix : BlobStoreConstants.DIRECTORY_SUFFIXES) {
         if (metadata.getName().endsWith(suffix)) {
           return metadata.getName().substring(0, metadata.getName().lastIndexOf(suffix));
         }
       }
       // It is important that this is last, in case there is a file with a known directory
       // suffix who also has content type set to application/directory
       if (blobMd.getContentMetadata().getContentType() != null
           && blobMd.getContentMetadata().getContentType().equals("application/directory"))
         return metadata.getName();
   }
   return null;
 }
Exemplo n.º 3
0
 public int compareTo(BlobMetadata o) {
   if (getName() == null) return -1;
   return (this == o) ? 0 : getName().compareTo(o.getName());
 }
  public void testBlobMetadata_withDefaultMetadata() throws IOException {
    String BLOB_KEY = TestUtils.createRandomBlobKey(null, null);
    // create the blob
    TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY);

    BlobMetadata metadata = blobStore.blobMetadata(CONTAINER_NAME, BLOB_KEY);
    assertNotNull(metadata, "Metadata null");

    assertEquals(metadata.getName(), BLOB_KEY, "Wrong blob name");
    assertEquals(metadata.getType(), StorageType.BLOB, "Wrong blob type");
    assertEquals(
        metadata.getContentMetadata().getContentType(),
        "application/unknown",
        "Wrong blob content-type");
    assertEquals(
        base16().lowerCase().encode(metadata.getContentMetadata().getContentMD5()),
        metadata.getETag(),
        "Wrong blob MD5");
    assertEquals(metadata.getLocation(), null, "Wrong blob location");
    assertEquals(metadata.getProviderId(), null, "Wrong blob provider id");
    assertEquals(metadata.getUri(), null, "Wrong blob URI");
    assertNotNull(metadata.getUserMetadata(), "No blob UserMetadata");
    assertEquals(metadata.getUserMetadata().size(), 0, "Wrong blob UserMetadata");
    // metadata.getLastModified()
    File file = new File(TARGET_CONTAINER_NAME, BLOB_KEY);
    assertEquals(
        metadata.getContentMetadata().getContentLength(),
        Long.valueOf(file.length()),
        "Wrong blob size");
  }