Path: blob/master/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileAttributes.java
41159 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package jdk.internal.jrtfs;2526import java.nio.file.attribute.BasicFileAttributes;27import java.nio.file.attribute.FileTime;28import java.util.Formatter;29import jdk.internal.jimage.ImageReader.Node;3031/**32* File attributes implementation for jrt image file system.33*34* @implNote This class needs to maintain JDK 8 source compatibility.35*36* It is used internally in the JDK to implement jimage/jrtfs access,37* but also compiled and delivered as part of the jrtfs.jar to support access38* to the jimage file provided by the shipped JDK by tools running on JDK 8.39*/40final class JrtFileAttributes implements BasicFileAttributes {4142private final Node node;4344JrtFileAttributes(Node node) {45this.node = node;46}4748///////// basic attributes ///////////49@Override50public FileTime creationTime() {51return node.creationTime();52}5354@Override55public boolean isDirectory() {56return node.isDirectory();57}5859@Override60public boolean isOther() {61return false;62}6364@Override65public boolean isRegularFile() {66return !isDirectory();67}6869@Override70public FileTime lastAccessTime() {71return node.lastAccessTime();72}7374@Override75public FileTime lastModifiedTime() {76return node.lastModifiedTime();77}7879@Override80public long size() {81return node.size();82}8384@Override85public boolean isSymbolicLink() {86return node.isLink();87}8889@Override90public Object fileKey() {91return node.resolveLink(true);92}9394///////// jrtfs specific attributes ///////////95/**96* Compressed resource file. If not available or not applicable, 0L is97* returned.98*99* @return the compressed resource size for compressed resources.100*/101public long compressedSize() {102return node.compressedSize();103}104105/**106* "file" extension of a file resource.107*108* @return extension string for the file resource109*/110public String extension() {111return node.extension();112}113114@Override115public final String toString() {116StringBuilder sb = new StringBuilder(1024);117try (Formatter fm = new Formatter(sb)) {118if (creationTime() != null) {119fm.format(" creationTime : %tc%n", creationTime().toMillis());120} else {121fm.format(" creationTime : null%n");122}123if (lastAccessTime() != null) {124fm.format(" lastAccessTime : %tc%n", lastAccessTime().toMillis());125} else {126fm.format(" lastAccessTime : null%n");127}128fm.format(" lastModifiedTime: %tc%n", lastModifiedTime().toMillis());129fm.format(" isRegularFile : %b%n", isRegularFile());130fm.format(" isDirectory : %b%n", isDirectory());131fm.format(" isSymbolicLink : %b%n", isSymbolicLink());132fm.format(" isOther : %b%n", isOther());133fm.format(" fileKey : %s%n", fileKey());134fm.format(" size : %d%n", size());135fm.format(" compressedSize : %d%n", compressedSize());136fm.format(" extension : %s%n", extension());137}138return sb.toString();139}140}141142143