SpotVgtProductReaderPlugIn implements ProductReaderPlugIn { @Override public DecodeQualification getDecodeQualification(Object input) { File file = getFileInput(input); if (file == null) { return DecodeQualification.UNABLE; } VirtualDir virtualDir = VirtualDir.create(file); if (virtualDir == null) { return DecodeQualification.UNABLE; } try { try { Reader reader = virtualDir.getReader(SpotVgtConstants.PHYS_VOL_FILENAME); if (reader == null) { return DecodeQualification.UNABLE; } try { PhysVolDescriptor descriptor = new PhysVolDescriptor(reader); String[] strings = virtualDir.list(descriptor.getLogVolDirName()); if (strings.length == 0) { return DecodeQualification.UNABLE; } } finally { reader.close(); } return DecodeQualification.INTENDED; } catch (IOException e) { final String productName = FilenameUtils.getBaseName(file.getName()); try { virtualDir.getReader(productName + "_LOG.TXT"); } catch (IOException e1) { try { virtualDir.getReader(productName + "/" + productName + "_LOG.TXT"); } catch (IOException e2) { return DecodeQualification.UNABLE; } } String[] filesInProduct; if (file.list() != null) { filesInProduct = file.list(); } else { try { filesInProduct = virtualDir.list(productName); } catch (IOException e1) { return DecodeQualification.UNABLE; } } if (filesInProduct != null) { for (int i = 0; i < SpotVgtConstants.BANDS_IN_VGT_P_COLLECTION3_PRODUCT.length; i++) { boolean vgtPCollection3ProductFile = false; for (int j = 0; j < filesInProduct.length; j++) { if (filesInProduct[j].toUpperCase(). equals(productName + "_" + SpotVgtConstants.BANDS_IN_VGT_P_COLLECTION3_PRODUCT[i] + ".HDF")) { vgtPCollection3ProductFile = true; break; } } if (!vgtPCollection3ProductFile) { return DecodeQualification.UNABLE; } } isVgtPCollection3Product = true; return DecodeQualification.INTENDED; } else { return DecodeQualification.UNABLE; } } } finally { virtualDir.close(); } } SpotVgtProductReaderPlugIn(); @Override DecodeQualification getDecodeQualification(Object input); @Override Class[] getInputTypes(); @Override ProductReader createReaderInstance(); @Override SnapFileFilter getProductFileFilter(); @Override String[] getDefaultFileExtensions(); @Override String getDescription(Locale locale); @Override String[] getFormatNames();  }
@Test public void testDecodeQualification() { SpotVgtProductReaderPlugIn plugIn = new SpotVgtProductReaderPlugIn(); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(null)); File dir = TestDataDir.get(); File file; file = new File(dir, "decode_qual_intended.zip"); assertEquals(DecodeQualification.INTENDED, plugIn.getDecodeQualification(file)); assertEquals(DecodeQualification.INTENDED, plugIn.getDecodeQualification(file.getPath())); file = new File(dir, "decode_qual_intended"); assertEquals(DecodeQualification.INTENDED, plugIn.getDecodeQualification(file)); assertEquals(DecodeQualification.INTENDED, plugIn.getDecodeQualification(file.getPath())); file = new File(dir, "decode_qual_intended/PHYS_VOL.TXT"); assertEquals(DecodeQualification.INTENDED, plugIn.getDecodeQualification(file)); assertEquals(DecodeQualification.INTENDED, plugIn.getDecodeQualification(file.getPath())); file = new File(dir, "decode_qual_unable_1"); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file)); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file.getPath())); file = new File(dir, "decode_qual_unable_1/PHYS_VOL.TXT"); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file)); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file.getPath())); file = new File(dir, "decode_qual_unable_2"); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file)); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file.getPath())); file = new File(dir, "decode_qual_unable_2/PHYS_VOL.TXT"); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file)); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file.getPath())); file = new File(dir, "decode_qual_unable_3"); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file)); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file.getPath())); file = new File(dir, "decode_qual_unable_3/TEST.TXT"); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file)); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file.getPath())); file = new File(dir, "decode_qual_unable_3/NON_EXISTENT"); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file)); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file.getPath())); file = new File(dir, "decode_qual_intended_collection3/zip/V220050513179.zip"); assertEquals(DecodeQualification.INTENDED, plugIn.getDecodeQualification(file)); assertEquals(DecodeQualification.INTENDED, plugIn.getDecodeQualification(file.getPath())); file = new File(dir, "decode_qual_intended_collection3/V220050513179"); assertEquals(DecodeQualification.INTENDED, plugIn.getDecodeQualification(file)); assertEquals(DecodeQualification.INTENDED, plugIn.getDecodeQualification(file.getPath())); file = new File(dir, "decode_qual_unable_1_missing_bands_collection3/V220050513179"); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file)); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file.getPath())); file = new File(dir, "decode_qual_unable_2_missing_logdescr_collection3/V220050513179"); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file)); assertEquals(DecodeQualification.UNABLE, plugIn.getDecodeQualification(file.getPath())); }