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;
}
Aggregations