8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.internal.jrtfs; 27 28 import java.nio.file.attribute.*; 29 import java.io.IOException; 30 import java.util.LinkedHashMap; 31 import java.util.Map; 32 33 final class JrtFileAttributeView implements BasicFileAttributeView 34 { 35 private static enum AttrID { 36 size, 37 creationTime, 38 lastAccessTime, 39 lastModifiedTime, 40 isDirectory, 41 isRegularFile, 42 isSymbolicLink, 43 isOther, 44 fileKey, 45 compressedSize, 46 extension 47 }; 48 49 private final JrtPath path; 50 private final boolean isJrtView; 51 52 private JrtFileAttributeView(JrtPath path, boolean isJrtView) { 53 this.path = path; 54 this.isJrtView = isJrtView; 55 } 56 57 @SuppressWarnings("unchecked") // Cast to V 58 static <V extends FileAttributeView> V get(JrtPath path, Class<V> type) { 59 if (type == null) 60 throw new NullPointerException(); 61 if (type == BasicFileAttributeView.class) 62 return (V)new JrtFileAttributeView(path, false); 63 if (type == JrtFileAttributeView.class) 64 return (V)new JrtFileAttributeView(path, true); 65 return null; 66 } 67 68 static JrtFileAttributeView get(JrtPath path, String type) { 69 if (type == null) 70 throw new NullPointerException(); 71 if (type.equals("basic")) 72 return new JrtFileAttributeView(path, false); 73 if (type.equals("jjrt")) 74 return new JrtFileAttributeView(path, true); 75 return null; 76 } 77 78 @Override 79 public String name() { 80 return isJrtView ? "jjrt" : "basic"; 81 } 82 83 @Override 84 public JrtFileAttributes readAttributes() throws IOException 85 { 86 return path.getAttributes(); 87 } 88 89 @Override 90 public void setTimes(FileTime lastModifiedTime, 91 FileTime lastAccessTime, 92 FileTime createTime) 93 throws IOException 94 { 95 path.setTimes(lastModifiedTime, lastAccessTime, createTime); 96 } 97 98 void setAttribute(String attribute, Object value) 99 throws IOException 100 { 101 try { 102 if (AttrID.valueOf(attribute) == AttrID.lastModifiedTime) 103 setTimes ((FileTime)value, null, null); 104 if (AttrID.valueOf(attribute) == AttrID.lastAccessTime) 105 setTimes (null, (FileTime)value, null); 106 if (AttrID.valueOf(attribute) == AttrID.creationTime) | 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.internal.jrtfs; 27 28 import java.nio.file.LinkOption; 29 import java.nio.file.attribute.*; 30 import java.io.IOException; 31 import java.util.LinkedHashMap; 32 import java.util.Map; 33 34 final class JrtFileAttributeView implements BasicFileAttributeView 35 { 36 private static enum AttrID { 37 size, 38 creationTime, 39 lastAccessTime, 40 lastModifiedTime, 41 isDirectory, 42 isRegularFile, 43 isSymbolicLink, 44 isOther, 45 fileKey, 46 compressedSize, 47 extension 48 }; 49 50 private final JrtPath path; 51 private final boolean isJrtView; 52 private final LinkOption[] options; 53 54 private JrtFileAttributeView(JrtPath path, boolean isJrtView, LinkOption... options) { 55 this.path = path; 56 this.isJrtView = isJrtView; 57 this.options = options; 58 } 59 60 @SuppressWarnings("unchecked") // Cast to V 61 static <V extends FileAttributeView> V get(JrtPath path, Class<V> type, LinkOption... options) { 62 if (type == null) 63 throw new NullPointerException(); 64 if (type == BasicFileAttributeView.class) 65 return (V)new JrtFileAttributeView(path, false, options); 66 if (type == JrtFileAttributeView.class) 67 return (V)new JrtFileAttributeView(path, true, options); 68 return null; 69 } 70 71 static JrtFileAttributeView get(JrtPath path, String type, LinkOption... options) { 72 if (type == null) 73 throw new NullPointerException(); 74 if (type.equals("basic")) 75 return new JrtFileAttributeView(path, false, options); 76 if (type.equals("jjrt")) 77 return new JrtFileAttributeView(path, true, options); 78 return null; 79 } 80 81 @Override 82 public String name() { 83 return isJrtView ? "jjrt" : "basic"; 84 } 85 86 @Override 87 public JrtFileAttributes readAttributes() throws IOException 88 { 89 return path.getAttributes(options); 90 } 91 92 @Override 93 public void setTimes(FileTime lastModifiedTime, 94 FileTime lastAccessTime, 95 FileTime createTime) 96 throws IOException 97 { 98 path.setTimes(lastModifiedTime, lastAccessTime, createTime); 99 } 100 101 void setAttribute(String attribute, Object value) 102 throws IOException 103 { 104 try { 105 if (AttrID.valueOf(attribute) == AttrID.lastModifiedTime) 106 setTimes ((FileTime)value, null, null); 107 if (AttrID.valueOf(attribute) == AttrID.lastAccessTime) 108 setTimes (null, (FileTime)value, null); 109 if (AttrID.valueOf(attribute) == AttrID.creationTime) |