Search code examples
javajardownloadinputstream

Create JarFile from InputStream


I want to read a JarFile, from the Internet, to the ram and handle it as a JarFile. Is there a way to convert a JarInputStream to a JarFile or a byte[] into a JarFile, without first saving it?

plid is 55283

public static void update() throws Exception {

    HttpURLConnection conn = (HttpURLConnection) new URL("https://api.spiget.org/v2/resources/" + plid).openConnection();
    JSONObject info = (JSONObject) new JSONParser().parse(new InputStreamReader(conn.getInputStream()));
    long dwlid = Long.parseLong( ((JSONObject) ((JSONArray) info.get("versions")).get(0)).get("id").toString() );
    String dwl = String.format("https://api.spiget.org/v2/resources/{0}/versions/{1}/download", plid, dwlid);

    conn = (HttpURLConnection) new URL(dwl).openConnection();
    conn.setRequestProperty("user-agent", Core.useragent);
    conn = f(conn);

    InputStream in = conn.getInputStream();
    JarInputStream jis = new JarInputStream(in);
    JarFile jf = new Jar


}

Solution

  • Unfortunately java.util.jar.JarFile and java.util.zip.ZipFile only operate on a File.

    Furthermore the part that actually reads the file is implemented in native. Therefore overriding the class and redirecting the implementation to a byte[] or any other sort of buffer does not seem to be feasible from my point of view.