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);
   }
 }
示例#2
0
  /** DOCUMENT ME! */
  public void loadRaids() {
    File f = new File(REPO);

    if (!f.exists()) {
      return;
    }

    FileInputStream fIn = null;
    ObjectInputStream oIn = null;

    try {
      fIn = new FileInputStream(REPO);
      oIn = new ObjectInputStream(fIn);
      // de-serializing object
      raids = (HashMap<String, GregorianCalendar>) oIn.readObject();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } finally {
      try {
        oIn.close();
        fIn.close();
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    }
  }
  public static void main(String[] args) {
    new ExampleProjects();

    try {

      File exsDir = new File("osb/showcase/neuroConstructShowcase");

      File mainFile = new File("docs/XML/xmlForHtml/samples/index.xml");

      logger.logComment("Going to create docs at: " + mainFile.getCanonicalPath(), true);

      generateMainPage(mainFile, exsDir);

      logger.logComment("Created doc at: " + mainFile.getCanonicalPath(), true);
      /*
      File modelsDir = new File("nCmodels");
      mainFile = new File("docs/XML/xmlForHtml/models/index.xml");


      generateMainPage(mainFile, modelsDir);

      logger.logComment("Created doc at: "+ mainFile.getCanonicalPath(), true);

       */
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#4
0
文件: Copier.java 项目: ohadcn/oop
  /**
   * Copy the files.
   *
   * @param CWD the source directory.
   * @throws IOException in case of a problem while coping.
   */
  public void commit(File CWD) throws IOException {
    String targetDir = CWD.getCanonicalPath() + "//" + target + "//";
    File tarDir = new File(targetDir);
    if (!tarDir.isDirectory()) tarDir.mkdirs();

    commit(tarDir, CWD);
  }
示例#5
0
  public BackTestFileWriter(Strategy strategy) throws JArbitragerException {
    decimalFormat = NumberFormatterFactory.getNumberFormatter(5);
    dateFormat = new SimpleDateFormat("MMddyy,HHmmss");
    dateFormat.setTimeZone(strategy.getTradingSchedule().getTimeZone());

    File marketDataDir = new File(MARKET_DATA_DIR);
    if (!marketDataDir.exists()) {
      marketDataDir.mkdir();
    }

    String fullFileName = MARKET_DATA_DIR + FILE_SEP + strategy.getName() + ".txt";
    try {
      boolean fileExisted = new File(fullFileName).exists();
      writer = new PrintWriter(new BufferedWriter(new FileWriter(fullFileName, true)));
      if (!fileExisted) {
        StringBuilder header =
            getHeader(
                strategy.getInstrument1().getContract().m_symbol,
                strategy.getInstrument2().getContract().m_symbol);
        writer.println(header);
      }
    } catch (IOException ioe) {
      throw new JArbitragerException("Could not write to file " + strategy.getName());
    }
  }
示例#6
0
  public CryoBay reconnectServer(ORB o, ReconnectThread rct) {

    BufferedReader reader;
    File file;
    ORB orb;
    org.omg.CORBA.Object obj;

    orb = o;

    obj = null;
    cryoB = null;

    try {
      // instantiate ModuleAccessor
      file = new File("/vnmr/acqqueue/cryoBay.CORBAref");
      if (file.exists()) {
        reader = new BufferedReader(new FileReader(file));
        obj = orb.string_to_object(reader.readLine());
      }

      if (obj != null) {
        cryoB = CryoBayHelper.narrow(obj);
      }

      if (cryoB != null) {
        if (!(cryoB._non_existent())) {
          // System.out.println("reconnected!!!!");
          rct.reconnected = true;
        }
      }
    } catch (Exception e) {
      // System.out.println("Got error: " + e);
    }
    return cryoB;
  }
  public static void writeByteBuffer(ByteBuffer bbuf, String filename) {
    // Write bbuf to filename
    File file;
    try {
      // Get log file
      String logfile = "C:\\" + filename + ".txt";
      file = new File(logfile);
      boolean exists = file.exists();
      if (!exists) {
        // create a new, empty node file
        try {
          file = new File(logfile);
          boolean success = file.createNewFile();
        } catch (IOException e) {
          System.out.println("Create Event Log file failed!");
        }
      }
      try {
        // Create a writable file channel
        FileChannel wChannel = new FileOutputStream(file, true).getChannel();
        // Write the ByteBuffer contents; the bytes between the ByteBuffer's
        // position and the limit is written to the file
        wChannel.write(bbuf);

        // Close the file
        wChannel.close();
      } catch (IOException e) {
      }
    } catch (java.lang.Exception e) {
    }
  }
 public static void writeLogFile(String descript, String filename) {
   File file;
   FileOutputStream outstream;
   // BufferedWriter outstream;
   Date time = new Date();
   long bytes = 30000000;
   try {
     // Get log file
     String logfile = "C:\\" + filename + ".txt";
     file = new File(logfile);
     boolean exists = file.exists();
     if (!exists) {
       // create a new, empty node file
       try {
         file = new File(logfile);
         boolean success = file.createNewFile();
       } catch (IOException e) {
         System.out.println("Create Event Log file failed!");
       }
     }
     try {
       descript = descript + "\n";
       outstream = new FileOutputStream(file, true);
       for (int i = 0; i < descript.length(); ++i) {
         outstream.write((byte) descript.charAt(i));
       }
       outstream.close();
     } catch (IOException e) {
     }
   } catch (java.lang.Exception e) {
   }
 }
  private Service getService(File base) throws Exception {
    File dataFile = new File(base, "data");
    if (!dataFile.isFile()) return null;

    ServiceData data = getData(ServiceData.class, dataFile);
    return new Service(this, data);
  }
示例#10
0
  public void jButton1_actionPerformed(ActionEvent e) {
    JFileChooser fc = new JFileChooser();
    int returnVal = fc.showOpenDialog(parent);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File file = fc.getSelectedFile();
      jTextField1.setText(file.toString());
    }
  }
示例#11
0
 /**
  * Method to build an absolute path
  *
  * @param dir the root dir
  * @param name the name of the new directory
  * @return if name is an absolute directory, returns name, else returns dir+name
  */
 public static String getDir(String dir, String name) {
   if (!dir.endsWith(File.separator)) dir = dir + File.separator;
   File mv = new File(name);
   String new_dir = null;
   if (!mv.isAbsolute()) {
     new_dir = dir + name;
   } else new_dir = name;
   return new_dir;
 }
 /**
  * Enable or disable the logging of the summary stats computed with all the stats collected by
  * this <tt>HammerStats</tt>.
  *
  * @param summaryStats the boolean that enable of disable the logging.
  */
 public void setSummaryStatsLogging(boolean summaryStats) {
   this.summaryStatsLogging = summaryStats;
   if (summaryStats) {
     File saveDir = new File(this.statsDirectoryPath);
     if (!saveDir.exists()) {
       logger.info("Creating stats directory at : " + this.statsDirectoryPath);
       saveDir.mkdirs();
     }
   }
 }
 /**
  * Enable or disable the logging of all the stats collected by this <tt>HammerStats</tt>.
  *
  * @param overallStats the boolean that enable of disable the logging.
  */
 public void setOverallStatsLogging(boolean overallStats) {
   this.overallStatsLogging = overallStats;
   if (overallStats) {
     File saveDir = new File(this.statsDirectoryPath);
     if (!saveDir.exists()) {
       logger.info("Creating stats directory at : " + this.statsDirectoryPath);
       saveDir.mkdirs();
     }
   }
 }
示例#14
0
  /** Display a dialog which allows the user to export a scene to an OBJ file. */
  public static void exportFile(BFrame parent, Scene theScene) {
    // Display a dialog box with options on how to export the scene.

    // ValueField errorField = new ValueField(0.05, ValueField.POSITIVE);
    // final ValueField widthField = new ValueField(200.0, ValueField.INTEGER+ValueField.POSITIVE);
    // final ValueField heightField = new ValueField(200.0, ValueField.INTEGER+ValueField.POSITIVE);
    // final ValueSlider qualitySlider = new ValueSlider(0.0, 1.0, 100, 0.5);
    // final BCheckBox smoothBox = new BCheckBox(Translate.text("subdivideSmoothMeshes"), true);
    final BCheckBox injectChoice = new BCheckBox(Translate.text("Inject"), true);
    // final BCheckBox UVChoice = new BCheckBox(Translate.text("Export UV"), true);

    /*BComboBox exportChoice = new BComboBox(new String [] {
      Translate.text("exportWholeScene"),
      Translate.text("selectedObjectsOnly")
    });*/

    ComponentsDialog dlg;
    if (theScene.getSelection().length > 0)
      dlg =
          new ComponentsDialog(
              parent,
              Translate.text("InjectToM2"),
              new Widget[] {injectChoice},
              new String[] {null, null, null, null, null});
    else
      dlg =
          new ComponentsDialog(
              parent,
              Translate.text("exportToM2"),
              new Widget[] {injectChoice},
              new String[] {null, null, null, null});
    if (!dlg.clickedOk()) return;

    // Ask the user to select the output file.

    BFileChooser fc = new BFileChooser(BFileChooser.SAVE_FILE, Translate.text("exportToWMO"));
    fc.setSelectedFile(new File("Untitled.m2"));
    if (ArtOfIllusion.getCurrentDirectory() != null)
      fc.setDirectory(new File(ArtOfIllusion.getCurrentDirectory()));
    if (!fc.showDialog(parent)) return;
    File dir = fc.getDirectory();
    f = fc.getSelectedFile();
    String name = f.getName();
    String baseName = (name.endsWith(".m2") ? name.substring(0, name.length() - 3) : name);
    ArtOfIllusion.setCurrentDirectory(dir.getAbsolutePath());

    m2 obj = null;
    try {
      obj = new m2(fileLoader.openBuffer(f.getAbsolutePath()));
    } catch (InvalidClassException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    writeScene(theScene, obj, false, 0.05, false, injectChoice.getState());
  }
示例#15
0
  public void setFileName(int row, String name) {
    // avoid moving a File by renaming it !!
    if (name.indexOf("..") < 0 && name.indexOf("/") < 0 && name.indexOf("\\") < 0) {
      File oldFile = getFile(filenames[row]);
      File newFile = new File(oldFile.getParent() + File.separator + name);

      filenames[row] = name;

      oldFile.renameTo(newFile);
    }
  }
示例#16
0
 // When already existing adapted project is created , need to move to new adapted project
 private boolean deleteCIJobFile(ApplicationInfo appInfo) throws PhrescoException {
   S_LOGGER.debug("Entering Method ProjectAdministratorImpl.deleteCI()");
   try {
     File ciJobInfo = new File(getCIJobPath(appInfo));
     return ciJobInfo.delete();
   } catch (ClientHandlerException ex) {
     S_LOGGER.error(
         "Entered into catch block of ProjectAdministratorImpl.deleteCI()"
             + ex.getLocalizedMessage());
     throw new PhrescoException(ex);
   }
 }
    @Override
    public void actionPerformed(ActionEvent e) {
      if (fc == null) {
        fc = new IDEFileChooser();
        fc.setFileView(new IDEFileView());
        fc.setAcceptAllFileFilterUsed(false);
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fc.setMultiSelectionEnabled(false);
        fc.setDialogTitle(
            messagesBundle.getString("ImageViewerPanelSaveAction.Choose_filename_to_save_4"));

        //$NON-NLS-1$

        // prepare file filters
        IIORegistry theRegistry = IIORegistry.getDefaultInstance();
        Iterator it = theRegistry.getServiceProviders(ImageWriterSpi.class, false);
        while (it.hasNext()) {
          ImageWriterSpi writer = (ImageWriterSpi) it.next();
          if ((imageType == BufferedImage.TYPE_INT_ARGB
                  || imageType == BufferedImage.TYPE_INT_ARGB_PRE)
              && "JPEG".equals(writer.getFormatNames()[0].toUpperCase())) continue;
          ImageWriterSpiFileFilter ff = new ImageWriterSpiFileFilter(writer);
          fc.addChoosableFileFilter(ff);
        }
      }

      if (fc.showSaveDialog(viewerPanel) == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fc.getSelectedFile();

        if (selectedFile != null) {
          String fileName = selectedFile.getAbsolutePath();
          ImageWriterSpiFileFilter ff = (ImageWriterSpiFileFilter) fc.getFileFilter();
          if (!ff.hasCorrectSuffix(fileName)) fileName = ff.addSuffix(fileName);
          selectedFile = new File(fileName);
          if (selectedFile.exists()) {
            String message =
                MessageFormat.format(
                    messagesBundle.getString("ImageViewerPanelSaveAction.Overwrite_question_5"),
                    //$NON-NLS-1$
                    fileName);
            if (JOptionPane.NO_OPTION
                == JOptionPane.showConfirmDialog(
                    viewerPanel,
                    message,
                    messagesBundle.getString("ImageViewerPanelSaveAction.Warning_6"),
                    //$NON-NLS-1$
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE)) return;
          }
          writeToFile(selectedFile, ff);
        }
      }
    }
示例#18
0
文件: Macro.java 项目: bramk/bnd
 public String _isdir(String args[]) {
   if (args.length < 2) {
     domain.warning("Need at least one file name for ${isdir;...}");
     return null;
   }
   boolean isdir = true;
   for (int i = 1; i < args.length; i++) {
     File f = new File(args[i]).getAbsoluteFile();
     isdir &= f.isDirectory();
   }
   return isdir ? "true" : "false";
 }
  private void saveData(TelemetryData data) {
    PrintWriter out;
    boolean newFile = false;

    if (saveCnt > 25000) {
      File logFile;
      int i;

      logFile = new File(telemetryDir + 99 + ".log");
      logFile.delete();
      newFile = true;

      for (i = 99; i > 0; i--) {
        logFile = new File(telemetryDir + (i - 1) + ".log");
        logFile.renameTo(new File(telemetryDir + i + ".log"));
      }
      saveCnt = 0;
    }

    try {
      String text = "";
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN);

      saveCnt++;
      out = new PrintWriter(new FileOutputStream(telemetryDir + "0.log", true));
      if (newFile) {
        text =
            "Time\tLatitude\tLongitude\tSpeed\tAcceleration X\tAcceleration Y\tAcceleration Z\tCoG\tOrientation Y\tOrientation Z\n\n";
        out.print(text);
      }
      text = dateFormat.format(new Date(System.currentTimeMillis())) + "\t";
      if (posValid) text = text + lastLat + "\t" + lastLon + "\t" + m_lastSpeed + "\t";
      else text = text + "-\t-\t-\t";
      text =
          text
              + data.getAccelX()
              + "\t"
              + data.getAccelY()
              + "\t"
              + data.getAccelZ()
              + "\t"
              + data.CoG
              + "\t"
              + data.getOrientY()
              + "\t"
              + data.getOrientZ()
              + "\n\n";
      out.print(text);
      out.close();
    } catch (IOException ioe) {
    }
  }
 /**
  * Get a thumbnail.
  *
  * <p>If not available the image is created.
  */
 public synchronized Image getImage(PM_Picture picture, boolean toImport) {
   File fileOriginal = picture.getFileOriginal();
   File fileThumbnail = PM_Utils.getFileThumbnail(fileOriginal);
   // The thumbnail file is available.
   if (fileThumbnail.isFile()) {
     return readImageThumbnail(fileThumbnail);
   }
   // The thumb nail file is NOT available.
   if (toImport) {
     //			return readThumbAsIcon(picture, fileOriginal, fileThumbnail);
   }
   return readThumb(picture, fileThumbnail);
 };
示例#21
0
  public List<CommandData> getCommands(File commandDir) throws Exception {
    List<CommandData> result = new ArrayList<CommandData>();

    if (!commandDir.exists()) {
      return result;
    }

    for (File f : commandDir.listFiles()) {
      CommandData data = getData(CommandData.class, f);
      if (data != null) result.add(data);
    }
    return result;
  }
示例#22
0
  private ArrayList GetFolderTree(String s_Dir, String s_Flag, int n_Indent, int n_TreeIndex) {
    String s_List = "";
    ArrayList aSubFolders = new ArrayList();

    File file = new File(s_Dir);
    File[] filelist = file.listFiles();

    if (filelist != null && filelist.length > 0) {
      for (int i = 0; i < filelist.length; i++) {
        if (filelist[i].isDirectory()) {
          aSubFolders.add(filelist[i].getName());
        }
      }

      int n_Count = aSubFolders.size();
      String s_LastFlag = "";
      String s_Folder = "";
      for (int i = 1; i <= n_Count; i++) {
        if (i < n_Count) {
          s_LastFlag = "0";
        } else {
          s_LastFlag = "1";
        }

        s_Folder = aSubFolders.get(i - 1).toString();
        s_List =
            s_List
                + "arr"
                + s_Flag
                + "["
                + String.valueOf(n_TreeIndex)
                + "]=new Array(\""
                + s_Folder
                + "\","
                + String.valueOf(n_Indent)
                + ", "
                + s_LastFlag
                + ");\n";
        n_TreeIndex = n_TreeIndex + 1;
        ArrayList a_Temp =
            GetFolderTree(s_Dir + s_Folder + sFileSeparator, s_Flag, n_Indent + 1, n_TreeIndex);
        s_List = s_List + a_Temp.get(0).toString();
        n_TreeIndex = Integer.valueOf(a_Temp.get(1).toString()).intValue();
      }
    }

    ArrayList a_Return = new ArrayList();
    a_Return.add(s_List);
    a_Return.add(String.valueOf(n_TreeIndex));
    return a_Return;
  }
示例#23
0
文件: Macro.java 项目: bramk/bnd
  String ls(String args[], boolean relative) {
    if (args.length < 2)
      throw new IllegalArgumentException(
          "the ${ls} macro must at least have a directory as parameter");

    File dir = domain.getFile(args[1]);
    if (!dir.isAbsolute())
      throw new IllegalArgumentException(
          "the ${ls} macro directory parameter is not absolute: " + dir);

    if (!dir.exists())
      throw new IllegalArgumentException(
          "the ${ls} macro directory parameter does not exist: " + dir);

    if (!dir.isDirectory())
      throw new IllegalArgumentException(
          "the ${ls} macro directory parameter points to a file instead of a directory: " + dir);

    Collection<File> files = new ArrayList<File>(new SortedList<File>(dir.listFiles()));

    for (int i = 2; i < args.length; i++) {
      Instructions filters = new Instructions(args[i]);
      files = filters.select(files, true);
    }

    List<String> result = new ArrayList<String>();
    for (File file : files) result.add(relative ? file.getName() : file.getAbsolutePath());

    return Processor.join(result, ",");
  }
示例#24
0
文件: Macro.java 项目: bramk/bnd
  public String _fmodified(String args[]) throws Exception {
    verifyCommand(args, _fmodifiedHelp, null, 2, Integer.MAX_VALUE);

    long time = 0;
    Collection<String> names = new ArrayList<String>();
    for (int i = 1; i < args.length; i++) {
      Processor.split(args[i], names);
    }
    for (String name : names) {
      File f = new File(name);
      if (f.exists() && f.lastModified() > time) time = f.lastModified();
    }
    return "" + time;
  }
示例#25
0
  public List<ServiceData> getServices(File serviceDir) throws Exception {
    List<ServiceData> result = new ArrayList<ServiceData>();

    if (!serviceDir.exists()) {
      return result;
    }

    for (File sdir : serviceDir.listFiles()) {
      File dataFile = new File(sdir, "data");
      ServiceData data = getData(ServiceData.class, dataFile);
      result.add(data);
    }
    return result;
  }
示例#26
0
 public static boolean deleteRecursive(File dir) {
   boolean result = true;
   File files[] = dir.listFiles();
   if (files != null) {
     for (int i = 0; i < files.length; i++) {
       if (files[i].isDirectory()) {
         result = result && deleteRecursive(files[i]);
       } else {
         result = result && files[i].delete();
       }
     }
   }
   result = result && dir.delete();
   return result;
 }
示例#27
0
 private static void listPhoneBooks(String curDirectory) throws IOException, ParseException {
   File myDir = new File(curDirectory);
   String[] filenames = myDir.list();
   ArrayList<String> phoneBooks = new ArrayList<String>();
   for (int i = 0; i < filenames.length; i++) {
     int temp = filenames[i].lastIndexOf(".");
     if (temp > 0) {
       String ext = filenames[i].substring(temp + 1);
       if (ext.compareTo("txt") == 0) {
         phoneBooks.add(filenames[i].substring(0, temp));
       }
     }
   }
   displayPhoneBooks(phoneBooks);
 }
示例#28
0
  public static int save(m2 out) {
    // TODO: catch failures and so on

    out.render();
    fileLoader.saveBuffer(out.buff, f.getAbsolutePath());
    return 1;
  }
示例#29
0
  public void restartApplication() {

    try {

      final String javaBin =
          System.getProperty("java.home") + File.separator + "bin" + File.separator + "javaw";
      final File currentJar =
          new File(network.class.getProtectionDomain().getCodeSource().getLocation().toURI());

      System.out.println("javaBin " + javaBin);
      System.out.println("currentJar " + currentJar);
      System.out.println("currentJar.getPath() " + currentJar.getPath());

      /* is it a jar file? */
      // if(!currentJar.getName().endsWith(".jar")){return;}

      try {

        // xmining = 0;
        // systemx.shutdown();

      } catch (Exception e) {
        e.printStackTrace();
      }

      /* Build command: java -jar application.jar */
      final ArrayList<String> command = new ArrayList<String>();
      command.add(javaBin);
      command.add("-jar");
      command.add("-Xms256m");
      command.add("-Xmx1024m");
      command.add(currentJar.getPath());

      final ProcessBuilder builder = new ProcessBuilder(command);
      builder.start();

      // try{Thread.sleep(10000);} catch (InterruptedException e){}

      // close and exit
      SystemTray.getSystemTray().remove(network.icon);
      System.exit(0);

    } // try
    catch (Exception e) {
      JOptionPane.showMessageDialog(null, e.getCause());
    }
  } // ******************************
示例#30
0
 public static Vector expandFileList(String[] files, boolean inclDirs) {
   Vector v = new Vector();
   if (files == null) return v;
   for (int i = 0; i < files.length; i++) v.add(new File(URLDecoder.decode(files[i])));
   for (int i = 0; i < v.size(); i++) {
     File f = (File) v.get(i);
     if (f.isDirectory()) {
       File[] fs = f.listFiles();
       for (int n = 0; n < fs.length; n++) v.add(fs[n]);
       if (!inclDirs) {
         v.remove(i);
         i--;
       }
     }
   }
   return v;
 }