当前位置: 首页>>代码示例>>Java>>正文


Java ModuleReference.open方法代码示例

本文整理汇总了Java中java.lang.module.ModuleReference.open方法的典型用法代码示例。如果您正苦于以下问题:Java ModuleReference.open方法的具体用法?Java ModuleReference.open怎么用?Java ModuleReference.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.module.ModuleReference的用法示例。


在下文中一共展示了ModuleReference.open方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAutomaticModuleNameAttributeAvailable

import java.lang.module.ModuleReference; //导入方法依赖的package包/类
boolean isAutomaticModuleNameAttributeAvailable(ModuleReference moduleReference) {
  try (var moduleReader = moduleReference.open()) {
    var manifestString =
        moduleReader
            .read("META-INF/MANIFEST.MF")
            .map(StandardCharsets.UTF_8::decode)
            .map(Object::toString)
            .orElse("");
    if (manifestString.contains("Automatic-Module-Name")) {
      return true;
    }
  } catch (Exception e) {
    debug("reading manifest failed: {0}", e);
  }
  return false;
}
 
开发者ID:jodastephen,项目名称:jpms-module-names,代码行数:17,代码来源:Generator.java

示例2: moduleReaderFor

import java.lang.module.ModuleReference; //导入方法依赖的package包/类
/**
 * Returns the ModuleReader for the given module, creating it if needed
 */
private ModuleReader moduleReaderFor(ModuleReference mref) {
    ModuleReader reader = moduleToReader.get(mref);
    if (reader == null) {
        // avoid method reference during startup
        Function<ModuleReference, ModuleReader> create = new Function<>() {
            public ModuleReader apply(ModuleReference moduleReference) {
                try {
                    return mref.open();
                } catch (IOException e) {
                    // Return a null module reader to avoid a future class
                    // load attempting to open the module again.
                    return new NullModuleReader();
                }
            }
        };
        reader = moduleToReader.computeIfAbsent(mref, create);
    }
    return reader;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:BuiltinClassLoader.java

示例3: main

import java.lang.module.ModuleReference; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    String mn = args[0];

    ModuleReference mref = ModuleLayer.boot()
            .configuration()
            .findModule(mn)
            .map(ResolvedModule::reference)
            .orElseThrow(() -> new RuntimeException(mn + " not resolved!!"));

    try (ModuleReader reader = mref.open()) {
        reader.list().forEach(name -> {
            testFindUnchecked(name);

            // if the resource is a directory then find without trailing slash
            if (name.endsWith("/")) {
                testFindUnchecked(name.substring(0, name.length() - 1));
            }
        });
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:Main.java

示例4: createModuleReader

import java.lang.module.ModuleReference; //导入方法依赖的package包/类
/**
 * Creates a ModuleReader for the given module.
 */
private ModuleReader createModuleReader(ModuleReference mref) {
    try {
        return mref.open();
    } catch (IOException e) {
        // Return a null module reader to avoid a future class load
        // attempting to open the module again.
        return new NullModuleReader();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:Loader.java

示例5: listAllModules

import java.lang.module.ModuleReference; //导入方法依赖的package包/类
/**
 * List all modules that the finder finds and the resources in the module.
 */
private void listAllModules(ModuleFinder finder) throws Exception {
    for (ModuleReference mref : finder.findAll()) {
        System.out.println(mref.descriptor());
        try (ModuleReader reader = mref.open()) {
            reader.list().forEach(name -> System.out.format("  %s%n", name));
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ModulesInCustomFileSystem.java

示例6: read

import java.lang.module.ModuleReference; //导入方法依赖的package包/类
public static ModuleTarget read(ModuleReference modRef) throws IOException {
    ModuleReader reader = modRef.open();
    try (InputStream in = reader.open("module-info.class").get()) {
        return read(in);
    } finally {
        reader.close();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:ModuleTargetHelper.java

示例7: testModuleReader

import java.lang.module.ModuleReference; //导入方法依赖的package包/类
/**
 * Exercise ModuleReader on a multi-release JAR
 */
public void testModuleReader() throws Exception {
    String name = "m1";

    ModuleDescriptor descriptor1 = ModuleDescriptor.newModule(name)
            .requires("java.base")
            .build();

    // module descriptor for versioned section
    ModuleDescriptor descriptor2 = ModuleDescriptor.newModule(name)
            .requires("java.base")
            .requires("jdk.unsupported")
            .build();

    Path jar = new JarBuilder(name)
            .moduleInfo(MODULE_INFO, descriptor1)
            .moduleInfo("META-INF/versions/" + VERSION + "/" + MODULE_INFO, descriptor2)
            .build();

    // find the module
    ModuleFinder finder = ModuleFinder.of(jar);
    Optional<ModuleReference> omref = finder.find(name);
    assertTrue((omref.isPresent()));
    ModuleReference mref = omref.get();

    ModuleDescriptor expected;
    if (MULTI_RELEASE) {
        expected = descriptor2;
    } else {
        expected = descriptor1;
    }

    // test ModuleReader by reading module-info.class resource
    try (ModuleReader reader = mref.open()) {

        // open resource
        Optional<InputStream> oin = reader.open(MODULE_INFO);
        assertTrue(oin.isPresent());
        try (InputStream in = oin.get()) {
            checkRequires(ModuleDescriptor.read(in), expected);
        }

        // read resource
        Optional<ByteBuffer> obb = reader.read(MODULE_INFO);
        assertTrue(obb.isPresent());
        ByteBuffer bb = obb.get();
        try {
            checkRequires(ModuleDescriptor.read(bb), expected);
        } finally {
            reader.release(bb);
        }

        // find resource
        Optional<URI> ouri = reader.find(MODULE_INFO);
        assertTrue(ouri.isPresent());
        URI uri = ouri.get();

        String expectedTail = "!/";
        if (MULTI_RELEASE)
            expectedTail += "META-INF/versions/" + VERSION + "/";
        expectedTail += MODULE_INFO;
        assertTrue(uri.toString().endsWith(expectedTail));

        URLConnection uc = uri.toURL().openConnection();
        uc.setUseCaches(false);
        try (InputStream in = uc.getInputStream()) {
            checkRequires(ModuleDescriptor.read(in), expected);
        }

    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:74,代码来源:MultiReleaseJarTest.java


注:本文中的java.lang.module.ModuleReference.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。