Exemple #1
0
  public boolean main(Context c, String[] arg) {
    ctx = c;

    if (arg.length < 2) {
      ctx.error("Usage: __builtin_cp::[file::[file::[file...]]]::[dest]");
      return false;
    }

    if (arg.length > 2) {
      return copy_many_to_one(arg);
    } else {
      return copy_one_to_one(arg);
    }
  }
 private static void unpackZip(
     final Context context,
     final File path,
     final URL remoteUrl,
     final ArrayList<File> unpackedFiles,
     final int retry)
     throws IOException {
   try {
     final InputStream response = remoteUrl.openConnection().getInputStream();
     final ZipInputStream zip = new ZipInputStream(new BufferedInputStream(response));
     ZipEntry entry;
     final byte[] buffer = new byte[8192];
     while ((entry = zip.getNextEntry()) != null) {
       long size = 0;
       final File file = new File(path, entry.getName());
       unpackedFiles.add(file);
       final FileOutputStream fos = new FileOutputStream(file);
       int len;
       while ((len = zip.read(buffer)) != -1) {
         fos.write(buffer, 0, len);
         size += len;
       }
       fos.close();
       context.log("Unpacked: " + entry.getName() + ". Size: " + (size / 1024) + "kB");
       zip.closeEntry();
     }
     zip.close();
   } catch (IOException io) {
     context.error(io);
     for (final File f : unpackedFiles) {
       if (f.delete()) {
         context.log("Cleaned up: " + f);
       } else {
         context.log("Failed to clean up: " + f);
       }
     }
     if (retry > 0) {
       context.log("Retrying download... from " + remoteUrl);
       unpackZip(context, path, remoteUrl, new ArrayList<File>(), retry - 1);
     } else throw io;
   }
 }