public static void main(final String[] args) {
   final File targetFile = new File("D:\\abc.def");
   final File tmp = new File(targetFile.getPath() + ".frftmp");
   if (!FileAccess.compressFileGZip(targetFile, tmp)) {
     return; // error
   }
   targetFile.delete();
   tmp.renameTo(targetFile);
 }
Beispiel #2
0
 public boolean ok(String out, String reference) {
   try {
     File fo = File.createTempFile("homeworkeval", ".out");
     File fr = File.createTempFile("homeworkeval", ".ref");
     log.fine("Running custom validator.");
     save(out, fo);
     save(reference, fr);
     ArrayList<String> c = new ArrayList<String>();
     c.add(command);
     c.add(fo.getPath());
     c.add(fr.getPath());
     ProcessBuilder pb = new ProcessBuilder(c);
     Process p = pb.start();
     int rc = p.waitFor();
     fo.delete();
     fr.delete();
     log.fine("Custom validator " + command + " says " + rc);
     return rc == 0;
   } catch (Exception e) {
     // Assume NOK. Don't propagate info to the client.
     log.finer("exc: " + UtilSrv.describe(e));
     return false;
   }
 }
  @Timeout
  public void handletimeout(Timer timer) {
    // delete temp files

    for (File f : deleteTempFileList) {
      dbgLog.fine("file to be deleted: path=" + f.getAbsolutePath() + "\tname=" + f.getName());
      if (f.exists()) {
        boolean sc = f.delete();
        if (!sc) {
          dbgLog.fine(
              "failed to delete file: path=" + f.getAbsolutePath() + "\tname=" + f.getName());
        } else {
          dbgLog.fine("successfully deleted? let's check its existence");
          if (f.exists()) {
            dbgLog.fine("surprise: actually the File still exists");
          } else {
            dbgLog.fine("The file no longer exists");
          }
        }
      }
    }
  }