3909N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. 893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 893N/A * This code is free software; you can redistribute it and/or modify it 893N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 893N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 893N/A * This code is distributed in the hope that it will be useful, but WITHOUT 893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 893N/A * version 2 for more details (a copy is included in the LICENSE file that 893N/A * accompanied this code). 893N/A * You should have received a copy of the GNU General Public License version 893N/A * 2 along with this work; if not, write to the Free Software Foundation, 893N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 893N/A * A file attribute view that provides a view of a file's user-defined 893N/A * attributes, sometimes known as <em>extended attributes</em>. User-defined 893N/A * file attributes are used to store metadata with a file that is not meaningful 893N/A * to the file system. It is primarily intended for file system implementations 893N/A * that support such a capability directly but may be emulated. The details of 893N/A * such emulation are highly implementation specific and therefore not specified. 893N/A * <p> This {@code FileAttributeView} provides a view of a file's user-defined 893N/A * attributes as a set of name/value pairs, where the attribute name is 893N/A * represented by a {@code String}. An implementation may require to encode and 893N/A * decode from the platform or file system representation when accessing the 893N/A * attribute. The value has opaque content. This attribute view defines the 893N/A * {@link #read read} and {@link #write write} methods to read the value into 893N/A * or write from a {@link ByteBuffer}. This {@code FileAttributeView} is not 893N/A * intended for use where the size of an attribute value is larger than {@link 893N/A * <p> User-defined attributes may be used in some implementations to store 893N/A * security related attributes so consequently, in the case of the default 893N/A * provider at least, all methods that access user-defined attributes require the 893N/A * {@code RuntimePermission("accessUserDefinedAttributes")} permission when a 893N/A * security manager is installed. 893N/A * <p> The {@link java.nio.file.FileStore#supportsFileAttributeView 893N/A * supportsFileAttributeView} method may be used to test if a specific {@link 893N/A * java.nio.file.FileStore FileStore} supports the storage of user-defined 893N/A * <p> Where dynamic access to file attributes is required, the {@link 3471N/A * java.nio.file.Files#getAttribute getAttribute} method may be used to read 1319N/A * the attribute value. The attribute value is returned as a byte array (byte[]). 3471N/A * The {@link java.nio.file.Files#setAttribute setAttribute} method may be used 1319N/A * to write the value of a user-defined attribute from a buffer (as if by 1319N/A * invoking the {@link #write write} method), or byte array (byte[]). 893N/A * Returns the name of this attribute view. Attribute views of this type 1319N/A * have the name {@code "user"}. 893N/A * Returns a list containing the names of the user-defined attributes. 893N/A * @return An unmodifiable list continaing the names of the file's 893N/A * If an I/O error occurs 893N/A * @throws SecurityException 893N/A * In the case of the default provider, a security manager is 893N/A * installed, and it denies {@link 893N/A * RuntimePermission}<tt>("accessUserDefinedAttributes")</tt> 893N/A * or its {@link SecurityManager#checkRead(String) checkRead} method 893N/A * denies read access to the file. 893N/A * Returns the size of the value of a user-defined attribute. 893N/A * @return The size of the attribute value, in bytes. 893N/A * @throws ArithmeticException 893N/A * If the size of the attribute is larger than {@link Integer#MAX_VALUE} 893N/A * If an I/O error occurs 893N/A * @throws SecurityException 893N/A * In the case of the default provider, a security manager is 893N/A * installed, and it denies {@link 893N/A * RuntimePermission}<tt>("accessUserDefinedAttributes")</tt> 893N/A * or its {@link SecurityManager#checkRead(String) checkRead} method 893N/A * denies read access to the file. 893N/A * Read the value of a user-defined attribute into a buffer. 893N/A * <p> This method reads the value of the attribute into the given buffer 893N/A * as a sequence of bytes, failing if the number of bytes remaining in 893N/A * the buffer is insufficient to read the complete attribute value. The 893N/A * number of bytes transferred into the buffer is {@code n}, where {@code n} 893N/A * is the size of the attribute value. The first byte in the sequence is at 893N/A * index {@code p} and the last byte is at index {@code p + n - 1}, where 893N/A * {@code p} is the buffer's position. Upon return the buffer's position 893N/A * will be equal to {@code p + n}; its limit will not have changed. 893N/A * <p> <b>Usage Example:</b> 893N/A * Suppose we want to read a file's MIME type that is stored as a user-defined 893N/A * attribute with the name "{@code user.mimetype}". 3471N/A * UserDefinedFileAttributeView view = 3471N/A * Files.getFileAttributeView(path, UserDefinedFileAttributeView.class); 893N/A * String name = "user.mimetype"; 893N/A * ByteBuffer buf = ByteBuffer.allocate(view.size(name)); 893N/A * view.read(name, buf); 893N/A * String value = Charset.defaultCharset().decode(buf).toString(); 893N/A * The destination buffer 893N/A * @return The number of bytes read, possibly zero 893N/A * @throws IllegalArgumentException 893N/A * If the destination buffer is read-only 893N/A * If an I/O error occurs or there is insufficient space in the 893N/A * destination buffer for the attribute value 893N/A * @throws SecurityException 893N/A * In the case of the default provider, a security manager is 893N/A * installed, and it denies {@link 893N/A * RuntimePermission}<tt>("accessUserDefinedAttributes")</tt> 893N/A * or its {@link SecurityManager#checkRead(String) checkRead} method 893N/A * denies read access to the file. 893N/A * Writes the value of a user-defined attribute from a buffer. 893N/A * <p> This method writes the value of the attribute from a given buffer as 893N/A * a sequence of bytes. The size of the value to transfer is {@code r}, 893N/A * where {@code r} is the number of bytes remaining in the buffer, that is 893N/A * {@code src.remaining()}. The sequence of bytes is transferred from the 893N/A * buffer starting at index {@code p}, where {@code p} is the buffer's 893N/A * position. Upon return, the buffer's position will be equal to {@code 893N/A * p + n}, where {@code n} is the number of bytes transferred; its limit 893N/A * will not have changed. 893N/A * <p> If an attribute of the given name already exists then its value is 893N/A * replaced. If the attribute does not exist then it is created. If it 893N/A * implementation specific if a test to check for the existence of the 893N/A * attribute and the creation of attribute are atomic with repect to other 893N/A * file system activities. 893N/A * <p> Where there is insufficient space to store the attribute, or the 893N/A * attribute name or value exceed an implementation specific maximum size 893N/A * then an {@code IOException} is thrown. 893N/A * <p> <b>Usage Example:</b> 893N/A * Suppose we want to write a file's MIME type as a user-defined attribute: 3471N/A * UserDefinedFileAttributeView view = 3471N/A * FIles.getFileAttributeView(path, UserDefinedFileAttributeView.class); 893N/A * view.write("user.mimetype", Charset.defaultCharset().encode("text/html")); 893N/A * The buffer containing the attribute value 893N/A * @return The number of bytes written, possibly zero 893N/A * If an I/O error occurs 893N/A * @throws SecurityException 893N/A * In the case of the default provider, a security manager is 893N/A * installed, and it denies {@link 893N/A * RuntimePermission}<tt>("accessUserDefinedAttributes")</tt> 893N/A * or its {@link SecurityManager#checkWrite(String) checkWrite} 893N/A * method denies write access to the file. 893N/A * Deletes a user-defined attribute. 893N/A * If an I/O error occurs or the attribute does not exist 893N/A * @throws SecurityException 893N/A * In the case of the default provider, a security manager is 893N/A * installed, and it denies {@link 893N/A * RuntimePermission}<tt>("accessUserDefinedAttributes")</tt> 893N/A * or its {@link SecurityManager#checkWrite(String) checkWrite} 893N/A * method denies write access to the file.