< prev index next >
jdk/src/java.base/share/classes/jdk/internal/jmod/JmodFile.java
Print this page
*** 28,37 ****
--- 28,42 ----
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
+ import java.util.Arrays;
+ import java.util.HashMap;
+ import java.util.Map;
+ import java.util.function.Function;
+ import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
/**
*** 66,81 ****
/**
* JMOD sections
*/
public static enum Section {
- NATIVE_LIBS("native"),
- NATIVE_CMDS("bin"),
CLASSES("classes"),
CONFIG("conf"),
HEADER_FILES("include"),
! MAN_PAGES("man");
private final String jmodDir;
private Section(String jmodDir) {
this.jmodDir = jmodDir;
}
--- 71,87 ----
/**
* JMOD sections
*/
public static enum Section {
CLASSES("classes"),
CONFIG("conf"),
HEADER_FILES("include"),
! LEGAL_NOTICES("legal"),
! MAN_PAGES("man"),
! NATIVE_LIBS("native"),
! NATIVE_CMDS("bin");
private final String jmodDir;
private Section(String jmodDir) {
this.jmodDir = jmodDir;
}
*** 83,93 ****
/**
* Returns the directory name in the JMOD file corresponding to
* this section
*/
public String jmodDir() { return jmodDir; }
-
}
/**
* JMOD file entry.
*
--- 89,98 ----
*** 105,115 ****
if (i <= 1) {
throw new RuntimeException("invalid jmod entry: " + name);
}
this.zipEntry = e;
! this.section = section(name);
this.name = name.substring(i+1);
}
/**
* Returns the section of this entry.
--- 110,120 ----
if (i <= 1) {
throw new RuntimeException("invalid jmod entry: " + name);
}
this.zipEntry = e;
! this.section = section(name.substring(0, i));
this.name = name.substring(i+1);
}
/**
* Returns the section of this entry.
*** 139,168 ****
@Override
public String toString() {
return section.jmodDir() + "/" + name;
}
static Section section(String name) {
! int i = name.indexOf('/');
! String s = name.substring(0, i);
! switch (s) {
! case "native":
! return Section.NATIVE_LIBS;
! case "bin":
! return Section.NATIVE_CMDS;
! case "classes":
! return Section.CLASSES;
! case "conf":
! return Section.CONFIG;
! case "include":
! return Section.HEADER_FILES;
! case "man":
! return Section.MAN_PAGES;
! default:
! throw new IllegalArgumentException("invalid section: " + s);
}
}
}
private final Path file;
private final ZipFile zipfile;
--- 144,168 ----
@Override
public String toString() {
return section.jmodDir() + "/" + name;
}
+ /*
+ * A map from the jmodDir name to Section
+ */
+ static final Map<String, Section> NAME_TO_SECTION =
+ Arrays.stream(Section.values())
+ .collect(Collectors.toMap(Section::jmodDir, Function.identity()));
+
static Section section(String name) {
! if (!NAME_TO_SECTION.containsKey(name)) {
! throw new IllegalArgumentException("invalid section: " + name);
!
}
+ return NAME_TO_SECTION.get(name);
}
+
}
private final Path file;
private final ZipFile zipfile;
< prev index next >