示例#1
0
 /**
  * Injects the StorageInfo into the FileAttributes.
  *
  * <p>Legacy fields that used to be stored in StorageInfo, but are now stored in FileAttributes,
  * are injected into the FileAttributes too.
  *
  * <p>Should only be used when backwards compatibility must be maintained.
  */
 public static FileAttributes injectInto(StorageInfo info, FileAttributes attributes) {
   attributes.setStorageInfo(info);
   attributes.setSize(info.getLegacySize());
   attributes.setAccessLatency(info.getLegacyAccessLatency());
   attributes.setRetentionPolicy(info.getLegacyRetentionPolicy());
   String cFlag = info.getKey("flag-c");
   if (cFlag != null) {
     attributes.setChecksums(
         Sets.newHashSet(
             transform(
                 Splitter.on(',').trimResults().omitEmptyStrings().split(cFlag),
                 new Function<String, Checksum>() {
                   @Override
                   public Checksum apply(String digest) {
                     return Checksum.parseChecksum(digest);
                   }
                 })));
   }
   String uid = info.getKey("uid");
   if (uid != null) {
     attributes.setOwner(Integer.parseInt(uid));
   }
   String gid = info.getKey("gid");
   if (gid != null) {
     attributes.setGroup(Integer.parseInt(gid));
   }
   attributes.setFlags(info.getMap());
   return attributes;
 }
 private FileAttributes getFileAttributesForNotification(Set<URI> uris) throws CacheException {
   FileAttributes fileAttributes = descriptor.getFileAttributes();
   StorageInfo storageInfo = fileAttributes.getStorageInfo().clone();
   for (URI uri : uris) {
     try {
       HsmLocationExtractorFactory.validate(uri);
       storageInfo.addLocation(uri);
       storageInfo.isSetAddLocation(true);
     } catch (IllegalArgumentException e) {
       throw new CacheException(2, e.getMessage(), e);
     }
   }
   FileAttributes fileAttributesForNotification = new FileAttributes();
   fileAttributesForNotification.setAccessLatency(fileAttributes.getAccessLatency());
   fileAttributesForNotification.setRetentionPolicy(fileAttributes.getRetentionPolicy());
   fileAttributesForNotification.setStorageInfo(storageInfo);
   fileAttributesForNotification.setSize(fileAttributes.getSize());
   return fileAttributesForNotification;
 }