test/java/nio/file/attribute/UserDefinedFileAttributeView/Basic.java

Print this page




 124             throw new RuntimeException("Attribute name not in list");
 125 
 126         // Test: delete
 127         view.delete(ATTR_NAME);
 128         if (hasAttribute(view, ATTR_NAME))
 129             throw new RuntimeException("Attribute name in list");
 130 
 131         // Test: dynamic access
 132         String name = "user:" + ATTR_NAME;
 133         byte[] valueAsBytes = ATTR_VALUE.getBytes();
 134         Files.setAttribute(file, name, valueAsBytes);
 135         byte[] actualAsBytes = (byte[])Files.getAttribute(file, name);
 136         if (!Arrays.equals(valueAsBytes, actualAsBytes))
 137             throw new RuntimeException("Unexpected attribute value");
 138         Map<String,?> map = Files.readAttributes(file, name);
 139         if (!Arrays.equals(valueAsBytes, (byte[])map.get(ATTR_NAME)))
 140             throw new RuntimeException("Unexpected attribute value");
 141         map = Files.readAttributes(file, "user:*");
 142         if (!Arrays.equals(valueAsBytes, (byte[])map.get(ATTR_NAME)))
 143             throw new RuntimeException("Unexpected attribute value");
 144         map = Files.readAttributes(file, "user:DoesNotExist");
 145         if (!map.isEmpty())
 146             throw new RuntimeException("Map expected to be empty");
 147     }
 148 
 149     static void miscTests(final Path file) throws IOException {
 150         final UserDefinedFileAttributeView view =
 151             Files.getFileAttributeView(file, UserDefinedFileAttributeView.class);
 152         view.write(ATTR_NAME, ByteBuffer.wrap(ATTR_VALUE.getBytes()));
 153 
 154         // NullPointerException
 155         final ByteBuffer buf = ByteBuffer.allocate(100);
 156 
 157         expectNullPointerException(new Task() {
 158             public void run() throws IOException {
 159                 view.read(null, buf);
 160             }});
 161         expectNullPointerException(new Task() {
 162             public void run() throws IOException {
 163                 view.read(ATTR_NAME, null);
 164             }});
 165         expectNullPointerException(new Task() {
 166             public void run() throws IOException {




 124             throw new RuntimeException("Attribute name not in list");
 125 
 126         // Test: delete
 127         view.delete(ATTR_NAME);
 128         if (hasAttribute(view, ATTR_NAME))
 129             throw new RuntimeException("Attribute name in list");
 130 
 131         // Test: dynamic access
 132         String name = "user:" + ATTR_NAME;
 133         byte[] valueAsBytes = ATTR_VALUE.getBytes();
 134         Files.setAttribute(file, name, valueAsBytes);
 135         byte[] actualAsBytes = (byte[])Files.getAttribute(file, name);
 136         if (!Arrays.equals(valueAsBytes, actualAsBytes))
 137             throw new RuntimeException("Unexpected attribute value");
 138         Map<String,?> map = Files.readAttributes(file, name);
 139         if (!Arrays.equals(valueAsBytes, (byte[])map.get(ATTR_NAME)))
 140             throw new RuntimeException("Unexpected attribute value");
 141         map = Files.readAttributes(file, "user:*");
 142         if (!Arrays.equals(valueAsBytes, (byte[])map.get(ATTR_NAME)))
 143             throw new RuntimeException("Unexpected attribute value");



 144     }
 145 
 146     static void miscTests(final Path file) throws IOException {
 147         final UserDefinedFileAttributeView view =
 148             Files.getFileAttributeView(file, UserDefinedFileAttributeView.class);
 149         view.write(ATTR_NAME, ByteBuffer.wrap(ATTR_VALUE.getBytes()));
 150 
 151         // NullPointerException
 152         final ByteBuffer buf = ByteBuffer.allocate(100);
 153 
 154         expectNullPointerException(new Task() {
 155             public void run() throws IOException {
 156                 view.read(null, buf);
 157             }});
 158         expectNullPointerException(new Task() {
 159             public void run() throws IOException {
 160                 view.read(ATTR_NAME, null);
 161             }});
 162         expectNullPointerException(new Task() {
 163             public void run() throws IOException {