All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ibm.wala.util.io.RtJar Maven / Gradle / Ivy

The newest version!
package com.ibm.wala.util.io;

import com.ibm.wala.util.PlatformUtil;
import com.ibm.wala.util.collections.ArrayIterator;
import com.ibm.wala.util.collections.FilterIterator;
import com.ibm.wala.util.collections.MapIterator;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.jar.JarFile;
import org.jspecify.annotations.NullUnmarked;

public class RtJar {

  @NullUnmarked
  public static JarFile getRtJar(Iterator x) {
    while (x.hasNext()) {
      JarFile JF = x.next();
      switch (Paths.get(JF.getName()).getFileName().toString()) {
        case "core.jar":
        case "java.base.jmod":
        case "rt.jar":
          return JF;
        case "classes.jar":
          if (PlatformUtil.onMacOSX()) return JF;
        // $FALL-THROUGH$
        default:
      }
    }

    return null;
  }

  public static void main(String[] args) {
    @SuppressWarnings("resource")
    JarFile rt =
        getRtJar(
            new MapIterator<>(
                new FilterIterator<>(
                    new ArrayIterator<>(
                        System.getProperty("sun.boot.class.path").split(File.pathSeparator)),
                    t -> t.endsWith(".jar")),
                object -> {
                  try {
                    return new JarFile(object);
                  } catch (IOException e) {
                    throw new RuntimeException(e);
                  }
                }));

    System.err.println(rt.getName());
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy