Esempio n. 1
0
  /**
   * Returns list of mapped files, that should be transformed. Files can by specified via attributes
   * (srcFile, srcDir) or resources (FileSet, FileList, DirSet, etc). Mapped file represents input
   * and output file for transformation.
   *
   * @return list of mapped files
   */
  public List<MappedFile> getMappedFiles() {
    mappedFiles.clear();

    // one src file
    if (getSrcFile() != null) {
      addMappedFile(getSrcFile());
    }

    if (getSrcDir() != null) {
      addMappedFile(getSrcDir());
    }

    Iterator element = resources.iterator();
    while (element.hasNext()) {
      ResourceCollection rc = (ResourceCollection) element.next();
      if (rc instanceof FileSet && rc.isFilesystemOnly()) {
        FileSet fs = (FileSet) rc;
        File fromDir = fs.getDir(getProject());

        DirectoryScanner ds;
        try {
          ds = fs.getDirectoryScanner(getProject());
        } catch (BuildException ex) {
          log("Could not scan directory " + fromDir, ex, Project.MSG_ERR);
          continue;
        }

        for (String f : ds.getIncludedFiles()) {
          addMappedFile(new File(fromDir + System.getProperty("file.separator") + f), fromDir);
        }
      } else {
        if (!rc.isFilesystemOnly()) {
          log("Only filesystem resources are supported", Project.MSG_WARN);
          continue;
        }
        Iterator rcIt = rc.iterator();
        while (rcIt.hasNext()) {
          Resource r = (Resource) rcIt.next();
          if (!r.isExists()) {
            log("Could not find resource " + r.toLongString(), Project.MSG_VERBOSE);
            continue;
          }

          if (r instanceof FileResource) {
            FileResource fr = (FileResource) r;
            addMappedFile(fr.getFile(), fr.getBaseDir());
          } else {
            log(
                "Only file resources are supported (" + r.getClass().getSimpleName() + " found)",
                Project.MSG_WARN);
            continue;
          }
        }
      }
    }

    return mappedFiles;
  }
  @Override
  public void putImage(TaggedImage taggedImage) throws MMException {
    if (!newDataSet_) {
      throw new MMException("This ImageFileManager is read-only.");
    }
    int fileSetIndex = 0;
    if (splitByXYPosition_) {
      try {
        fileSetIndex = MDUtils.getPositionIndex(taggedImage.tags);
      } catch (JSONException ex) {
        ReportingUtils.logError(ex);
      }
    }
    String label = MDUtils.getLabel(taggedImage.tags);
    if (fileSets_ == null) {
      try {
        fileSets_ = new HashMap<Integer, FileSet>();
        createDirectory(directory_);
      } catch (Exception ex) {
        ReportingUtils.logError(ex);
      }
    }

    if (omeTiff_) {
      if (omeMetadata_ == null) {
        omeMetadata_ = new OMEMetadata(this);
      }
    }

    if (fileSets_.get(fileSetIndex) == null) {
      fileSets_.put(fileSetIndex, new FileSet(taggedImage.tags, this));
    }
    FileSet set = fileSets_.get(fileSetIndex);
    try {
      set.writeImage(taggedImage);
    } catch (IOException ex) {
      ReportingUtils.showError("problem writing image to file");
    }
    tiffReadersByLabel_.put(label, set.getCurrentReader());

    int frame;
    try {
      frame = MDUtils.getFrameIndex(taggedImage.tags);
    } catch (JSONException ex) {
      frame = 0;
    }
    lastFrameOpenedDataSet_ = Math.max(frame, lastFrameOpenedDataSet_);
    cached_.add(taggedImage, label);
  }
 /**
  * Call this function when no more images are expected Finishes writing the metadata file and
  * closes it. After calling this function, the imagestorage is read-only
  */
 @Override
 public synchronized void finished() {
   if (finished_) {
     return;
   }
   newDataSet_ = false;
   try {
     if (fileSets_ != null) {
       for (FileSet p : fileSets_.values()) {
         p.finishAbortedAcqIfNeeded();
       }
       for (FileSet p : fileSets_.values()) {
         p.finished();
       }
     }
   } catch (IOException ex) {
     ReportingUtils.logError(ex);
   }
   finished_ = true;
 }