Exemplo n.º 1
0
  @Override
  public DecodeQualification getDecodeQualification(Object input) {
    String filename = new File(input.toString()).getName();
    if (!isLandsatMSSFilename(filename)
        && !isLandsat4Filename(filename)
        && !isLandsat5Filename(filename)
        && !isLandsat7Filename(filename)
        && !isLandsat8Filename(filename)
        && !isLandsat5LegacyFilename(filename)
        && !isLandsat7LegacyFilename(filename)) {
      return DecodeQualification.UNABLE;
    }

    VirtualDir virtualDir;
    try {
      virtualDir = getInput(input);
    } catch (IOException e) {
      return DecodeQualification.UNABLE;
    }

    if (virtualDir == null) {
      return DecodeQualification.UNABLE;
    }

    String[] allFiles;
    try {
      allFiles = virtualDir.listAllFiles();
      if (allFiles == null || allFiles.length == 0) {
        return DecodeQualification.UNABLE;
      }
    } catch (IOException e) {
      return DecodeQualification.UNABLE;
    }

    for (String filePath : allFiles) {
      try {
        if (isMetadataFilename(new File(filePath).getName())) {
          InputStream inputStream = virtualDir.getInputStream(filePath);
          if (isMetadataFile(inputStream)) {
            return DecodeQualification.INTENDED;
          }
        }
      } catch (IOException ignore) {
        // file is broken, but be tolerant here
      }
    }
    // didn't find the expected metadata file
    return DecodeQualification.UNABLE;
  }
Exemplo n.º 2
0
  static VirtualDir getInput(Object input) throws IOException {
    File inputFile = getFileInput(input);

    if (inputFile == null) {
      throw new IOException("Unknown input type.");
    }

    if (inputFile.isFile() && !isCompressedFile(inputFile)) {
      final File absoluteFile = inputFile.getAbsoluteFile();
      inputFile = absoluteFile.getParentFile();
      if (inputFile == null) {
        throw new IOException(
            "Unable to retrieve parent to file: " + absoluteFile.getAbsolutePath());
      }
    }

    VirtualDir virtualDir = VirtualDir.create(inputFile);
    if (virtualDir == null) {
      virtualDir = new VirtualDirTgz(inputFile);
    }
    return virtualDir;
  }