public void init() throws IOException {
   URL s = getClass().getClassLoader().getResource(SERVICE_JAR_FILE);
   if (s == null)
     if (underTest) return;
     else throw new Error("No " + SERVICE_JAR_FILE + " resource in jar");
   service.getParentFile().mkdirs();
   IO.copy(s, service);
 }
 private File fileReallyExists(URL ret, String fileWithoutPackage) {
   File path;
   try {
     /* fix for GROOVY-5809 */
     path = new File(ret.toURI());
   } catch (URISyntaxException e) {
     path = new File(decodeFileName(ret.getFile()));
   }
   path = path.getParentFile();
   if (path.exists() && path.isDirectory()) {
     File file = new File(path, fileWithoutPackage);
     if (file.exists()) {
       // file.exists() might be case insensitive. Let's do
       // case sensitive match for the filename
       File parent = file.getParentFile();
       for (String child : parent.list()) {
         if (child.equals(fileWithoutPackage)) return file;
       }
     }
   }
   // file does not exist!
   return null;
 }
 public static String getBase() throws Exception {
   if (PKCS11_BASE != null) {
     return PKCS11_BASE;
   }
   File cwd = new File(System.getProperty("test.src", ".")).getCanonicalFile();
   while (true) {
     File file = new File(cwd, "TEST.ROOT");
     if (file.isFile()) {
       break;
     }
     cwd = cwd.getParentFile();
     if (cwd == null) {
       throw new Exception("Test root directory not found");
     }
   }
   PKCS11_BASE = new File(cwd, PKCS11_REL_PATH.replace('/', SEP)).getAbsolutePath();
   return PKCS11_BASE;
 }
Beispiel #4
0
  public static void extract(String zipFile, String newPath, boolean overwrite)
      throws ZipException, IOException {
    File file = new File(zipFile);

    ZipFile zip = new ZipFile(file);

    new File(newPath).mkdir();
    Enumeration<? extends ZipEntry> zipFileEntries = zip.entries();

    // Process each entry
    while (zipFileEntries.hasMoreElements()) {
      // grab a zip file entry
      ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
      String currentEntry = entry.getName();
      File destFile = new File(newPath, currentEntry);
      // destFile = new File(newPath, destFile.getName());
      File destinationParent = destFile.getParentFile();

      // create the parent directory structure if needed
      destinationParent.mkdirs();

      if (!entry.isDirectory()) {
        if (!overwrite && destFile.exists()) continue;
        BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry));
        int currentByte;
        // establish buffer for writing file
        byte data[] = new byte[BUFFER];

        // write the current file to disk
        FileOutputStream fos = new FileOutputStream(destFile);
        BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);

        // read and write until last byte is encountered
        while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
          dest.write(data, 0, currentByte);
        }
        close(dest);
        close(is);
      }
    }
  }