예제 #1
0
  @Override
  public void run(String... args) throws Exception {
    CommandLine line = this.commandLineParser.parse(this.options, args);
    String[] remainingArgs = line.getArgs();

    if (remainingArgs.length < 3 && !line.hasOption("file")
        || remainingArgs.length < 1 && line.hasOption("file")) {
      helpFormatter.printHelp("xmergel [OPTION] [file1 file2 ...] [result_file]", this.options);
      System.exit(1);
    }
    if (line.hasOption("debug")) {
      this.isDebug = true;
    }
    List<Path> filesToCombine = this.getPathsFromArgs(remainingArgs);
    if (line.hasOption("file")) {
      System.out.println("Finding files...");
      filesToCombine = this.getPathsFromFile(line.getOptionValue("file"), filesToCombine);
    }
    String output = remainingArgs[remainingArgs.length - 1];
    System.out.println("Merging files...");
    try {
      this.xmergel.setResultFile(output);
      this.xmergel.combine(filesToCombine);
    } catch (Exception e) {
      System.out.println("Error: " + e.getMessage());
      if (this.isDebug) {
        e.printStackTrace();
      }
      System.exit(1);
    }
    File fileOutput = Paths.get(output).toFile();
    System.out.println("Files have been merged in '" + fileOutput.getAbsolutePath() + "'.");
  }
예제 #2
0
 public static void main(String[] args) {
   String pathToDB = "test";
   String source = ".";
   if (args.length == 2 || args.length == 4) {
     for (int i = 0; i < args.length; i++) {
       if ("-db".equals(args[i])) {
         pathToDB = args[i + 1];
         i++;
       }
       if ("-source".equals(args[i])) {
         source = args[i + 1];
         i++;
       }
     }
   } else {
     System.err.println(
         "Usage: java "
             + MediaIndexer.class.getName()
             + "[-db path_to_db] -source folder_or_file_to_process");
     System.exit(0);
   }
   ThumbStore ts = new ThumbStore(pathToDB);
   MediaIndexer tb = new MediaIndexer(ts);
   File fs = new File(source);
   tb.processMTRoot(source);
 }
  /** Prints the structure for a given directory or file */
  public static void main(String[] args) throws IOException {
    if (args.length != 1) {
      printUsage();
      System.exit(-1);
    }

    String pathName = args[0];
    Path startingDir = Paths.get(pathName);

    PrintDirectoryStructureWithVisitor pdsv = new PrintDirectoryStructureWithVisitor();
    Files.walkFileTree(startingDir, pdsv);
  }
예제 #4
0
  private void parsestories() {

    try {

      List<String> lns =
          Files.readAllLines(Paths.get("datasets/" + name + ".tsv"), Charset.defaultCharset());

      for (String ln : lns) stories.add(Story.fromtext(ln));

    } catch (IOException e) {

      System.out.println("Error reading dataset.");
      System.exit(1);
    }
  }
예제 #5
0
 public static void work(BufferedReader ir) {
   TestParser testParser = new TestParser();
   try {
     PushbackReader r = new PushbackReader(ir, 1024);
     Parser parser = new Parser(new Lexer(r));
     Node syntaxTree = parser.parse();
     syntaxTree.apply(testParser);
   } catch (LexerException e) {
     System.out.println(e.getMessage() + ".");
   } catch (ParserException e) {
     System.out.println(e.getMessage() + ".");
   } catch (IOException e) {
     System.out.println(e.getMessage() + ".");
     System.exit(1);
   }
 }
예제 #6
0
 private List<Path> getPathsFromArgs(String... remainingArgs) {
   if (remainingArgs.length == 1) {
     return new ArrayList<Path>();
   }
   List<Path> filesToCombine = Lists.newArrayList();
   for (int i = 0; i < remainingArgs.length - 1; i++) {
     try {
       filesToCombine.add(Paths.get(remainingArgs[i]));
     } catch (Exception e) {
       System.out.println("Error: " + e.getMessage());
       if (this.isDebug) {
         e.printStackTrace();
       }
       System.exit(1);
     }
   }
   return filesToCombine;
 }
예제 #7
0
파일: Installer.java 프로젝트: suever/CTP
  /**
   * Class constructor; creates a new Installer object, displays a JFrame introducing the program,
   * allows the user to select an install directory, and copies files from the jar into the
   * directory.
   */
  public Installer(String args[]) {
    // Inputs are --install-dir INSTALL_DIR
    for (int k = 0; k < args.length; k = k + 2) {

      switch (args[k]) {
        case "--install-dir":
          directory = new File(args[k + 1]);
          System.out.println(directory);
          break;
        case "--port":
          port = Integer.parseInt(args[k + 1]);
          break;
      }
    }

    cp = new Stream();

    // Find the installer program so we can get to the files.
    installer = getInstallerProgramFile();
    String name = installer.getName();
    programName = (name.substring(0, name.indexOf("-"))).toUpperCase();

    // Get the installation information
    thisJava = System.getProperty("java.version");
    thisJavaBits = System.getProperty("sun.arch.data.model") + " bits";

    // Find the ImageIO Tools and get the version
    String javaHome = System.getProperty("java.home");
    File extDir = new File(javaHome);
    extDir = new File(extDir, "lib");
    extDir = new File(extDir, "ext");
    File clib = getFile(extDir, "clibwrapper_jiio", ".jar");
    File jai = getFile(extDir, "jai_imageio", ".jar");
    imageIOTools = (clib != null) && clib.exists() && (jai != null) && jai.exists();
    if (imageIOTools) {
      Hashtable<String, String> jaiManifest = getManifestAttributes(jai);
      imageIOVersion = jaiManifest.get("Implementation-Version");
    }

    // Get the CTP.jar parameters
    Hashtable<String, String> manifest = getJarManifestAttributes("/CTP/libraries/CTP.jar");
    programDate = manifest.get("Date");
    buildJava = manifest.get("Java-Version");

    // Get the util.jar parameters
    Hashtable<String, String> utilManifest = getJarManifestAttributes("/CTP/libraries/util.jar");
    utilJava = utilManifest.get("Java-Version");

    // Get the MIRC.jar parameters (if the plugin is present)
    Hashtable<String, String> mircManifest = getJarManifestAttributes("/CTP/libraries/MIRC.jar");
    if (mircManifest != null) {
      mircJava = mircManifest.get("Java-Version");
      mircDate = mircManifest.get("Date");
      mircVersion = mircManifest.get("Version");
    }

    // Set up the installation information for display
    if (imageIOVersion.equals("")) {
      imageIOVersion = "<b><font color=\"red\">not installed</font></b>";
    } else if (imageIOVersion.startsWith("1.0")) {
      imageIOVersion = "<b><font color=\"red\">" + imageIOVersion + "</font></b>";
    }
    if (thisJavaBits.startsWith("64")) {
      thisJavaBits = "<b><font color=\"red\">" + thisJavaBits + "</font></b>";
    }
    boolean javaOK = (thisJava.compareTo(buildJava) >= 0);
    javaOK &= (thisJava.compareTo(utilJava) >= 0);
    javaOK &= (thisJava.compareTo(mircJava) >= 0);
    if (!javaOK) {
      thisJava = "<b><font color=\"red\">" + thisJava + "</font></b>";
    }

    if (directory == null) exit();

    // Point to the parent of the directory in which to install the program.
    // so the copy process works correctly for directory trees.
    //
    // If the user has selected a directory named "CTP",
    // then assume that this is the directory in which
    // to install the program.
    //
    // If the directory is not CTP, see if it is called "RSNA" and contains
    // the Launcher program, in which case we can assume that it is an
    // installation that was done with Bill Weadock's all-in-one installer for Windows.
    //
    // If neither of those cases is true, then this is already the parent of the
    // directory in which to install the program
    if (directory.getName().equals("CTP")) {
      directory = directory.getParentFile();
    } else if (directory.getName().equals("RSNA")
        && (new File(directory, "Launcher.jar")).exists()) {
      suppressFirstPathElement = true;
    }

    // Cleanup old releases
    cleanup(directory);

    // Get a port for the server.
    if (port < 0) {
      if (checkServer(-port, false)) {
        System.err.println(
            "CTP appears to be running.\nPlease stop CTP and run the installer again.");
        System.exit(0);
      }
    }

    // Now install the files and report the results.
    int count =
        unpackZipFile(installer, "CTP", directory.getAbsolutePath(), suppressFirstPathElement);
    if (count > 0) {
      // Create the service installer batch files.
      updateWindowsServiceInstaller();
      updateLinuxServiceInstaller();

      // If this was a new installation, set up the config file and set the port
      installConfigFile(port);

      // Make any necessary changes in the config file to reflect schema evolution
      fixConfigSchema();

      System.out.println("Installation complete.");
      System.out.println(programName + " has been installed successfully.");
      System.out.println(count + " files were installed.");
    } else {
      System.err.println("Installation failed.");
      System.err.println(programName + " could not be fully installed.");
    }
    if (!programName.equals("ISN") && startRunner(new File(directory, "CTP"))) System.exit(0);
  }
예제 #8
0
파일: Installer.java 프로젝트: suever/CTP
 private static void exit() {
   System.exit(0);
 }
예제 #9
0
  public PalindromeTest() {
    ArrayList<String> words = new ArrayList<String>();
    ArrayList<String> palis;

    try {
      for (String line : Files.readAllLines(Paths.get("com/jsanders/web2"))) {
        words.add(line);
      }
    } catch (IOException ex) {
      System.out.println("IO error");
      System.exit(1);
    }

    palis = Palindrome.palindromes(words);
    assertEquals(palis.size(), 161, 0.01);

    int shortest = Word.shortestLength(words);
    assertEquals(shortest, 1, 0.01);

    int longest = Word.longestLength(words);
    assertEquals(longest, 24, 0.01);

    ArrayList<String> shortestWords = Word.shortestWords(words);
    assertEquals(shortestWords.size(), 52, 0.01);

    ArrayList<String> longestWords = Word.longestWords(words);
    assertEquals(longestWords.size(), 5, 0.01);

    int totalWords = Word.totalWords(words);
    double avgLen = Word.averageLength(words);

    assertEquals(totalWords, 235886, 0.01);
    assertEquals(avgLen, 9.56, 0.01);

    ArrayList<Double> letterFreq = Word.letterFrequency(words);
    assertEquals(letterFreq.get(0), 0.087, 0.01);

    double properFreq = Word.properFrequency(words);
    assertEquals(properFreq, 0.106, 0.01);

    ArrayList<Integer> startFreq = Word.startFrequency(words);
    assertEquals(startFreq.get(0), 17096, 0.01);

    ArrayList<String> sameStartEnd = Word.startEndWords(words);
    assertEquals(sameStartEnd.size(), 11505, 0.01);

    try {
      PrintWriter f = new PrintWriter("short.txt");
      for (String w : shortestWords) f.println(w);
      f.close();

      f = new PrintWriter("long.txt");
      for (String w : longestWords) f.println(w);
      f.close();

      f = new PrintWriter("same.txt");
      for (String w : sameStartEnd) f.println(w);
      f.close();

      f = new PrintWriter("statistics.txt");
      f.println("avg word len: " + avgLen);
      f.println("freq of letters: " + letterFreq);
      f.println("freq of proper nouns/names: " + properFreq);
      f.println("words that start with each letter:: " + startFreq);

      f.close();
    } catch (IOException ex) {
      System.out.println("IO error");
      System.exit(1);
    }
  }
 static void usage() {
   System.err.println("usage: java Test.WatchDir [-r] dir");
   System.exit(-1);
 }
예제 #11
0
  //
  // обработка исходящего каталога АБС
  //
  public boolean processOutDirectory() {
    boolean result = true;
    try {

      //
      // читаем control.xml
      //
      File controlFile = new File(ABS_OUTPUT_DIR + "/control.xml");
      if (!controlFile.exists()) {
        logger.error("Нет файла " + controlFile.getName());
        if (new File(ABS_OUTPUT_DIR + "/control.zip").exists()) {
          logger.info("Обнаружен архив " + ABS_OUTPUT_DIR + "/control.zip");
          return true;
        }
        return false;
      }
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document controlDoc = builder.parse(controlFile);
      // готовимся изменять файл
      XPath searchPath = XPathFactory.newInstance().newXPath();

      // ищем каталоги с контейнерами
      File[] directoryList = (new File(ABS_OUTPUT_DIR)).listFiles(p -> p.isDirectory());

      //
      // просматриваем каталоги типа FILES/out/....
      //
      for (int i = 0; i < directoryList.length; i++) {
        //
        // в каталоге должен быть файл data.zip и файлы-вложения
        // файл data.zip нужно подписать и зазиповать
        //
        logger.info("Обрабатываем каталог " + directoryList[i].getAbsolutePath());
        //
        // просматриваем содержимое каталога с контейнером
        //
        File[] currentDir = (directoryList[i]).listFiles(p -> p.isFile());
        //
        // создаем zip-file
        //
        File zip = new File(directoryList[i].getAbsolutePath() + "/data_" + i + ".zip");
        logger.info("Создаем архив " + zip.getAbsolutePath());
        FileOutputStream zipStream = new FileOutputStream(zip);
        ZipOutputStream dataZip = new ZipOutputStream(zipStream);
        for (File curFile : currentDir) {
          if ("data.xml.sig".equals(curFile.getName())) continue;
          appendZipFile(dataZip, curFile);
          //
          // для файла data.zip создаем цифровую подпись и записываем файл с подписью в архив
          //
          if ("data.xml".equals(curFile.getName())) {
            fileSigner.cades(curFile.getAbsolutePath());
            String fName = curFile.getAbsolutePath();
            File signFile = new File(fName.substring(0, fName.length() - 3) + "sign");
            appendZipFile(dataZip, signFile);
            signFile.delete();
          }
          //
          // удаляем файл после включения в архив
          //
          curFile.delete();
        }
        //
        // закрываем архив и его поток
        //
        dataZip.close();
        zipStream.close();
        logger.info("Запись в архив " + zip.getAbsolutePath() + " завершена");
        //
        // вычисляем crc32
        //
        long crc32 = Utils.calculateCRC32(zip);
        long zipSize = zip.length();
        //
        // в файле control.xml ищем соответствующий узел контейнера и меняем его атрибуты
        //
        String xpathQuery = "//Containers[@ReqUID='" + directoryList[i].getName() + "']";
        Node containerNode =
            (Node) searchPath.evaluate(xpathQuery, controlDoc, XPathConstants.NODE);
        if (containerNode == null) {
          logger.error(
              "В файле control.xml  не найдено описание для контейнера "
                  + directoryList[i].getName());
          System.exit(1);
        }
        Element containerElement = (Element) containerNode;
        containerElement.setAttribute("name", zip.getName());
        containerElement.setAttribute("size", zipSize + "");
        containerElement.setAttribute("CRC", crc32 + "");
      }
      // сохраняем control.xml
      DOMSource domSource = new DOMSource(controlDoc);
      StreamResult streamResult = new StreamResult(controlFile);
      Transformer transformer = TransformerFactory.newInstance().newTransformer();
      transformer.transform(domSource, streamResult);
      transformer.reset();
      //
      // подписываем файл
      //
      fileSigner.cades(controlFile.getAbsolutePath());
      //
      // записываем файл control.xml и подпись в архив
      //
      File zip = new File(ABS_OUTPUT_DIR + "/control.zip");
      logger.info("Создаем архив " + zip.getAbsolutePath());
      FileOutputStream zipStream = new FileOutputStream(zip);
      ZipOutputStream dataZip = new ZipOutputStream(zipStream);
      //
      // дописываем управляющий файл
      //
      File cFile = new File(ABS_OUTPUT_DIR + "/control.xml");
      appendZipFile(dataZip, cFile);
      cFile.delete();
      //
      // дописываем подпись
      //
      cFile = new File(ABS_OUTPUT_DIR + "/control.sign");
      appendZipFile(dataZip, cFile);
      cFile.delete();
      logger.info("Запись в архив " + zip.getAbsolutePath() + " завершена");
      //
      // закрываем архив и его поток
      //
      dataZip.close();
      zipStream.close();
    } catch (Exception e) {
      logger.error(e.getMessage());
      e.printStackTrace();
    }

    return result;
  }
예제 #12
0
 static void error() {
   System.err.println("Error: java Main <path>");
   System.exit(-1);
 }