< prev index next >

src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java

Print this page

  1 /*
  2  * Copyright (c) 2014, 2022, 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

 41 import java.nio.file.FileSystem;
 42 import java.nio.file.FileSystemException;
 43 import java.nio.file.InvalidPathException;
 44 import java.nio.file.LinkOption;
 45 import java.nio.file.NoSuchFileException;
 46 import java.nio.file.NotDirectoryException;
 47 import java.nio.file.OpenOption;
 48 import java.nio.file.Path;
 49 import java.nio.file.PathMatcher;
 50 import java.nio.file.ReadOnlyFileSystemException;
 51 import java.nio.file.StandardOpenOption;
 52 import java.nio.file.WatchService;
 53 import java.nio.file.attribute.FileAttribute;
 54 import java.nio.file.attribute.FileTime;
 55 import java.nio.file.attribute.UserPrincipalLookupService;
 56 import java.nio.file.spi.FileSystemProvider;
 57 import java.util.Arrays;
 58 import java.util.Collections;
 59 import java.util.HashSet;
 60 import java.util.Iterator;
 61 import java.util.Map;
 62 import java.util.Objects;
 63 import java.util.Set;
 64 import java.util.regex.Pattern;
 65 import jdk.internal.jimage.ImageReader.Node;

 66 
 67 /**
 68  * jrt file system implementation built on System jimage files.
 69  *
 70  * @implNote This class needs to maintain JDK 8 source compatibility.
 71  *
 72  * It is used internally in the JDK to implement jimage/jrtfs access,
 73  * but also compiled and delivered as part of the jrtfs.jar to support access
 74  * to the jimage file provided by the shipped JDK by tools running on JDK 8.
 75  */
 76 class JrtFileSystem extends FileSystem {
 77 
 78     private final JrtFileSystemProvider provider;
 79     private final JrtPath rootPath = new JrtPath(this, "/");
 80     private volatile boolean isOpen;
 81     private volatile boolean isClosable;
 82     private SystemImage image;
 83 
 84     JrtFileSystem(JrtFileSystemProvider provider, Map<String, ?> env)
 85             throws IOException
 86     {






 87         this.provider = provider;
 88         this.image = SystemImage.open();  // open image file
 89         this.isOpen = true;
 90         this.isClosable = env != null;















 91     }
 92 
 93     // FileSystem method implementations
 94     @Override
 95     public boolean isOpen() {
 96         return isOpen;
 97     }
 98 
 99     @Override
100     public void close() throws IOException {
101         if (!isClosable)
102             throw new UnsupportedOperationException();
103         cleanup();
104     }
105 
106     @Override
107     public FileSystemProvider provider() {
108         return provider;
109     }
110 

  1 /*
  2  * Copyright (c) 2014, 2025, 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

 41 import java.nio.file.FileSystem;
 42 import java.nio.file.FileSystemException;
 43 import java.nio.file.InvalidPathException;
 44 import java.nio.file.LinkOption;
 45 import java.nio.file.NoSuchFileException;
 46 import java.nio.file.NotDirectoryException;
 47 import java.nio.file.OpenOption;
 48 import java.nio.file.Path;
 49 import java.nio.file.PathMatcher;
 50 import java.nio.file.ReadOnlyFileSystemException;
 51 import java.nio.file.StandardOpenOption;
 52 import java.nio.file.WatchService;
 53 import java.nio.file.attribute.FileAttribute;
 54 import java.nio.file.attribute.FileTime;
 55 import java.nio.file.attribute.UserPrincipalLookupService;
 56 import java.nio.file.spi.FileSystemProvider;
 57 import java.util.Arrays;
 58 import java.util.Collections;
 59 import java.util.HashSet;
 60 import java.util.Iterator;

 61 import java.util.Objects;
 62 import java.util.Set;
 63 import java.util.regex.Pattern;
 64 import jdk.internal.jimage.ImageReader.Node;
 65 import jdk.internal.jimage.PreviewMode;
 66 
 67 /**
 68  * jrt file system implementation built on System jimage files.
 69  *
 70  * @implNote This class needs to maintain JDK 8 source compatibility.
 71  *
 72  * It is used internally in the JDK to implement jimage/jrtfs access,
 73  * but also compiled and delivered as part of the jrtfs.jar to support access
 74  * to the jimage file provided by the shipped JDK by tools running on JDK 8.
 75  */
 76 class JrtFileSystem extends FileSystem {
 77 
 78     private final JrtFileSystemProvider provider;
 79     private final JrtPath rootPath = new JrtPath(this, "/");
 80     private volatile boolean isOpen;
 81     private volatile boolean isClosable;
 82     private SystemImage image;
 83 
 84     /**
 85      * Special constructor for the singleton system jrt file system. This creates
 86      * a non-closable instance, and should only be called once by {@link
 87      * JrtFileSystemProvider}.
 88      *
 89      * @param provider the provider opening the file system.
 90      */
 91     JrtFileSystem(JrtFileSystemProvider provider)
 92             throws IOException {
 93         this.provider = provider;
 94         this.image = SystemImage.open(PreviewMode.FOR_RUNTIME);  // open image file
 95         this.isOpen = true;
 96         // Only the system singleton jrt file system is "unclosable".
 97         this.isClosable = false;
 98     }
 99 
100     /**
101      * Creates a new, non-system, instance of the jrt file system.
102      *
103      * @param provider the provider opening the file system.
104      * @param mode controls whether preview resources are visible.
105      */
106     JrtFileSystem(JrtFileSystemProvider provider, PreviewMode mode)
107             throws IOException {
108         this.provider = provider;
109         this.image = SystemImage.open(mode);  // open image file
110         this.isOpen = true;
111         this.isClosable = true;
112     }
113 
114     // FileSystem method implementations
115     @Override
116     public boolean isOpen() {
117         return isOpen;
118     }
119 
120     @Override
121     public void close() throws IOException {
122         if (!isClosable)
123             throw new UnsupportedOperationException();
124         cleanup();
125     }
126 
127     @Override
128     public FileSystemProvider provider() {
129         return provider;
130     }
131 
< prev index next >