APIdia Launch Partner
Top Description Constructors Methods
jdk.internal.module

public final Class Resources

extends Object
Class Inheritance
Imports
java.io.File, .IOException, java.nio.file.FileSystem, .Files, .InvalidPathException, .NoSuchFileException, .Path, java.nio.file.attribute.BasicFileAttributes

A helper class to support working with resources in modules. Also provides support for translating resource names to file paths.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean
canEncapsulate(String name)

Return true if a resource can be encapsulated.

private static boolean
mayTranslate(String name, int off, int len)

Returns true if the element in a resource name is a candidate to translate to the element of a file path.

public static Path
toFilePath(Path dir, String name)

Returns a file path to a resource in a file tree.

public static String
toPackageName(String name)

Derive a package name for a resource.

public static String
toResourceName(Path dir, Path file)

Returns a resource name corresponding to the relative file path between dir and file.

private static Path
toSafeFilePath(FileSystem fs, String name)

Map a resource name to a "safe" file path.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Resourcesback to summary
private Resources()

Method Detail

canEncapsulateback to summary
public static boolean canEncapsulate(String name)

Return true if a resource can be encapsulated. Resource with names ending in ".class" or "/" cannot be encapsulated. Resource names that map to a legal package name can be encapsulated.

mayTranslateback to summary
private static boolean mayTranslate(String name, int off, int len)

Returns true if the element in a resource name is a candidate to translate to the element of a file path.

toFilePathback to summary
public static Path toFilePath(Path dir, String name) throws IOException

Returns a file path to a resource in a file tree. If the resource name has a trailing "/" then the file path will locate a directory. Returns null if the resource does not map to a file in the tree file.

toPackageNameback to summary
public static String toPackageName(String name)

Derive a package name for a resource. The package name returned by this method may not be a legal package name. This method returns null if the resource name ends with a "/" (a directory) or the resource name does not contain a "/".

toResourceNameback to summary
public static String toResourceName(Path dir, Path file)

Returns a resource name corresponding to the relative file path between dir and file. If the file is a directory then the name will end with a "/", except the top-level directory where the empty string is returned.

toSafeFilePathback to summary
private static Path toSafeFilePath(FileSystem fs, String name)

Map a resource name to a "safe" file path. Returns null if the resource name cannot be converted into a "safe" file path. Resource names with empty elements, or elements that are "." or ".." are rejected, as are resource names that translates to a file path with a root component.