jdk/src/java.base/share/classes/jdk/internal/jrtfs/AbstractJrtFileAttributes.java
changeset 37407 9a0927683faa
parent 37406 ffe907153695
parent 37396 8d78fb40648d
child 37408 15d3d0e61f2e
equal deleted inserted replaced
37406:ffe907153695 37407:9a0927683faa
     1 /*
       
     2  * Copyright (c) 2015, 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 package jdk.internal.jrtfs;
       
    26 
       
    27 import java.nio.file.attribute.BasicFileAttributes;
       
    28 import java.util.Formatter;
       
    29 
       
    30 /**
       
    31  * Base class for file attributes supported by jrt file systems.
       
    32  *
       
    33  * @implNote This class needs to maintain JDK 8 source compatibility.
       
    34  *
       
    35  * It is used internally in the JDK to implement jimage/jrtfs access,
       
    36  * but also compiled and delivered as part of the jrtfs.jar to support access
       
    37  * to the jimage file provided by the shipped JDK by tools running on JDK 8.
       
    38  */
       
    39 public abstract class AbstractJrtFileAttributes implements BasicFileAttributes {
       
    40 
       
    41     // jrt fs specific attributes
       
    42     /**
       
    43      * Compressed resource file. If not available or not applicable, 0L is
       
    44      * returned.
       
    45      *
       
    46      * @return the compressed resource size for compressed resources.
       
    47      */
       
    48     public abstract long compressedSize();
       
    49 
       
    50     /**
       
    51      * "file" extension of a file resource.
       
    52      *
       
    53      * @return extension string for the file resource
       
    54      */
       
    55     public abstract String extension();
       
    56 
       
    57     @Override
       
    58     public final String toString() {
       
    59         StringBuilder sb = new StringBuilder(1024);
       
    60         try (Formatter fm = new Formatter(sb)) {
       
    61             if (creationTime() != null) {
       
    62                 fm.format("    creationTime    : %tc%n", creationTime().toMillis());
       
    63             } else {
       
    64                 fm.format("    creationTime    : null%n");
       
    65             }
       
    66 
       
    67             if (lastAccessTime() != null) {
       
    68                 fm.format("    lastAccessTime  : %tc%n", lastAccessTime().toMillis());
       
    69             } else {
       
    70                 fm.format("    lastAccessTime  : null%n");
       
    71             }
       
    72             fm.format("    lastModifiedTime: %tc%n", lastModifiedTime().toMillis());
       
    73             fm.format("    isRegularFile   : %b%n", isRegularFile());
       
    74             fm.format("    isDirectory     : %b%n", isDirectory());
       
    75             fm.format("    isSymbolicLink  : %b%n", isSymbolicLink());
       
    76             fm.format("    isOther         : %b%n", isOther());
       
    77             fm.format("    fileKey         : %s%n", fileKey());
       
    78             fm.format("    size            : %d%n", size());
       
    79             fm.format("    compressedSize  : %d%n", compressedSize());
       
    80             fm.format("    extension       : %s%n", extension());
       
    81         }
       
    82         return sb.toString();
       
    83     }
       
    84 }