Skip to content

Commit

Permalink
Fixing Issue #49: Closing dataset used for metadata initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
dromagnoli committed Mar 14, 2013
1 parent 099ca86 commit 2903870
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,49 +131,63 @@ public GDALCommonIIOImageMetadata(Dataset dataset, String name,
return;
setDatasetDescription(dataset.GetDescription());
Driver driver = null;
try {
driver = dataset.GetDriver();
if (driver != null) {
setDriverDescription(driver.GetDescription());
setDriverName(driver.getShortName());
}
gdalDomainMetadataMap = new HashMap<String, Map<String, String>>();

// //
//
// Getting Metadata from Default domain and Image_structure domain
//
// //
Map<String, String> defMap = dataset.GetMetadata_Dict(GDALUtilities.GDALMetadataDomain.DEFAULT);
if (defMap != null && defMap.size() > 0)
gdalDomainMetadataMap.put(GDALUtilities.GDALMetadataDomain.DEFAULT_KEY_MAP, defMap);

Map<String, String> imageStMap = dataset.GetMetadata_Dict(GDALUtilities.GDALMetadataDomain.IMAGESTRUCTURE);
if (imageStMap != null && imageStMap.size() > 0)
gdalDomainMetadataMap.put(GDALUtilities.GDALMetadataDomain.IMAGESTRUCTURE,imageStMap);

// //
//
// Initializing member if needed
//
// //
if (initializationRequired)
setMembers(dataset);
setGeoreferencingInfo(dataset);
// clean up data set in order to avoid keeping them around for a lot
// of time.
} finally {
if (driver != null){
try{
try {
driver = dataset.GetDriver();
if (driver != null) {
setDriverDescription(driver.GetDescription());
setDriverName(driver.getShortName());
}
gdalDomainMetadataMap = new HashMap<String, Map<String, String>>();

// //
//
// Getting Metadata from Default domain and Image_structure domain
//
// //
Map<String, String> defMap = dataset
.GetMetadata_Dict(GDALUtilities.GDALMetadataDomain.DEFAULT);
if (defMap != null && defMap.size() > 0)
gdalDomainMetadataMap.put(GDALUtilities.GDALMetadataDomain.DEFAULT_KEY_MAP, defMap);

Map<String, String> imageStMap = dataset
.GetMetadata_Dict(GDALUtilities.GDALMetadataDomain.IMAGESTRUCTURE);
if (imageStMap != null && imageStMap.size() > 0)
gdalDomainMetadataMap.put(GDALUtilities.GDALMetadataDomain.IMAGESTRUCTURE,
imageStMap);

// //
//
// Initializing member if needed
//
// //
if (initializationRequired)
setMembers(dataset);
setGeoreferencingInfo(dataset);
// clean up data set in order to avoid keeping them around for a lot
// of time.
} finally {
if (driver != null) {
try {
// Closing the driver
driver.delete();
}catch (Throwable e) {
if(LOGGER.isLoggable(Level.FINEST))
LOGGER.log(Level.FINEST,e.getLocalizedMessage(),e);
}
}
}

driver.delete();
} catch (Throwable e) {
if (LOGGER.isLoggable(Level.FINEST))
LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e);
}
}
if (initializationRequired) {
if (dataset != null)
try {
// Closing the dataset
GDALUtilities.closeDataSet(dataset);
} catch (Throwable e) {
if (LOGGER.isLoggable(Level.FINEST))
LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e);
}
}

}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,21 @@ public class JP2KReadTest extends AbstractGDALTest {
private final static boolean isJP2ECWAvailable;

static {
if (isGDALAvailable){
gdal.AllRegister();
final String versionInfo = gdal.VersionInfo("RELEASE_NAME");
if (versionInfo.contains("1.9.") && System.getProperty("os.name").toLowerCase().startsWith("linux")) {
// JP2 ECW crashes on Linux with > 1.8: http://trac.osgeo.org/gdal/ticket/4201
isJP2ECWAvailable = false;
} else {
final Driver driverkak = gdal.GetDriverByName("JP2KAK");
final Driver drivermrsid = gdal.GetDriverByName("JP2MrSID");
if (driverkak != null || drivermrsid != null) {
final StringBuilder skipDriver = new StringBuilder("");
if (driverkak != null)
skipDriver.append("JP2KAK ");
if (drivermrsid != null)
skipDriver.append("JP2MrSID");
gdal.SetConfigOption("GDAL_SKIP", skipDriver.toString());
gdal.AllRegister();
}
isJP2ECWAvailable = GDALUtilities.isDriverAvailable("JP2ECW");
}
if (isGDALAvailable) {
gdal.AllRegister();
final Driver driverkak = gdal.GetDriverByName("JP2KAK");
final Driver drivermrsid = gdal.GetDriverByName("JP2MrSID");
if (driverkak != null || drivermrsid != null) {
final StringBuilder skipDriver = new StringBuilder("");
if (driverkak != null)
skipDriver.append("JP2KAK ");
if (drivermrsid != null)
skipDriver.append("JP2MrSID");
gdal.SetConfigOption("GDAL_SKIP", skipDriver.toString());
gdal.AllRegister();
}
isJP2ECWAvailable = GDALUtilities.isDriverAvailable("JP2ECW");
// }
} else {
isJP2ECWAvailable = false;
}
Expand Down Expand Up @@ -225,9 +220,9 @@ public void testJaiOperations() throws IOException {

@Before
public void setUp() throws Exception {
super.setUp();
JAI.getDefaultInstance().getTileCache().setMemoryCapacity(64 * 1024 * 1024);
JAI.getDefaultInstance().getTileCache().setMemoryThreshold(1.0f);
}
super.setUp();
JAI.getDefaultInstance().getTileCache().setMemoryCapacity(64 * 1024 * 1024);
JAI.getDefaultInstance().getTileCache().setMemoryThreshold(1.0f);
}

}

0 comments on commit 2903870

Please sign in to comment.