LandsatMetadataFactory { static LandsatMetadata create(File mtlFile) throws IOException { LandsatLegacyMetadata landsatMetadata = new LandsatLegacyMetadata(new FileReader(mtlFile)); if (landsatMetadata.isLegacyFormat()) { if (landsatMetadata.isLandsatTM() || landsatMetadata.isLandsatETM_Plus()) { return landsatMetadata; } else { throw new ProductIOException("Product is of a legacy landsat format, not a legacy Landsat5 or Landsat7 ETM+ product."); } } else { BufferedReader reader = null; try { FileReader fileReader = new FileReader(mtlFile); reader = new BufferedReader(fileReader); String line = reader.readLine(); while (line != null) { if (line.contains("SPACECRAFT_ID")) { if (line.contains("LANDSAT_8")) { return new Landsat8Metadata(new FileReader(mtlFile)); } else { return new LandsatReprocessedMetadata(new FileReader(mtlFile)); } } line = reader.readLine(); } } finally { if (reader != null) { reader.close(); } } throw new IllegalStateException( "File '" + mtlFile + "' does not contain spacecraft information. (Field 'SPACECRAFT_ID' missing)"); } }    }
@Test public void testCreate_L1_MSS_reproc() throws Exception { File testFile = new File(getClass().getResource("test_L1_MSS_MTL.txt").getFile()); LandsatMetadata landsatMetadata = LandsatMetadataFactory.create(testFile); assertTrue(landsatMetadata instanceof LandsatReprocessedMetadata); }
@Test public void testCreate_L3_MSS_reproc() throws Exception { File testFile = new File(getClass().getResource("test_L3_MSS_MTL.txt").getFile()); LandsatMetadata landsatMetadata = LandsatMetadataFactory.create(testFile); assertTrue(landsatMetadata instanceof LandsatReprocessedMetadata); }
@Test public void testCreate_5_reproc() throws Exception { File testFile = new File(getClass().getResource("test_5_reproc_MTL.txt").getFile()); LandsatMetadata landsatMetadata = LandsatMetadataFactory.create(testFile); assertTrue(landsatMetadata instanceof LandsatReprocessedMetadata); }
@Test public void testCreate_7_reproc() throws Exception { File testFile = new File(getClass().getResource("test_7_reproc_MTL.txt").getFile()); LandsatMetadata landsatMetadata = LandsatMetadataFactory.create(testFile); assertTrue(landsatMetadata instanceof LandsatReprocessedMetadata); }
@Test public void testCreate_8() throws Exception { File testFile = new File(getClass().getResource("test_L8_MTL.txt").getFile()); LandsatMetadata landsatMetadata = LandsatMetadataFactory.create(testFile); assertTrue(landsatMetadata instanceof Landsat8Metadata); }
@Test public void testCreate_Legacy() throws Exception { File testFile = new File(getClass().getResource("test_L7_MTL.txt").getFile()); LandsatMetadata landsatMetadata = LandsatMetadataFactory.create(testFile); assertTrue(landsatMetadata instanceof LandsatLegacyMetadata); }
@Test(expected = IllegalStateException.class) public void testFail() throws IOException { File testFile = new File(getClass().getResource("test_broken_MTL.txt").getFile()); LandsatMetadataFactory.create(testFile); }