< prev index next >
src/java.base/share/classes/jdk/internal/module/ModuleReferences.java
Print this page
*** 23,33 ****
* questions.
*/
package jdk.internal.module;
- import java.io.File;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.lang.module.ModuleReader;
--- 23,32 ----
*** 48,58 ****
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipFile;
import jdk.internal.jmod.JmodFile;
- import jdk.internal.loader.ResourceHelper;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.module.ModuleHashes.HashSupplier;
import jdk.internal.util.jar.VersionedStream;
import sun.net.www.ParseUtil;
--- 47,56 ----
*** 76,85 ****
--- 74,84 ----
HashSupplier hasher) {
ModuleReference mref = new ModuleReferenceImpl(attrs.descriptor(),
uri,
supplier,
null,
+ attrs.target(),
attrs.recordedHashes(),
hasher,
attrs.moduleResolution());
if (patcher != null)
mref = patcher.patchIfNeeded(mref);
*** 240,259 ****
this.jf = newJarFile(path);
this.uri = uri;
}
private JarEntry getEntry(String name) {
! JarEntry entry = jf.getJarEntry(Objects.requireNonNull(name));
! return (entry == null || entry.isDirectory()) ? null : entry;
}
@Override
Optional<URI> implFind(String name) throws IOException {
JarEntry je = getEntry(name);
if (je != null) {
if (jf.isMultiRelease())
name = SharedSecrets.javaUtilJarAccess().getRealName(jf, je);
String encodedPath = ParseUtil.encodePath(name, false);
String uris = "jar:" + uri + "!/" + encodedPath;
return Optional.of(URI.create(uris));
} else {
return Optional.empty();
--- 239,259 ----
this.jf = newJarFile(path);
this.uri = uri;
}
private JarEntry getEntry(String name) {
! return jf.getJarEntry(Objects.requireNonNull(name));
}
@Override
Optional<URI> implFind(String name) throws IOException {
JarEntry je = getEntry(name);
if (je != null) {
if (jf.isMultiRelease())
name = SharedSecrets.javaUtilJarAccess().getRealName(jf, je);
+ if (je.isDirectory() && !name.endsWith("/"))
+ name += "/";
String encodedPath = ParseUtil.encodePath(name, false);
String uris = "jar:" + uri + "!/" + encodedPath;
return Optional.of(URI.create(uris));
} else {
return Optional.empty();
*** 272,282 ****
@Override
Stream<String> implList() throws IOException {
// take snapshot to avoid async close
List<String> names = VersionedStream.stream(jf)
- .filter(e -> !e.isDirectory())
.map(JarEntry::getName)
.collect(Collectors.toList());
return names.stream();
}
--- 272,281 ----
*** 314,323 ****
--- 313,324 ----
@Override
Optional<URI> implFind(String name) {
JmodFile.Entry je = getEntry(name);
if (je != null) {
+ if (je.isDirectory() && !name.endsWith("/"))
+ name += "/";
String encodedPath = ParseUtil.encodePath(name, false);
String uris = "jmod:" + uri + "!/" + encodedPath;
return Optional.of(URI.create(uris));
} else {
return Optional.empty();
*** 374,403 ****
*/
private void ensureOpen() throws IOException {
if (closed) throw new IOException("ModuleReader is closed");
}
- /**
- * Returns a Path to access the given resource. Returns null if the
- * resource name does not convert to a file path that locates a regular
- * file in the module.
- */
- private Path toFilePath(String name) {
- Path path = ResourceHelper.toFilePath(name);
- if (path != null) {
- Path file = dir.resolve(path);
- if (Files.isRegularFile(file)) {
- return file;
- }
- }
- return null;
- }
-
@Override
public Optional<URI> find(String name) throws IOException {
ensureOpen();
! Path path = toFilePath(name);
if (path != null) {
try {
return Optional.of(path.toUri());
} catch (IOError e) {
throw (IOException) e.getCause();
--- 375,388 ----
*/
private void ensureOpen() throws IOException {
if (closed) throw new IOException("ModuleReader is closed");
}
@Override
public Optional<URI> find(String name) throws IOException {
ensureOpen();
! Path path = Resources.toFilePath(dir, name);
if (path != null) {
try {
return Optional.of(path.toUri());
} catch (IOError e) {
throw (IOException) e.getCause();
*** 408,445 ****
}
@Override
public Optional<InputStream> open(String name) throws IOException {
ensureOpen();
! Path path = toFilePath(name);
if (path != null) {
return Optional.of(Files.newInputStream(path));
} else {
return Optional.empty();
}
}
@Override
public Optional<ByteBuffer> read(String name) throws IOException {
ensureOpen();
! Path path = toFilePath(name);
if (path != null) {
return Optional.of(ByteBuffer.wrap(Files.readAllBytes(path)));
} else {
return Optional.empty();
}
}
@Override
public Stream<String> list() throws IOException {
ensureOpen();
! // sym links not followed
! return Files.find(dir, Integer.MAX_VALUE,
! (path, attrs) -> attrs.isRegularFile())
! .map(f -> dir.relativize(f)
! .toString()
! .replace(File.separatorChar, '/'));
}
@Override
public void close() {
closed = true;
--- 393,427 ----
}
@Override
public Optional<InputStream> open(String name) throws IOException {
ensureOpen();
! Path path = Resources.toFilePath(dir, name);
if (path != null) {
return Optional.of(Files.newInputStream(path));
} else {
return Optional.empty();
}
}
@Override
public Optional<ByteBuffer> read(String name) throws IOException {
ensureOpen();
! Path path = Resources.toFilePath(dir, name);
if (path != null) {
return Optional.of(ByteBuffer.wrap(Files.readAllBytes(path)));
} else {
return Optional.empty();
}
}
@Override
public Stream<String> list() throws IOException {
ensureOpen();
! return Files.walk(dir, Integer.MAX_VALUE)
! .map(f -> Resources.toResourceName(dir, f))
! .filter(s -> s.length() > 0);
}
@Override
public void close() {
closed = true;
< prev index next >