ResourceHandler { InputStream getResourceStream(String path) throws FileNotFoundException { final String dddbDirFromProperty = System.getProperty(SMOS_DDDB_DIR_PROPERTY_NAME); if (StringUtils.isNotNullAndNotEmpty(dddbDirFromProperty)) { final File resourceFile = new File(dddbDirFromProperty, path); if (resourceFile.isFile()) { return new FileInputStream(resourceFile); } } return getClass().getResourceAsStream(path); }    }
@Test public void testGetResourceStream_fromJar() throws IOException { System.clearProperty(ResourceHandler.SMOS_DDDB_DIR_PROPERTY_NAME); final InputStream resourceStream = resourceHandler.getResourceStream("bands/AUX_/DFFLAI/DBL_SM_XXXX_AUX_DFFLAI_0200.csv"); assertNotNull(resourceStream); resourceStream.close(); }
@Test public void testGetResourceStream_fromDirectory() throws IOException { final String testFileName = "test_me"; File targetDirectory = null; InputStream resourceStream = null; try { targetDirectory = createTestDirectory(); System.setProperty(ResourceHandler.SMOS_DDDB_DIR_PROPERTY_NAME, targetDirectory.getAbsolutePath()); createTestFile(targetDirectory, testFileName); resourceStream = resourceHandler.getResourceStream(testFileName); assertNotNull(resourceStream); } finally { if (resourceStream != null) { resourceStream.close(); } System.clearProperty(ResourceHandler.SMOS_DDDB_DIR_PROPERTY_NAME); if (targetDirectory != null && targetDirectory.isDirectory()) { if (!FileUtils.deleteTree(targetDirectory)) { fail("Unable to delete test directory"); } } } }