25 26 package org.openjdk.jigsaw; 27 28 import java.io.*; 29 import java.lang.module.*; 30 import java.util.Objects; 31 32 33 /** 34 * <p> A collection of module-info files together with associated module files, 35 * suitable for download and installation. </p> 36 */ 37 38 public abstract class Repository 39 extends LocatableCatalog 40 { 41 42 /** 43 * <p> The type of a module file <p> 44 */ 45 public static enum ModuleType { // ## Should be ModuleFileType 46 /** 47 * A module type that is a java module file 48 */ 49 JMOD("jmod"), 50 51 /** 52 * A module type that is a modular jar file 53 */ 54 JAR("jar"); 55 56 private final String extension; 57 58 ModuleType(String suffix) { 59 this.extension = suffix; 60 } 61 62 public String getFileNameExtension() { 63 return extension; 64 } 65 66 public String getFileNameSuffix() { 67 return "." + getFileNameExtension(); 68 } 69 70 /** 71 * Get the module type from the file name extension. 72 * 73 * @param extension the file name extension. 74 * @return the module type. 75 * @throws IllegalArgumentException if {@code extension} 76 * has no corresponding module type. 77 * @throws NullPointerException if {@code extension} is null 78 */ 79 public static ModuleType fromFileNameExtension(String extension) { 80 Objects.requireNonNull(extension, "Extension is null"); 81 for (ModuleType type: values()) { 82 if (type.extension.equals(extension)) { 83 return type; 84 } 85 } 86 87 throw new IllegalArgumentException( 88 "No module type for the file name extension " + extension); 89 } 90 91 } 92 93 /** 94 * <p> Size and type information about a yet-to-be-installed module </p> 95 */ 96 public static class ModuleMetaData { // ## Should be ModuleFileMetaData 97 98 private final ModuleType type; 99 100 /** 101 * The type of the module. 102 */ 103 public ModuleType getType() { 104 return type; 105 } 106 107 private final long csize; 108 109 /** 110 * The module's download size, in bytes. 111 */ 112 public long getDownloadSize() { return csize; } 113 114 private final long usize; 115 116 /** 117 * The module's installed size, in bytes. 118 * 119 * <p> The number of bytes required to install a module may be less 120 * than the value returned by this method, but it will never be 121 * greater. </p> 122 */ 123 public long getInstallSize() { return usize; } 124 125 ModuleMetaData(ModuleType t, long cs, long us) { 126 type = t; 127 csize = cs; 128 usize = us; 129 } 130 131 } 132 133 /** 134 * Fetch the meta data for a given module. Such meta data will consist of 135 * of the module type and size information. 136 * 137 * @param mid 138 * The {@linkplain java.lang.module.ModuleId id} of the 139 * requested module 140 * 141 * @throws IllegalArgumentException 142 * If the named module is not present in this repository 143 */ 144 public abstract ModuleMetaData fetchMetaData(ModuleId mid) throws IOException; 145 146 /** 147 * Fetch the bytes for a given module. 148 * 149 * @param mid 150 * The {@linkplain java.lang.module.ModuleId id} of the 151 * requested module 152 * 153 * @throws IllegalArgumentException 154 * If the named module is not present in this repository 155 * @throws IOException 156 * If there is an error fetching the module. 157 */ 158 public abstract InputStream fetch(ModuleId mid) throws IOException; 159 160 } | 25 26 package org.openjdk.jigsaw; 27 28 import java.io.*; 29 import java.lang.module.*; 30 import java.util.Objects; 31 32 33 /** 34 * <p> A collection of module-info files together with associated module files, 35 * suitable for download and installation. </p> 36 */ 37 38 public abstract class Repository 39 extends LocatableCatalog 40 { 41 42 /** 43 * <p> The type of a module file <p> 44 */ 45 public static enum ModuleFileType { 46 /** 47 * A module type that is a java module file 48 */ 49 JMOD("jmod"), 50 51 /** 52 * A module type that is a modular jar file 53 */ 54 JAR("jar"); 55 56 private final String extension; 57 58 ModuleFileType(String suffix) { 59 this.extension = suffix; 60 } 61 62 public String getFileNameExtension() { 63 return extension; 64 } 65 66 public String getFileNameSuffix() { 67 return "." + getFileNameExtension(); 68 } 69 70 /** 71 * Get the module type from the file name extension. 72 * 73 * @param extension the file name extension. 74 * @return the module type. 75 * @throws IllegalArgumentException if {@code extension} 76 * has no corresponding module type. 77 * @throws NullPointerException if {@code extension} is null 78 */ 79 public static ModuleFileType fromFileNameExtension(String extension) { 80 Objects.requireNonNull(extension, "Extension is null"); 81 for (ModuleFileType type: values()) { 82 if (type.extension.equals(extension)) { 83 return type; 84 } 85 } 86 87 throw new IllegalArgumentException( 88 "No module type for the file name extension " + extension); 89 } 90 91 } 92 93 /** 94 * <p> Size and type information about a yet-to-be-installed module </p> 95 */ 96 public static class ModuleFileMetaData { 97 98 private final ModuleFileType type; 99 100 /** 101 * The type of the module-file.. 102 */ 103 public ModuleFileType getType() { 104 return type; 105 } 106 107 private ModuleArchitecture modArch; 108 109 /** 110 * The Architecture of a module-file 111 */ 112 public ModuleArchitecture architecture() { 113 return modArch; 114 } 115 116 private final long csize; 117 118 /** 119 * The module's download size, in bytes. 120 */ 121 public long getDownloadSize() { return csize; } 122 123 private final long usize; 124 125 /** 126 * The module's installed size, in bytes. 127 * 128 * <p> The number of bytes required to install a module may be less 129 * than the value returned by this method, but it will never be 130 * greater. </p> 131 */ 132 public long getInstallSize() { return usize; } 133 134 ModuleFileMetaData(ModuleFileType t, ModuleArchitecture ma, 135 long cs, long us) { 136 type = t; 137 modArch = ma; 138 csize = cs; 139 usize = us; 140 } 141 142 } 143 144 /** 145 * Fetch the meta data for a given module. Such meta data will consist of 146 * of the module type and size information. 147 * 148 * @param mid 149 * The {@linkplain java.lang.module.ModuleId id} of the 150 * requested module 151 * 152 * @throws IllegalArgumentException 153 * If the named module is not present in this repository 154 */ 155 public abstract ModuleFileMetaData fetchMetaData(ModuleId mid) 156 throws IOException; 157 158 /** 159 * Fetch the bytes for a given module. 160 * 161 * @param mid 162 * The {@linkplain java.lang.module.ModuleId id} of the 163 * requested module 164 * 165 * @throws IllegalArgumentException 166 * If the named module is not present in this repository 167 * @throws IOException 168 * If there is an error fetching the module. 169 */ 170 public abstract InputStream fetch(ModuleId mid) 171 throws IOException; 172 173 } |