< prev index next >

src/java.base/share/classes/sun/nio/fs/AbstractUserDefinedFileAttributeView.java

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


  66         ByteBuffer bb;
  67         if (value instanceof byte[]) {
  68             bb = ByteBuffer.wrap((byte[])value);
  69         } else {
  70             bb = (ByteBuffer)value;
  71         }
  72         write(attribute, bb);
  73     }
  74 
  75     @Override
  76     public final Map<String,Object> readAttributes(String[] attributes)
  77         throws IOException
  78     {
  79         // names of attributes to return
  80         List<String> names = new ArrayList<>();
  81         for (String name: attributes) {
  82             if (name.equals("*")) {
  83                 names = list();
  84                 break;
  85             } else {
  86                 if (name.length() == 0)
  87                     throw new IllegalArgumentException();
  88                 names.add(name);
  89             }
  90         }
  91 
  92         // read each value and return in map
  93         Map<String,Object> result = new HashMap<>();
  94         for (String name: names) {
  95             int size = size(name);
  96             byte[] buf = new byte[size];
  97             int n = read(name, ByteBuffer.wrap(buf));
  98             byte[] value = (n == size) ? buf : Arrays.copyOf(buf, n);
  99             result.put(name, value);
 100         }
 101         return result;
 102     }
 103 }


  66         ByteBuffer bb;
  67         if (value instanceof byte[]) {
  68             bb = ByteBuffer.wrap((byte[])value);
  69         } else {
  70             bb = (ByteBuffer)value;
  71         }
  72         write(attribute, bb);
  73     }
  74 
  75     @Override
  76     public final Map<String,Object> readAttributes(String[] attributes)
  77         throws IOException
  78     {
  79         // names of attributes to return
  80         List<String> names = new ArrayList<>();
  81         for (String name: attributes) {
  82             if (name.equals("*")) {
  83                 names = list();
  84                 break;
  85             } else {
  86                 if (name.isEmpty())
  87                     throw new IllegalArgumentException();
  88                 names.add(name);
  89             }
  90         }
  91 
  92         // read each value and return in map
  93         Map<String,Object> result = new HashMap<>();
  94         for (String name: names) {
  95             int size = size(name);
  96             byte[] buf = new byte[size];
  97             int n = read(name, ByteBuffer.wrap(buf));
  98             byte[] value = (n == size) ? buf : Arrays.copyOf(buf, n);
  99             result.put(name, value);
 100         }
 101         return result;
 102     }
 103 }
< prev index next >