/**
   * Find the Java File object based off of a starting directory.
   *
   * @param filename the filename to search for
   * @param startingDirectory the directory to start searching at
   * @return the File discovered
   * @throws FileNotFoundException will throw an exception if no file is found matching the criteria
   */
  public static File findAbsoluteFile(final String filename, final String startingDirectory)
      throws FileNotFoundException {
    File returnFile = null;
    try {
      File startingDirFile = new File(startingDirectory);
      Collection<File> files =
          FileUtils.listFiles(
              startingDirFile, FileFilterUtils.nameFileFilter(filename), TrueFileFilter.INSTANCE);

      if (files.size() == 0) {
        throw new FileNotFoundException(
            "file '" + filename + "' not found in directory '" + startingDirectory);
      } else if (files.size() > 1) {
        throw new FileNotFoundException(
            "multiple files with filename '"
                + filename
                + "' found in directory '"
                + startingDirectory);
      } else {
        for (File f : files) {
          returnFile = f;
        }
      }
    } catch (FileNotFoundException fnfe) {
      throw fnfe;
    } catch (Exception e) {
      throw new FileNotFoundException(
          "'" + filename + "' not found in directory '" + startingDirectory + "'");
    }
    return returnFile;
  }
 private File copyProject(String path) throws Exception {
   File projectDir = temp.newFolder();
   File originalProjectDir =
       new File(IssueModeAndReportsMediumTest.class.getResource(path).toURI());
   FileUtils.copyDirectory(
       originalProjectDir,
       projectDir,
       FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".sonar")));
   return projectDir;
 }
 /**
  * Cleaning up the generated files (shape and properties so that we recreate them).
  *
  * @throws FileNotFoundException
  * @throws IOException
  */
 private void cleanUp() throws FileNotFoundException, IOException {
   File dir = TestData.file(this, "heterogeneous/");
   File[] files =
       dir.listFiles(
           (FilenameFilter)
               FileFilterUtils.notFileFilter(
                   FileFilterUtils.or(
                       FileFilterUtils.or(
                           FileFilterUtils.suffixFileFilter("tif"),
                           FileFilterUtils.suffixFileFilter("aux")),
                       FileFilterUtils.nameFileFilter("datastore.properties"))));
   for (File file : files) {
     file.delete();
   }
 }
Example #4
0
  private void copyLocalNativeLibraries(
      final File localNativeLibrariesDirectory, final File destinationDirectory)
      throws MojoExecutionException {
    getLog().debug("Copying existing native libraries from " + localNativeLibrariesDirectory);
    try {

      IOFileFilter libSuffixFilter = FileFilterUtils.suffixFileFilter(".so");

      IOFileFilter gdbserverNameFilter = FileFilterUtils.nameFileFilter("gdbserver");
      IOFileFilter orFilter = FileFilterUtils.or(libSuffixFilter, gdbserverNameFilter);

      IOFileFilter libFiles = FileFilterUtils.and(FileFileFilter.FILE, orFilter);
      FileFilter filter = FileFilterUtils.or(DirectoryFileFilter.DIRECTORY, libFiles);
      org.apache.commons.io.FileUtils.copyDirectory(
          localNativeLibrariesDirectory, destinationDirectory, filter);

    } catch (IOException e) {
      getLog().error("Could not copy native libraries: " + e.getMessage(), e);
      throw new MojoExecutionException("Could not copy native dependency.", e);
    }
  }
Example #5
0
  @Test
  public void testImageReaderGOME2AncillaryFiles() throws Exception {
    final File file = TestData.file(this, "20130101.METOPA.GOME2.NO2.DUMMY.nc");
    final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
    assertTrue(unidataImageReaderSpi.canDecodeInput(file));
    NetCDFImageReader reader = null;
    try {

      // checking low level
      reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
      reader.setInput(file);
      int numImages = reader.getNumImages(true);
      assertEquals(1, numImages);
      LOGGER.info("Found " + numImages + " images.");
      for (int i = 0; i < numImages; i++) {
        Slice2DIndex sliceIndex = reader.getSlice2DIndex(i);
        assertNotNull(sliceIndex);
        spitOutSliceInformation(i, sliceIndex);
      }

      // check coverage names
      final List<Name> names = reader.getCoveragesNames();
      assertNotNull(names);
      assertTrue(!names.isEmpty());
      assertTrue(1 == names.size());
      assertEquals("NO2", names.get(0).toString());

      // checking slice catalog
      final CoverageSlicesCatalog cs = reader.getCatalog();
      assertNotNull(cs);

      MessageDigest md = MessageDigest.getInstance("SHA-1");
      md.update(file.getCanonicalPath().getBytes());
      String hashCode = AncillaryFileManager.convertToHex(md.digest());

      // Check if the auxiliary files directory is present
      File parentDir = file.getParentFile();

      String auxiliaryDirPath =
          parentDir
              + File.separator
              + "."
              + FilenameUtils.getBaseName(file.getName())
              + "_"
              + hashCode;

      File auxiliaryDir = new File(auxiliaryDirPath);

      assertTrue(auxiliaryDir.exists());
      assertTrue(auxiliaryDir.isDirectory());

      // Check if the Auxiliary File Directory contains the origin.txt file
      FilenameFilter nameFileFilter = FileFilterUtils.nameFileFilter("origin.txt");
      File[] files = auxiliaryDir.listFiles(nameFileFilter);
      assertTrue(files != null);
      assertTrue(files[0].exists());
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }