void put(final URI uri, ArtifactData data) throws Exception {
   reporter.trace("put %s %s", uri, data);
   File tmp = createTempFile(repoDir, "mtp", ".whatever");
   tmp.deleteOnExit();
   try {
     copy(uri.toURL(), tmp);
     byte[] sha = SHA1.digest(tmp).digest();
     reporter.trace("SHA %s %s", uri, Hex.toHexString(sha));
     ArtifactData existing = get(sha);
     if (existing != null) {
       reporter.trace("existing");
       xcopy(existing, data);
       return;
     }
     File meta = new File(repoDir, Hex.toHexString(sha) + ".json");
     File file = new File(repoDir, Hex.toHexString(sha));
     rename(tmp, file);
     reporter.trace("file %s", file);
     data.file = file.getAbsolutePath();
     data.sha = sha;
     data.busy = false;
     CommandData cmddata = parseCommandData(data);
     if (cmddata.bsn != null) {
       data.name = cmddata.bsn + "-" + cmddata.version;
     } else data.name = Strings.display(cmddata.title, cmddata.bsn, cmddata.name, uri);
     codec.enc().to(meta).put(data);
     reporter.trace("TD = " + data);
   } finally {
     tmp.delete();
     reporter.trace("puted %s %s", uri, data);
   }
 }
 private String createTemporaryPreinstallFile() {
   try {
     File tempFile = File.createTempFile("preinstall", null);
     tempFile.deleteOnExit();
     InstallUtil.copyResourceToFile("/gnu/io/installer/resources/macosx/preinstall", tempFile);
     String absPath = tempFile.getAbsolutePath();
     Process p = Runtime.getRuntime().exec(new String[] {"chmod", "a+x", absPath});
     p.waitFor();
     return absPath;
   } catch (Throwable t) {
   }
   return null;
 }
 private void installAuthKit() {
   boolean usingJWS = false;
   final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
   if (originalClassLoader.toString().toLowerCase().indexOf("jnlp") != -1) usingJWS = true;
   if (usingJWS) return;
   try {
     File tempFile = new File(jarFolder, "libAuthKit.jnilib");
     tempFile.deleteOnExit();
     InstallUtil.copyResourceToFile(
         "/gnu/io/installer/resources/macosx/lib/libAuthKit.jnilib", tempFile);
   } catch (Throwable t) {
     System.out.println("installAuthKit Throwable " + t);
   }
 }
Beispiel #4
0
    public void run() {
      try {
        URL url = new URL(protocol + "://localhost:" + port + "/test1/" + f);
        HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
        if (urlc instanceof HttpsURLConnection) {
          HttpsURLConnection urlcs = (HttpsURLConnection) urlc;
          urlcs.setHostnameVerifier(
              new HostnameVerifier() {
                public boolean verify(String s, SSLSession s1) {
                  return true;
                }
              });
          urlcs.setSSLSocketFactory(ctx.getSocketFactory());
        }
        byte[] buf = new byte[4096];

        if (fixedLen) {
          urlc.setRequestProperty("XFixed", "yes");
        }
        InputStream is = urlc.getInputStream();
        File temp = File.createTempFile("Test1", null);
        temp.deleteOnExit();
        OutputStream fout = new BufferedOutputStream(new FileOutputStream(temp));
        int c, count = 0;
        while ((c = is.read(buf)) != -1) {
          count += c;
          fout.write(buf, 0, c);
        }
        is.close();
        fout.close();

        if (count != size) {
          throw new RuntimeException("wrong amount of data returned");
        }
        String orig = root + "/" + f;
        compare(new File(orig), temp);
        temp.delete();
      } catch (Exception e) {
        e.printStackTrace();
        fail = true;
      }
    }