Search in sources :

Example 1 with ComponentArchiveReader

use of org.graalvm.component.installer.ComponentArchiveReader in project graal by oracle.

the class DirectoryCatalogProvider method maybeCreateComponent.

private ComponentInfo maybeCreateComponent(Path localFile) throws IOException {
    byte[] fileStart = null;
    String serial;
    if (Files.isRegularFile(localFile)) {
        try (ReadableByteChannel ch = FileChannel.open(localFile, StandardOpenOption.READ)) {
            ByteBuffer bb = ByteBuffer.allocate(8);
            ch.read(bb);
            fileStart = bb.array();
        }
        serial = SystemUtils.fingerPrint(SystemUtils.computeFileDigest(localFile, null));
    } else {
        fileStart = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 };
        serial = SystemUtils.digestString(localFile.toString(), false);
    }
    MetadataLoader ldr = null;
    try {
        for (ComponentArchiveReader provider : ServiceLoader.load(ComponentArchiveReader.class)) {
            ldr = provider.createLoader(localFile, fileStart, serial, feedback, verifyJars);
            if (ldr != null) {
                ComponentInfo info = ldr.getComponentInfo();
                info.setRemoteURL(localFile.toUri().toURL());
                info.setOrigin(feedback.l10n("DIR_LocalFile"));
                return info;
            }
        }
    } finally {
        // ignore, may be not a component...
        if (ldr != null) {
            ldr.close();
        }
    }
    return null;
}
Also used : ReadableByteChannel(java.nio.channels.ReadableByteChannel) ComponentArchiveReader(org.graalvm.component.installer.ComponentArchiveReader) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 ComponentArchiveReader (org.graalvm.component.installer.ComponentArchiveReader)1 ComponentInfo (org.graalvm.component.installer.model.ComponentInfo)1