示例#1
0
 /**
  * Extracts the StorageInfo stored in the FileAttributes.
  *
  * <p>Initializes legacy fields that used to be stored in StorageInfo, but are now stored in
  * FileAttributes.
  *
  * <p>Should only be used when backwards compatibility must be maintained.
  */
 public static StorageInfo extractFrom(FileAttributes attributes) {
   StorageInfo info = attributes.getStorageInfo();
   if (attributes.isDefined(FileAttribute.SIZE)) {
     info.setLegacySize(attributes.getSize());
   }
   if (attributes.isDefined(FileAttribute.ACCESS_LATENCY)) {
     info.setLegacyAccessLatency(attributes.getAccessLatency());
   }
   if (attributes.isDefined(FileAttribute.RETENTION_POLICY)) {
     info.setLegacyRetentionPolicy(attributes.getRetentionPolicy());
   }
   if (attributes.isDefined(FileAttribute.FLAGS)) {
     for (Map.Entry<String, String> entry : attributes.getFlags().entrySet()) {
       info.setKey(entry.getKey(), entry.getValue());
     }
   }
   if (attributes.isDefined(FileAttribute.CHECKSUM)) {
     info.setKey("flag-c", Joiner.on(',').join(attributes.getChecksums()));
   }
   if (attributes.isDefined(FileAttribute.OWNER)) {
     info.setKey("uid", Integer.toString(attributes.getOwner()));
   }
   if (attributes.isDefined(FileAttribute.OWNER_GROUP)) {
     info.setKey("gid", Integer.toString(attributes.getGroup()));
   }
   return info;
 }