1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 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.BasicFileAttributes; 29 import java.nio.file.attribute.FileTime; 30 import java.util.Formatter; 31 import jdk.internal.jimage.ImageReader.Node; 32 33 final class JrtFileAttributes implements BasicFileAttributes 34 { 35 private final Node node; 36 37 JrtFileAttributes(Node node) { 38 this.node = node; 39 } 40 41 ///////// basic attributes /////////// 42 @Override 43 public FileTime creationTime() { 44 return node.creationTime(); 45 } 46 47 @Override 48 public boolean isDirectory() { 49 return node.isDirectory(); 50 } 51 52 @Override 53 public boolean isOther() { 54 return false; 55 } 56 57 @Override 58 public boolean isRegularFile() { 59 return !isDirectory(); 60 } 61 62 @Override 63 public FileTime lastAccessTime() { 64 return node.lastAccessTime(); 65 } 66 67 @Override 68 public FileTime lastModifiedTime() { 69 return node.lastModifiedTime(); 70 } 71 72 @Override 73 public long size() { 74 return node.size(); 75 } 76 77 @Override 78 public boolean isSymbolicLink() { 79 return false; 80 } 81 82 @Override 83 public Object fileKey() { 84 return null; 85 } 86 87 ///////// jrt entry attributes /////////// 88 public long compressedSize() { 89 return node.compressedSize(); 90 } 91 92 public String extension() { 93 return node.extension(); 94 } 95 96 @Override 97 public String toString() { 98 StringBuilder sb = new StringBuilder(1024); 99 try (Formatter fm = new Formatter(sb)) { 100 if (creationTime() != null) 101 fm.format(" creationTime : %tc%n", creationTime().toMillis()); 102 else 103 fm.format(" creationTime : null%n"); 104 105 if (lastAccessTime() != null) 106 fm.format(" lastAccessTime : %tc%n", lastAccessTime().toMillis()); 107 else 108 fm.format(" lastAccessTime : null%n"); 109 fm.format(" lastModifiedTime: %tc%n", lastModifiedTime().toMillis()); 110 fm.format(" isRegularFile : %b%n", isRegularFile()); 111 fm.format(" isDirectory : %b%n", isDirectory()); 112 fm.format(" isSymbolicLink : %b%n", isSymbolicLink()); 113 fm.format(" isOther : %b%n", isOther()); 114 fm.format(" fileKey : %s%n", fileKey()); 115 fm.format(" size : %d%n", size()); 116 fm.format(" compressedSize : %d%n", compressedSize()); 117 fm.format(" extension : %s%n", extension()); 118 } 119 return sb.toString(); 120 } 121 }