< prev index next >

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

Print this page

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

102 
103         @Override
104         public boolean isLink() {
105             return link != null;
106         }
107 
108         @Override
109         public PathNode resolveLink(boolean recursive) {
110             if (link == null)
111                 return this;
112             return recursive && link.isLink() ? link.resolveLink(true) : link;
113         }
114 
115         byte[] getContent() throws IOException {
116             if (!getFileAttributes().isRegularFile())
117                 throw new FileSystemException(getName() + " is not file");
118             return Files.readAllBytes(path);
119         }
120 
121         @Override
122         public List<Node> getChildren() {
123             if (!isDirectory())
124                 throw new IllegalArgumentException("not a directory: " + getNameString());
125             if (children == null) {
126                 List<Node> list = new ArrayList<>();
127                 try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
128                     for (Path p : stream) {
129                         p = explodedModulesDir.relativize(p);
130                         String pName = MODULES + nativeSlashToFrontSlash(p.toString());
131                         Node node = findNode(pName);
132                         if (node != null) {  // findNode may choose to hide certain files!
133                             list.add(node);
134                         }
135                     }
136                 } catch (IOException x) {
137                     return null;
138                 }
139                 children = list;
140             }
141             return children;
142         }
143 
144         @Override
145         public long size() {
146             try {
147                 return isDirectory() ? 0 : Files.size(path);
148             } catch (IOException ex) {
149                 throw new UncheckedIOException(ex);
150             }
151         }
152     }
153 
154     @Override
155     public void close() throws IOException {
156         nodes.clear();
157     }
158 
159     @Override
160     public byte[] getResource(Node node) throws IOException {
161         return ((PathNode)node).getContent();

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

102 
103         @Override
104         public boolean isLink() {
105             return link != null;
106         }
107 
108         @Override
109         public PathNode resolveLink(boolean recursive) {
110             if (link == null)
111                 return this;
112             return recursive && link.isLink() ? link.resolveLink(true) : link;
113         }
114 
115         byte[] getContent() throws IOException {
116             if (!getFileAttributes().isRegularFile())
117                 throw new FileSystemException(getName() + " is not file");
118             return Files.readAllBytes(path);
119         }
120 
121         @Override
122         public Stream<String> getChildNames() {
123             if (!isDirectory())
124                 throw new IllegalArgumentException("not a directory: " + getName());
125             if (children == null) {
126                 List<Node> list = new ArrayList<>();
127                 try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
128                     for (Path p : stream) {
129                         p = explodedModulesDir.relativize(p);
130                         String pName = MODULES + nativeSlashToFrontSlash(p.toString());
131                         Node node = findNode(pName);
132                         if (node != null) {  // findNode may choose to hide certain files!
133                             list.add(node);
134                         }
135                     }
136                 } catch (IOException x) {
137                     return null;
138                 }
139                 children = list;
140             }
141             return children.stream().map(Node::getName);
142         }
143 
144         @Override
145         public long size() {
146             try {
147                 return isDirectory() ? 0 : Files.size(path);
148             } catch (IOException ex) {
149                 throw new UncheckedIOException(ex);
150             }
151         }
152     }
153 
154     @Override
155     public void close() throws IOException {
156         nodes.clear();
157     }
158 
159     @Override
160     public byte[] getResource(Node node) throws IOException {
161         return ((PathNode)node).getContent();
< prev index next >