Пример #1
0
  @Test
  public void shouldSyncReposToDisk() throws ClassNotFoundException, IOException {
    SubsetSizeRepo subsetRepo = factory.createSubsetRepo("dev", LATEST_VERSION);
    SuiteTimeRepo suiteTimeRepo = factory.createSuiteTimeRepo("dev", LATEST_VERSION);
    SuiteResultRepo suiteResultRepo = factory.createSuiteResultRepo("dev", LATEST_VERSION);
    subsetRepo.add(new SubsetSizeEntry(10));
    suiteTimeRepo.update(new SuiteTimeEntry("foo.bar.Quux", 25));
    suiteResultRepo.update(new SuiteResultEntry("foo.bar.Baz", true));

    assertThat(
        "No files should exist as sync on this factory has never been called.",
        baseDir.list().length,
        is(0));

    factory.syncReposToDisk();

    assertThat(
        "Files should exist as sync on this factory has been called.",
        baseDir.list().length,
        is(3));

    assertContentIs(EntryRepoFactory.name("dev", LATEST_VERSION, SUBSET_SIZE), "10");
    assertContentIs(EntryRepoFactory.name("dev", LATEST_VERSION, SUITE_TIME), "foo.bar.Quux: 25");
    assertContentIs(
        EntryRepoFactory.name("dev", LATEST_VERSION, SUITE_RESULT), "foo.bar.Baz: true");
  }
Пример #2
0
 public static void main(String[] args) {
   File path = new File(".");
   String[] list;
   if (args.length == 0) list = path.list();
   else list = path.list(new DirFilter(args[0]));
   Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
   for (String dirItem : list) System.out.println(dirItem);
 }
Пример #3
0
  /*................................................................................................*/
  private boolean hireFillers(String directoryPath) {
    String[] files = directory.list();
    String treePath;
    for (int i = 0; i < files.length; i++) {
      if (files[i] != null) {
        String fileLowerCase = files[i].toLowerCase();
        if (fileLowerCase.endsWith(".nex") || fileLowerCase.endsWith(".nexus")) {
          treePath = directoryPath + MesquiteFile.fileSeparator + files[i];
          File treeFile = new File(treePath);
          String treeFileName = treeFile.getName();
          if (StringUtil.blank(treeFileName)) {
            return false;
          }
          TreeBlockFiller newFiller;
          newFiller =
              (TreeBlockFiller)
                  hireNamedEmployee(TreeBlockFiller.class, "#SampleOneTreeFromFile"); // treePath);
          if (newFiller != null) {
            if (((SampleOneTreeFromFile) newFiller).setFilePath(treePath)
                && ((SampleOneTreeFromFile) newFiller).processFile()) {
              fillerTasks.addElement(newFiller);
            } else
              Debugg.println(
                  "Filler "
                      + i
                      + " processFile = "
                      + ((SampleOneTreeFromFile) newFiller).processFile());
          }
        }
      }
    }

    return true;
  }
Пример #4
0
  private static void addRSPack(boolean refreash) {
    File rspack = new File(getConfigFolder(), "/resources");
    if (!rspack.exists()) return;

    if (!Arrays.asList(rspack.list()).contains("pack.mcmeta")) {
      try {
        JsonWriter writer = new JsonWriter(new FileWriter(new File(rspack, "pack.mcmeta")));
        writer.beginObject();
        writer.name("pack");
        writer.beginObject();
        writer.name("pack_format").value(1);
        writer.name("description").value("Draconic Evolution GUI Images");
        writer.endObject();
        writer.endObject();
        writer.close();
      } catch (IOException e) {
        LogHelper.error("Error creating pack.mcmeta");
        e.printStackTrace();
      }
    }

    Field f =
        ReflectionHelper.findField(Minecraft.class, "defaultResourcePacks", "field_110449_ao");
    f.setAccessible(true);
    try {
      List defaultResourcePacks = (List) f.get(Minecraft.getMinecraft());
      defaultResourcePacks.add(new FolderResourcePack(rspack));

      f.set(Minecraft.getMinecraft(), defaultResourcePacks);
      LogHelper.info("RS Added");
      if (refreash) Minecraft.getMinecraft().refreshResources();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }
  }
Пример #5
0
 /**
  * Expands list of files to process into full list of all files that can be found by recursively
  * descending directories.
  */
 void expand(File dir, String[] files, boolean isUpdate) {
   if (files == null) {
     return;
   }
   for (int i = 0; i < files.length; i++) {
     File f;
     if (dir == null) {
       f = new File(files[i]);
     } else {
       f = new File(dir, files[i]);
     }
     if (f.isFile()) {
       if (entries.add(f)) {
         if (isUpdate) entryMap.put(entryName(f.getPath()), f);
       }
     } else if (f.isDirectory()) {
       if (entries.add(f)) {
         if (isUpdate) {
           String dirPath = f.getPath();
           dirPath = (dirPath.endsWith(File.separator)) ? dirPath : (dirPath + File.separator);
           entryMap.put(entryName(dirPath), f);
         }
         expand(f, f.list(), isUpdate);
       }
     } else {
       error(formatMsg("error.nosuch.fileordir", String.valueOf(f)));
       ok = false;
     }
   }
 }
Пример #6
0
    protected void setData(String strChecksum) {
      String strValue = (String) m_cmbPath.getSelectedItem();
      if (strValue == null || strValue.equals("")) return;

      m_cmbChecksum.removeAllItems();

      String strPath = strValue.substring(strValue.lastIndexOf("/") + 1);
      strPath = UtilB.unixPathToWindows(FileUtil.SYS_VNMR + "/p11/checksums/" + strPath);
      strPath = FileUtil.openPath(strPath);
      if (strPath != null) {
        File file = new File(strPath);
        String[] files = file.list();
        int nSize = files.length;
        for (int i = 0; i < nSize; i++) {
          String strfile = files[i];
          m_cmbChecksum.addItem(strfile);
        }

        int nIndex = strChecksum.lastIndexOf("/");
        if (nIndex < 0) nIndex = strChecksum.lastIndexOf(File.separator);
        if (nIndex + 1 < strChecksum.length()) strChecksum = strChecksum.substring(nIndex + 1);

        m_cmbChecksum.setSelectedItem(strChecksum);
      }
    }
  private void copyAllFilesToLogDir(File node, File parent) throws IOException {
    if (!node.getAbsoluteFile().equals(parent.getAbsoluteFile())
        && node.isFile()
        && !node.getParentFile().equals(parent)) {
      String fileNamePrefix = node.getName().substring(0, node.getName().lastIndexOf('.'));
      String fileNameSuffix = node.getName().substring(node.getName().lastIndexOf('.'));
      String newFilePath =
          node.getParentFile().getAbsolutePath()
              + File.separator
              + fileNamePrefix.replace(".", "_")
              + fileNameSuffix;

      File newNode = new File(newFilePath);
      if (node.renameTo(newNode)) {
        FileUtils.copyFileToDirectory(newNode, parent);
      }
    }
    if (node.isDirectory()) {
      String[] subNote = node.list();
      for (String filename : subNote) {
        copyAllFilesToLogDir(new File(node, filename), parent);
      }
      if (!node.equals(parent)) {
        FileUtils.deleteDirectory(node);
      }
    }
  }
Пример #8
0
 private void LoadQueriesBtnMouseClicked(
     java.awt.event.MouseEvent evt) { // GEN-FIRST:event_LoadQueriesBtnMouseClicked
   // Algorithm
   /*
    * Goto queries' directory and load all queryfile.query to Combobox
    * Change local directory to repository diretory
    * List all file there
    * Try to load all file and add to combobox
    *
    *
    */
   String sQueryRepositoryPath = "/home/natuan/Documents/OntologyMysql/QueriesRepository/";
   File dir = new File(sQueryRepositoryPath);
   String[] children = dir.list();
   if (children == null) {
     // Either dir does not exist or is not a directory
   } else {
     System.out.println("list files");
     for (int i = 0; i < children.length; i++) {
       // Get filename of file or directory
       String filename = children[i];
       String sContent = ReadWholeFileToString(sQueryRepositoryPath + filename);
       queryList.add(sContent);
       QueriesCmb.addItem(filename);
       SparqlTxtArea.setText(sContent);
       //   System.out.println(filename);
     }
     QueriesCmb.setSelectedIndex(children.length - 1);
   }
 } // GEN-LAST:event_LoadQueriesBtnMouseClicked
  /** @param args the command line arguments */
  public static void main(String[] args) throws Exception {

    // boolean Chinese = true;
    // File f = new File("C:/Users/Xin/Documents/opt/allign-zh-trans");
    // File out = new File("C:/Users/Xin/Documents/opt/out-zh");
    boolean Chinese = false;
    File f = new File("C:/Users/Xin/Documents/optest/allign-es-trans");
    File out = new File("C:/Users/Xin/Documents/optest/out-es");
    File seg = new File("C:/Users/Xin/Documents/optest/segmented-zh");

    out.mkdirs();
    seg.mkdirs();

    for (String name : f.list()) {

      String fullName = f.getAbsolutePath() + "/" + name;
      String outName = out.getAbsolutePath() + "/" + name;

      if (Chinese == true) {

        String segName = seg.getAbsolutePath() + "/" + name;
        ChineseSegment(fullName, segName);
        BlEUClaculatorOnefile(segName, outName, Chinese);
      } else {

        BlEUClaculatorOnefile(fullName, outName, Chinese);
      }
    }
  }
Пример #10
0
  public static List<Library> list(File folder) {
    List<Library> libraries = new ArrayList<Library>();
    List<File> librariesFolders = new ArrayList<File>();
    librariesFolders.addAll(discover(folder));

    for (File baseFolder : librariesFolders) {
      libraries.add(new Library(baseFolder));
    }

    // Support libraries inside of one level of subfolders? I believe this was
    // the compromise for supporting library groups, but probably a bad idea
    // because it's not compatible with the Manager.
    String[] folderNames = folder.list(junkFolderFilter);
    if (folderNames != null) {
      for (String subfolderName : folderNames) {
        File subfolder = new File(folder, subfolderName);

        if (!librariesFolders.contains(subfolder)) {
          List<File> discoveredLibFolders = discover(subfolder);
          for (File discoveredFolder : discoveredLibFolders) {
            libraries.add(new Library(discoveredFolder, subfolderName));
          }
        }
      }
    }
    return libraries;
  }
Пример #11
0
 protected void eraseFiles() {
   File tmpdirF = new File(tmpdir);
   String[] files = tmpdirF.list();
   for (int i = 0; files != null && i < files.length; i++) {
     new File(tmpdir + "/" + files[i]).delete();
   }
 }
  protected void getImages() {
    File directory = new File(this.saveDirectory);

    // BufferedImage img = null;

    images = new ArrayList<String>();
    if (directory.exists() && directory.isDirectory()) {
      // File[] files = directory.listFiles();
      String[] files = directory.list();

      for (int i = 0; i < files.length; i++) {
        // System.out.println(files[i]);
        // try {
        // if(files[i].getName().startsWith("cam"))
        if (files[i].startsWith("cam")) {
          // Windows spesific
          images.add(this.saveDirectory + "\\" + files[i]);
          /*
          img = ImageIO.read(files[i]);
          images.add(img);*/
        }
        // } catch (IOException e) {
        //	System.err.println("Failed on reading image. IOException.");
        // }
      }
    }

    System.out.println("Total image count = " + images.size());
    gotImages = true;
  }
Пример #13
0
 private void openDirectory(File f, String path) {
   if (path == null) return;
   if (!(path.endsWith(File.separator) || path.endsWith("/"))) path += File.separator;
   String[] names = f.list();
   names = (new FolderOpener()).trimFileList(names);
   if (names == null) return;
   String msg = "Open all " + names.length + " images in \"" + f.getName() + "\" as a stack?";
   GenericDialog gd = new GenericDialog("Open Folder");
   gd.setInsets(10, 5, 0);
   gd.addMessage(msg);
   gd.setInsets(15, 35, 0);
   gd.addCheckbox("Convert to RGB", convertToRGB);
   gd.setInsets(0, 35, 0);
   gd.addCheckbox("Use Virtual Stack", virtualStack);
   gd.enableYesNoCancel();
   gd.showDialog();
   if (gd.wasCanceled()) return;
   if (gd.wasOKed()) {
     convertToRGB = gd.getNextBoolean();
     virtualStack = gd.getNextBoolean();
     String options = " sort";
     if (convertToRGB) options += " convert_to_rgb";
     if (virtualStack) options += " use";
     IJ.run("Image Sequence...", "open=[" + path + "]" + options);
     DirectoryChooser.setDefaultDirectory(path);
   } else {
     for (int k = 0; k < names.length; k++) {
       IJ.redirectErrorMessages();
       if (!names[k].startsWith(".")) (new Opener()).open(path + names[k]);
     }
   }
   IJ.register(DragAndDrop.class);
 }
Пример #14
0
 public void init(File testDir) {
   // get files to process
   List<InputOutput> temp = new ArrayList<InputOutput>();
   String name;
   for (String file : testDir.list()) {
     if (null != commonInputFile) {
       if (file.equals(testName + ".output")) {
         temp.add(new InputOutput((new File(testDir, testName)).toString(), true));
         commonInputFile = (new File(testDir, commonInputFile)).toString();
       }
     } else {
       if (file.endsWith(".input") && file.startsWith(testName + "-")) {
         name = file.substring(0, file.length() - 6);
         temp.add(
             new InputOutput(
                 (new File(testDir, name)).toString(),
                 new File(testDir, name + ".output").exists()));
       }
     }
   }
   // When a common input file is specified, but no output file exists, add
   // a single InputOutput for the common input file.
   if (null != commonInputFile && 0 == temp.size()) {
     temp.add(new InputOutput(null, false));
   }
   setInputOutput(temp);
   testPath = testDir;
 }
Пример #15
0
 private void analyze(File f) throws IOException {
   String[] list = f.list();
   if (list != null) {
     for (int i = 0; i < list.length; i++)
       analyze(new File(f.getCanonicalPath() + "\\" + list[i]));
   } else {
     if (f.getName().endsWith(".ma") || f.getName().endsWith(".fg")) count(f);
   }
 }
Пример #16
0
 protected void eraseFiles(final String filesEndingWith) {
   File tmpdirF = new File(tmpdir);
   String[] files = tmpdirF.list();
   for (int i = 0; files != null && i < files.length; i++) {
     if (files[i].endsWith(filesEndingWith)) {
       new File(tmpdir + "/" + files[i]).delete();
     }
   }
 }
 static int countPlugins(String pluginsPath) {
   File configuredPluginsDir = new File(pluginsPath);
   if (configuredPluginsDir.exists()) {
     String[] list = configuredPluginsDir.list();
     if (list != null) {
       return list.length;
     }
   }
   return 0;
 }
Пример #18
0
 private static String[] getDirFiles(String localDir) throws Exception {
   File temp = new File(localDir);
   String[] listOfFiles = temp.list();
   if (listOfFiles != null) {
     return listOfFiles;
   } else {
     System.out.println("Local Path Doesn't Exist");
     return null;
   }
 }
 private void blossomDirectory(File dir) throws IOException {
   // System.out.println(">> blossomDirectory() on " + dir.getPath());
   String canonicalPath = dir.getCanonicalPath();
   String[] listing = (filter == null ? dir.list() : dir.list(filter));
   for (int i = listing.length; --i >= 0; ) {
     // System.out.println(">> listing: " + listing[i]);
     if (filter == null || filter.accept(dir, listing[i])) {
       String name = (canonical ? canonicalPath : dir.getPath()) + File.separator + listing[i];
       File file = new File(name);
       // System.out.println(">> parent: " + dir.getName());
       // System.out.println(">> created file: " + file.getPath());
       if (file.isFile()) files.push(file);
       else // dir
       {
         if (!markedDirex.containsKey(file.getCanonicalPath())) direx.push(file);
       }
     }
   }
   markedDirex.put(canonicalPath, dummy);
 }
Пример #20
0
  @Test
  public void should_NOT_SyncReposToDisk_unlessDirty() throws ClassNotFoundException, IOException {
    SubsetSizeRepo subsetRepo = factory.createSubsetRepo("dev", LATEST_VERSION);
    SuiteTimeRepo suiteTimeRepo = factory.createSuiteTimeRepo("dev", LATEST_VERSION);
    SuiteResultRepo suiteResultRepo = factory.createSuiteResultRepo("dev", LATEST_VERSION);
    subsetRepo.add(new SubsetSizeEntry(10));
    suiteTimeRepo.update(new SuiteTimeEntry("foo.bar.Quux", 25));
    suiteResultRepo.update(new SuiteResultEntry("foo.bar.Baz", true));

    factory.syncReposToDisk();

    FileUtils.cleanDirectory(baseDir);

    assertThat(baseDir.list().length, is(0));

    factory.syncReposToDisk();

    assertThat(
        "No files should exist as no repos were dirty when sync-to-disk was called.",
        baseDir.list().length,
        is(0));

    subsetRepo.add(new SubsetSizeEntry(21));
    suiteTimeRepo.update(new SuiteTimeEntry("foo.bar.Bang", 35));
    suiteResultRepo.update(new SuiteResultEntry("foo.bar.Baz", true));

    factory.syncReposToDisk();

    assertThat(
        "Files should exist as sync on this factory has been called.",
        baseDir.list().length,
        is(3));

    assertContentIs(EntryRepoFactory.name("dev", LATEST_VERSION, SUBSET_SIZE), "10", "21");
    assertContentIs(
        EntryRepoFactory.name("dev", LATEST_VERSION, SUITE_TIME),
        "foo.bar.Quux: 25",
        "foo.bar.Bang: 35");
    assertContentIs(
        EntryRepoFactory.name("dev", LATEST_VERSION, SUITE_RESULT), "foo.bar.Baz: true");
  }
 public static String[] getDirectoryNames(String path) {
   File fileName = new File(path);
   String[] directoryNamesArr =
       fileName.list(
           new FilenameFilter() {
             @Override
             public boolean accept(File current, String name) {
               return new File(current, name).isDirectory();
             }
           });
   log.info("Directories inside " + path + " are " + Arrays.toString(directoryNamesArr));
   return directoryNamesArr;
 }
Пример #22
0
  private void addItems(
      Context c, Collection[] mycollections, String sourceDir, String mapFile, boolean template)
      throws Exception {
    Map<String, String> skipItems =
        new HashMap<String, String>(); // set of items to skip if in 'resume'
    // mode

    System.out.println("Adding items from directory: " + sourceDir);
    System.out.println("Generating mapfile: " + mapFile);

    // create the mapfile
    File outFile = null;

    if (!isTest) {
      // get the directory names of items to skip (will be in keys of
      // hash)
      if (isResume) {
        skipItems = readMapFile(mapFile);
      }

      // sneaky isResume == true means open file in append mode
      outFile = new File(mapFile);
      mapOut = new PrintWriter(new FileWriter(outFile, isResume));

      if (mapOut == null) {
        throw new Exception("can't open mapfile: " + mapFile);
      }
    }

    // open and process the source directory
    File d = new java.io.File(sourceDir);

    if (d == null || !d.isDirectory()) {
      System.out.println("Error, cannot open source directory " + sourceDir);
      System.exit(1);
    }

    String[] dircontents = d.list(directoryFilter);

    Arrays.sort(dircontents);

    for (int i = 0; i < dircontents.length; i++) {
      if (skipItems.containsKey(dircontents[i])) {
        System.out.println("Skipping import of " + dircontents[i]);
      } else {
        addItem(c, mycollections, sourceDir, dircontents[i], mapOut, template);
        System.out.println(i + " " + dircontents[i]);
        c.clearCache();
      }
    }
  }
Пример #23
0
 void loadDirectory(File file) {
   String[] entries = file.list();
   for (int i = 0; i < entries.length; i++) {
     String entry = entries[i];
     File f = new File(file, entry);
     if (!f.isDirectory()) {
       if (f.getAbsolutePath().endsWith(".java")) {
         files.put(f, loadFile(f));
       }
     } else {
       loadDirectory(f);
     }
   }
 }
Пример #24
0
  /**
   * Test load all sg ffiles.
   *
   * @throws IOException Signals that an I/O exception has occurred.
   */
  public void testLoadAllSGFfiles() throws IOException {
    Stack<String> files = new Stack<String>();
    files.push("sgf/2004-12");
    int count = 0;

    while (files.size() > 0 && count <= 10) {
      String filename = files.pop();
      File file = new File(filename);
      count++;
      if (DEBUG) System.err.println("examining \"" + filename + "\"");
      if (file.exists()) {
        if (!file.isDirectory()) {
          // System.err.println("\"" + filename + "\" is not a
          // directory, parsing as an SGF file");

          Game game = Game.loadFromFile(file);
          if (game.getSize() == 19) {
            Iterator<Move> i = game.getMoves();
            Move move = null;
            BoardI board = new SmallerBoard(game.getSize());
            // System.err.println("board size is: \"" +
            // goGame.getSize()
            // + "\"");
            while (i.hasNext()) {
              move = i.next();
              assertNotNull(move);
              // System.err.print("move: \"" + move + "\"");
              // assertTrue("" + board + "\n" +
              // move.toString(),board.isLegalMove(move));
              board = board.newBoard(move);
              // System.err.println(" board size is: \"" +
              // board.getSize() + "\"");
            }
            // System.err.println();

          }
        } else {
          if (DEBUG) System.err.println("\"" + filename + "\" is a directory");
          if (!file.getName().contains(".svn")) {
            String[] children = file.list();
            for (int i = 0; i < children.length; i++) {
              // System.err.println("pushing \"" + children[i] +
              // "\"");
              files.push(filename + "/" + children[i]);
            }
          }
        }
      }
    }
  }
Пример #25
0
 protected JMenu createImagesMenu() {
   CommandMenu menu = new CommandMenu("Images");
   File imagesDirectory = new File(fgSampleImagesPath);
   try {
     String[] list = imagesDirectory.list();
     for (int i = 0; i < list.length; i++) {
       String name = list[i];
       String path = fgSampleImagesResourcePath + name;
       menu.add(new UndoableCommand(new InsertImageCommand(name, path, this)));
     }
   } catch (Exception e) {
   }
   return menu;
 }
Пример #26
0
  private boolean deleteDir(File dir) {
    if (dir.isDirectory()) {
      String[] children = dir.list();
      for (int i = 0; i < children.length; i++) {
        boolean success = deleteDir(new File(dir, children[i]));
        if (!success) {
          return false;
        }
      }
    }

    // The directory is now empty so delete it
    return dir.delete();
  }
Пример #27
0
  /**
   * Copy a directory recursively Source:
   * http://subversivebytes.wordpress.com/2012/11/05/java-copy-directory-\ recursive-delete/
   *
   * @param sourceLocation the source location.
   * @param targetLocation the target location.
   * @throws IOException if something goes wrong.
   */
  public static void copyDirectory(File sourceLocation, File targetLocation) throws IOException {
    if (sourceLocation.isDirectory()) {
      if (!targetLocation.exists() && !targetLocation.mkdir()) {
        throw new IOException("Can not create temp. directory.");
      }

      // Process all the elements of the directory.
      String[] children = sourceLocation.list();
      for (int i = 0; i < children.length; ++i) {
        copyDirectory(new File(sourceLocation, children[i]), new File(targetLocation, children[i]));
      }
    } else {
      copyFile(sourceLocation, targetLocation);
    }
  }
Пример #28
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);
 }
  /** Clears the archive directory. */
  private void clearCurrentDirectory() {
    File directory = new File(getCurrentDirectory());

    if (directory.exists() && directory.isDirectory()) {
      String[] listing = directory.list();

      for (String aListing : listing) {
        File file = new File(getCurrentDirectory(), aListing);
        boolean deleted = file.delete();
      }
    }

    if (!directory.exists()) {
      directory.mkdirs();
    }
  }
  /** Clears the archive directory. */
  public void clearArchiveDirectory() {
    File directory = new File(getArchiveDirectory());

    if (directory.exists() && directory.isDirectory()) {
      String[] listing = directory.list();

      for (String aListing : listing) {
        File file = new File(getArchiveDirectory(), aListing);
        file.delete();
      }
    }

    if (!directory.exists()) {
      directory.mkdirs();
    }
  }