|
From: <svn...@os...> - 2011-12-18 23:24:06
|
Author: simonegiannecchini
Date: 2011-12-18 15:23:59 -0800 (Sun, 18 Dec 2011)
New Revision: 38425
Modified:
branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/ImagePyramidFormat.java
branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/ImagePyramidReader.java
branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/Utils.java
branches/2.7.x/modules/plugin/imagepyramid/src/test/java/org/geotools/gce/imagepyramid/ImagePyramidReaderTest.java
Log:
minor improvement to messaging and mosaic caching
Modified: branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/ImagePyramidFormat.java
===================================================================
--- branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/ImagePyramidFormat.java 2011-12-18 11:57:59 UTC (rev 38424)
+++ branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/ImagePyramidFormat.java 2011-12-18 23:23:59 UTC (rev 38425)
@@ -166,28 +166,36 @@
*/
@Override
public boolean accepts(Object source, Hints hints) {
- try {
+ if(source==null){
+ throw new NullPointerException("Null parameter provided to the accepts method of this ImagePyramidFormat");
+ }
+
+ try {
+ if (LOGGER.isLoggable(Level.FINE)) {
+ LOGGER.fine("Accepts method of ImagePyramid with source" + source);
+ }
- // /////////////////////////////////////////////////////////////////////
//
// Check source
//
- // /////////////////////////////////////////////////////////////////////
- URL sourceURL = Utils.checkSource(source, hints);
+ URL sourceURL = Utils.checkSource(source, hints);
if(sourceURL == null)
return false;
try {
sourceURL.openStream().close();
} catch (Throwable e) {
+ if(LOGGER.isLoggable(Level.FINE)){
+ LOGGER.log(Level.FINE,e.getLocalizedMessage(),e);
+ }
return false;
}
- // ///////////////////////////////////////////////////////////////////
+
//
// Trying to load informations
//
//
- // ///////////////////////////////////////////////////////////////////
+
// //
//
// get the crs if able to
@@ -204,15 +212,15 @@
if (tempcrs == null) {
// use the default crs
tempcrs = AbstractGridFormat.getDefaultCRS();
- LOGGER.log(Level.FINE,new StringBuffer("Unable to find a CRS for this coverage, using a default one: ").append(tempcrs.toWKT()).toString());
+ LOGGER.log(Level.FINE,new StringBuilder("Unable to find a CRS for this coverage, using a default one: ").append(tempcrs.toWKT()).toString());
}
//
- // ///////////////////////////////////////////////////////////////////
+
//
// Load properties file with information about levels and envelope
//
//
- // ///////////////////////////////////////////////////////////////////
+
// property file
final Properties properties = new Properties();
BufferedInputStream propertyStream = null;
Modified: branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/ImagePyramidReader.java
===================================================================
--- branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/ImagePyramidReader.java 2011-12-18 11:57:59 UTC (rev 38424)
+++ branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/ImagePyramidReader.java 2011-12-18 23:23:59 UTC (rev 38425)
@@ -24,8 +24,8 @@
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.nio.channels.Channels;
-import java.util.Map;
import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -48,7 +48,6 @@
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.referencing.CRS;
import org.geotools.referencing.operation.builder.GridToEnvelopeMapper;
-import org.geotools.util.SoftValueHashMap;
import org.opengis.coverage.grid.Format;
import org.opengis.coverage.grid.GridCoverage;
import org.opengis.coverage.grid.GridCoverageReader;
@@ -139,8 +138,8 @@
/**
* Cache of {@link ImageMosaicReader} objects for the different levels.
*
- */
- private Map<Integer, ImageMosaicReader> readers;
+ */
+ private ConcurrentHashMap<Integer, ImageMosaicReader> readers =new ConcurrentHashMap<Integer, ImageMosaicReader>();
/**
* Constructor for an {@link ImagePyramidReader}.
@@ -173,23 +172,16 @@
// //
if (source == null) {
- final NullPointerException ex = new NullPointerException("ImagePyramidReader:No source set to read this coverage.");
- throw new DataSourceException(ex);
+ throw new DataSourceException("ImagePyramidReader:Null source set to read this coverage.");
}
this.source = source;
this.sourceURL = Utils.checkSource(source, uHints);
if(sourceURL == null) {
- throw new IllegalArgumentException(
- "This plugin accepts only File, URL and String pointing to a file");
+ throw new IllegalArgumentException("This plugin accepts only File, URL and String pointing to a file");
}
// //
- //
- // Load tiles informations, especially the bounds, which will be
- // reused
- //
// //
- // //
//
// get the crs if able to
//
@@ -226,8 +218,6 @@
//
// Load properties file with information about levels and envelope
//
-
- // property file
parseMainFile(sourceURL);
}
@@ -240,6 +230,10 @@
* @throws FileNotFoundException
*/
private void parseMainFile(final URL sourceURL) throws IOException {
+
+ if(LOGGER.isLoggable(Level.FINE)){
+ LOGGER.fine("Parsing pyramid properties file at:"+sourceURL.toExternalForm());
+ }
BufferedInputStream propertyStream = null;
InputStream openStream = null;
try {
@@ -265,10 +259,6 @@
numOverviews = Integer.parseInt(properties.getProperty("LevelsNum")) - 1;
levelsDirs = properties.getProperty("LevelsDirs").split(" ");
- // readers soft map
- final int readersCacheSize = (numOverviews + 1) / 3;
- readers = new SoftValueHashMap<Integer, ImageMosaicReader>(readersCacheSize == 0 ? numOverviews + 1 : readersCacheSize);
-
// resolutions levels
final String levels = properties.getProperty("Levels");
pairs = levels.split(" ");
@@ -295,7 +285,11 @@
);
final GridToEnvelopeMapper geMapper= new GridToEnvelopeMapper(originalGridRange,originalEnvelope);
geMapper.setPixelAnchor(PixelInCell.CELL_CORNER);
- raster2Model= geMapper.createTransform();
+ raster2Model= geMapper.createTransform();
+
+ if(LOGGER.isLoggable(Level.FINE)){
+ LOGGER.fine("Parsed pyramid properties file at:"+sourceURL.toExternalForm());
+ }
} finally {
// close input stream
if (propertyStream != null)
@@ -335,21 +329,26 @@
*
* @see org.opengis.coverage.grid.GridCoverageReader#read(org.opengis.parameter.GeneralParameterValue[])
*/
- @SuppressWarnings("unchecked")
public GridCoverage2D read(GeneralParameterValue[] params) throws IOException {
+
+ //light check to see if this reader had been disposed, not synching for performance. We'll check again later on.
+ if(readers==null){
+ throw new IllegalStateException("This ImagePyramidReader has already been disposed");
+ }
GeneralEnvelope requestedEnvelope = null;
Rectangle dim = null;
OverviewPolicy overviewPolicy=null;
if (params != null) {
- // /////////////////////////////////////////////////////////////////////
+
//
// Checking params
//
- // /////////////////////////////////////////////////////////////////////
+
if (params != null) {
for (int i = 0; i < params.length; i++) {
- final ParameterValue param = (ParameterValue) params[i];
+ @SuppressWarnings("rawtypes")
+ final ParameterValue param = (ParameterValue) params[i];
if (param == null){
continue;
}
@@ -367,11 +366,10 @@
}
}
}
- // /////////////////////////////////////////////////////////////////////
+
//
// Loading tiles
//
- // /////////////////////////////////////////////////////////////////////
return loadTiles(requestedEnvelope, dim, params, overviewPolicy);
}
@@ -391,7 +389,7 @@
Rectangle dim, GeneralParameterValue[] params, OverviewPolicy overviewPolicy)
throws IOException {
- // /////////////////////////////////////////////////////////////////////
+
//
// Check if we have something to load by intersecting the requested
// envelope with the bounds of the data set.
@@ -400,7 +398,7 @@
// we have to perform a conversion towards the latter crs before
// intersecting anything.
//
- // /////////////////////////////////////////////////////////////////////
+
if (requestedEnvelope != null) {
if (!CRS.equalsIgnoreMetadata(requestedEnvelope
.getCoordinateReferenceSystem(), this.crs)) {
@@ -468,37 +466,56 @@
throws TransformException, IOException {
// if we get here we have something to load
- // /////////////////////////////////////////////////////////////////////
+
//
// compute the requested resolution
//
- // /////////////////////////////////////////////////////////////////////
final ImageReadParam readP = new ImageReadParam();
Integer imageChoice=0;
if (dim != null)
imageChoice = setReadParams(overviewPolicy, readP,requestedEnvelope, dim);
- // /////////////////////////////////////////////////////////////////////
+
//
// Check to have the needed reader in memory
//
- // /////////////////////////////////////////////////////////////////////
- ImageMosaicReader reader = null;
- synchronized (readers) {
- Object o = readers.get(imageChoice);
- if (o == null) {
- final String levelDirName = levelsDirs[imageChoice.intValue()];
- final URL parentUrl = DataUtilities.getParentUrl(sourceURL);
- // look for a shapefile first
- final String extension = new StringBuilder(levelDirName).append("/").append(coverageName).append(".shp").toString();
- final URL shpFileUrl = DataUtilities.extendURL(parentUrl,extension);
- if(shpFileUrl.getProtocol()!=null&&shpFileUrl.getProtocol().equalsIgnoreCase("file")&&!DataUtilities.urlToFile(shpFileUrl).exists())
- reader= new ImageMosaicReader(DataUtilities.extendURL(parentUrl,levelDirName), hints);
- else
- reader = new ImageMosaicReader(shpFileUrl,hints);
- readers.put(imageChoice, reader);
-
- } else
- reader = (ImageMosaicReader) o;
+
+ // light check to see if this reader had been disposed, not synching for performance.
+ if (readers == null) {
+ throw new IllegalStateException("This ImagePyramidReader has already been disposed");
+ }
+
+ ImageMosaicReader reader = readers.get(imageChoice);
+ if (reader == null) {
+
+ //
+ // we must create the underlying mosaic
+ //
+ final String levelDirName = levelsDirs[imageChoice.intValue()];
+ final URL parentUrl = DataUtilities.getParentUrl(sourceURL);
+ // look for a shapefile first
+ final String extension = new StringBuilder(levelDirName).append("/").append(coverageName).append(".shp").toString();
+ final URL shpFileUrl = DataUtilities.extendURL(parentUrl, extension);
+ if (shpFileUrl.getProtocol() != null
+ && shpFileUrl.getProtocol().equalsIgnoreCase("file")
+ && !DataUtilities.urlToFile(shpFileUrl).exists())
+ reader = new ImageMosaicReader(DataUtilities.extendURL(parentUrl, levelDirName), hints);
+ else
+ reader = new ImageMosaicReader(shpFileUrl, hints);
+ final ImageMosaicReader putByOtherThreadJustNow =readers.putIfAbsent(imageChoice, reader);
+ if(putByOtherThreadJustNow!=null){
+ // some other thread just did inserted this
+ try{
+ reader.dispose();
+ } catch (Exception e) {
+ if(LOGGER.isLoggable(Level.FINE)){
+ LOGGER.log(Level.FINE,e.getLocalizedMessage(),e);
+ }
+ }
+
+ //use the other one
+ reader=putByOtherThreadJustNow;
+ }
+
}
@@ -521,7 +538,31 @@
@Override
public synchronized void dispose() {
super.dispose();
+
+ // dispose all the underlying ImageMosaicReader if we need to
+ if(readers==null){
+ return;
+ }
+ for(ImageMosaicReader reader:readers.values()){
+ try{
+ reader.dispose();
+ } catch (Exception e) {
+ if(LOGGER.isLoggable(Level.FINE)){
+ LOGGER.log(Level.FINE,e.getLocalizedMessage(),e);
+ }
+ }
+ }
+ // now clear the map
+ try{
+
+ readers.clear();
+ } catch (Exception e) {
+ if(LOGGER.isLoggable(Level.FINE)){
+ LOGGER.log(Level.FINE,e.getLocalizedMessage(),e);
+ }
+ }
readers.clear();
+ readers=null;
}
/**
Modified: branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/Utils.java
===================================================================
--- branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/Utils.java 2011-12-18 11:57:59 UTC (rev 38424)
+++ branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/Utils.java 2011-12-18 23:23:59 UTC (rev 38425)
@@ -26,12 +26,15 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.geotools.data.DataUtilities;
@@ -46,7 +49,8 @@
/**
* Code to build a pyramid from a gdal_retile output
*
- * @author Andrea Aime - OpenGeo
+ * @author Andrea Aime - GeoSolutions SAS
+ * @author Simone Giannecchini, GeoSolutions SAS
*
*/
class Utils {
@@ -60,11 +64,10 @@
static URL checkSource(Object source, Hints hints) {
URL sourceURL = null;
File sourceFile = null;
- // /////////////////////////////////////////////////////////////////////
+
//
// Check source
//
- // /////////////////////////////////////////////////////////////////////
// if it is a URL or a String let's try to see if we can get a file to
// check if we have to build the index
if (source instanceof File) {
@@ -94,15 +97,23 @@
}
} else {
// we really don't know how to convert the thing... give up
+ if(LOGGER.isLoggable(Level.WARNING)){
+ LOGGER.warning("we really don't know how to convert the thing:"+source!=null?source.toString():"null");
+ }
return null;
}
-
- // /////////////////////////////////////////////////////////////////////
+
+ // logging
+ if(LOGGER.isLoggable(Level.INFO)){
+ if(sourceFile!=null){
+ final String message = fileStatus(sourceFile);
+ LOGGER.info(message);
+ }
+ }
+
//
// Handle cases where the pyramid descriptor file already exists
//
- // /////////////////////////////////////////////////////////////////////
-
// can't do anything with it
if(sourceFile == null || !sourceFile.exists())
return sourceURL;
@@ -114,16 +125,20 @@
// it's a directory, let's see if it already has a pyramid description file inside
File directory = sourceFile;
sourceFile = new File(directory, directory.getName() + ".properties");
+ // logging
+ if(LOGGER.isLoggable(Level.INFO)){
+ if(sourceFile!=null){
+ final String message = fileStatus(sourceFile);
+ LOGGER.info(message);
+ }
+ }
if(sourceFile.exists())
return DataUtilities.fileToURL(sourceFile);
- // /////////////////////////////////////////////////////////////////////
//
// Try to build the sub-folders mosaics
//
- // /////////////////////////////////////////////////////////////////////
-
// if the structure of the directories is gdal_retile like, move the root files in their
// own sub directory
File zeroLevelDirectory = new File(directory, "0");
@@ -132,21 +147,39 @@
File[] directories = directory.listFiles((FileFilter) directoryFilter);
// do we have at least one sub-directory?
- if(directories.length == 0)
+ if(directories.length == 0){
+ if(LOGGER.isLoggable(Level.INFO)){
+ LOGGER.info("I was unable to determine a structure similar to the GDAL Retile one!!");
+ }
return null;
+ }
// check the gdal case and move files if necessary
if(!zeroLevelDirectory.exists() && numericDirectories.length == directories.length) {
LOGGER.log(Level.INFO, "Detected gdal_retile file structure, " +
"moving root files to the '0' subdirectory");
if(zeroLevelDirectory.mkdir()) {
+ if(LOGGER.isLoggable(Level.FINE)){
+ LOGGER.fine("Created '0' subidr, now moving files");
+ }
FileFilter notDirFilter = FileFilterUtils.notFileFilter(directoryFilter);
for (File f : directory.listFiles(notDirFilter)) {
+ if(LOGGER.isLoggable(Level.FINE)){
+ LOGGER.fine("Moving file"+f.getAbsolutePath());
+ }
+ if(LOGGER.isLoggable(Level.FINEST)){
+ LOGGER.finest(fileStatus(f));
+ }
if(!f.renameTo(new File(zeroLevelDirectory, f.getName())))
- LOGGER.log(Level.INFO, "Could not move " + f.getAbsolutePath() +
+ LOGGER.log(Level.WARNING, "Could not move " + f.getAbsolutePath() +
" to " + zeroLevelDirectory);
}
directories = directory.listFiles((FileFilter) directoryFilter);
+ } else {
+ if(LOGGER.isLoggable(Level.INFO)){
+ LOGGER.info("I was unable to create the 0 directory. check the file permission in the parent directory:"+sourceFile.getParent());
+ }
+ return null;
}
}
@@ -155,7 +188,14 @@
ImageMosaicFormat mosaicFactory = new ImageMosaicFormat();
for (File subdir : directories) {
if(mosaicFactory.accepts(subdir, hints)) {
+ if(LOGGER.isLoggable(Level.FINE)){
+ LOGGER.fine("Trying to build mosaic for the directory:"+subdir.getAbsolutePath());
+ }
mosaics.add(new MosaicInfo(subdir, mosaicFactory.getReader(subdir, hints)));
+ } else {
+ if(LOGGER.isLoggable(Level.INFO)){
+ LOGGER.info("Unable to build mosaic for the directory:"+subdir.getAbsolutePath());
+ }
}
}
@@ -178,12 +218,9 @@
}
}
- // /////////////////////////////////////////////////////////////////////
//
// We have everything we need, build the final pyramid descriptor info
- //
- // /////////////////////////////////////////////////////////////////////
-
+ //
// build the property file
Properties properties = new Properties();
properties.put("Name", directory.getName());
@@ -210,7 +247,7 @@
return null;
} finally {
if(os != null)
- try { os.close(); } catch(IOException e) {}
+ IOUtils.closeQuietly(os);
}
// build the .prj file if possible
@@ -231,12 +268,40 @@
return DataUtilities.fileToURL(sourceFile);
}
+
+ /**
+ * Prepares a message with the status of the provided file.
+ * @param sourceFile The {@link File} to provided the status message for
+ * @return a status message for the provided {@link File} or a {@link NullPointerException} in case the {@link File}is <code>null</code>.
+ */
+ private static String fileStatus(File sourceFile) {
+ if(sourceFile==null){
+ throw new NullPointerException("Provided null input to fileStatus method");
+ }
+ final StringBuilder builder = new StringBuilder();
+ builder.append("Checking file:").append(FilenameUtils.getFullPath(sourceFile.getAbsolutePath())).append("\n");
+ builder.append("exists").append(sourceFile.exists()).append("\n");
+ builder.append("isFile").append(sourceFile.isFile()).append("\n");
+ builder.append("canRead:").append(sourceFile.canRead()).append("\n");
+ builder.append("canWrite").append(sourceFile.canWrite()).append("\n");
+ builder.append("canExecute").append(sourceFile.canExecute()).append("\n");
+ builder.append("isHidden:").append(sourceFile.isHidden()).append("\n");
+ builder.append("lastModified").append(sourceFile.lastModified()).append("\n");
+
+ return builder.toString();
+ }
/**
* Stores informations about a mosaic
*/
static class MosaicInfo implements Comparable<MosaicInfo>{
+ @Override
+ public String toString() {
+ return "MosaicInfo [directory=" + directory + ", resolutions="
+ + Arrays.toString(resolutions) + "]";
+ }
+
File directory;
ImageMosaicReader reader;
double[] resolutions;
Modified: branches/2.7.x/modules/plugin/imagepyramid/src/test/java/org/geotools/gce/imagepyramid/ImagePyramidReaderTest.java
===================================================================
--- branches/2.7.x/modules/plugin/imagepyramid/src/test/java/org/geotools/gce/imagepyramid/ImagePyramidReaderTest.java 2011-12-18 11:57:59 UTC (rev 38424)
+++ branches/2.7.x/modules/plugin/imagepyramid/src/test/java/org/geotools/gce/imagepyramid/ImagePyramidReaderTest.java 2011-12-18 23:23:59 UTC (rev 38425)
@@ -159,22 +159,22 @@
public void testDefaultParameterValue() throws IOException,
MismatchedDimensionException, NoSuchAuthorityCodeException {
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get the resource.
//
//
- // /////////////////////////////////////////////////////////////////
+
final URL testFile = TestData.getResource(this, TEST_FILE);//
assertNotNull(testFile);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get a reader
//
//
- // /////////////////////////////////////////////////////////////////
+
final AbstractGridFormat format = new ImagePyramidFormat();
assertTrue(format.accepts(testFile));
final ImagePyramidReader reader = (ImagePyramidReader) format
@@ -182,12 +182,12 @@
assertNotNull(reader);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Show the coverage
//
//
- // /////////////////////////////////////////////////////////////////
+
final GridCoverage2D coverage = (GridCoverage2D) reader.read(null);
assertEquals("pyramid", coverage.getName().toString());
assertNotNull("Null value returned instead of a coverage", coverage);
@@ -205,22 +205,22 @@
public void testDefaultParameterValueFile() throws IOException,
MismatchedDimensionException, NoSuchAuthorityCodeException {
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get the resource.
//
//
- // /////////////////////////////////////////////////////////////////
+
final File testFile = TestData.file(this, TEST_FILE);//
assertNotNull(testFile);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get a reader
//
//
- // /////////////////////////////////////////////////////////////////
+
final AbstractGridFormat format = new ImagePyramidFormat();
assertTrue(format.accepts(testFile));
final ImagePyramidReader reader = (ImagePyramidReader) format
@@ -228,12 +228,12 @@
assertNotNull(reader);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Show the coverage
//
//
- // /////////////////////////////////////////////////////////////////
+
final GridCoverage2D coverage = (GridCoverage2D) reader.read(null);
assertNotNull("Null value returned instead of a coverage", coverage);
assertTrue("coverage dimensions different from what we expected",
@@ -250,23 +250,23 @@
public void testDefaultParameterValueString() throws IOException,
MismatchedDimensionException, NoSuchAuthorityCodeException {
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get the resource.
//
//
- // /////////////////////////////////////////////////////////////////
+
final String testFile = TestData.file(this, TEST_FILE)
.getCanonicalPath();//
assertNotNull(testFile);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get a reader
//
//
- // /////////////////////////////////////////////////////////////////
+
final AbstractGridFormat format = new ImagePyramidFormat();
assertTrue(format.accepts(testFile));
final ImagePyramidReader reader = (ImagePyramidReader) format
@@ -274,12 +274,12 @@
assertNotNull(reader);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Show the coverage
//
//
- // /////////////////////////////////////////////////////////////////
+
final GridCoverage2D coverage = (GridCoverage2D) reader.read(null);
assertNotNull("Null value returned instead of a coverage", coverage);
assertTrue("coverage dimensions different from what we expected",
@@ -296,21 +296,21 @@
public void testForErrors() throws IOException,
MismatchedDimensionException, NoSuchAuthorityCodeException {
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get the resource.
//
//
- // /////////////////////////////////////////////////////////////////
+
final File testFile = TestData.file(this, TEST_FILE);//
assertNotNull(testFile);
- // /////////////////////////////////////////////////////////////////
+
//
// Null argument
//
//
- // /////////////////////////////////////////////////////////////////
+
ImagePyramidReader reader = null;
try {
reader = new ImagePyramidReader(null, new Hints(
@@ -320,12 +320,12 @@
}
assertNull(reader);
- // /////////////////////////////////////////////////////////////////
+
//
// Illegal arguments
//
//
- // /////////////////////////////////////////////////////////////////
+
try {
reader = new ImagePyramidReader(new FileInputStream(testFile),
new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER,
@@ -343,12 +343,12 @@
}
assertNull(reader);
- // /////////////////////////////////////////////////////////////////
+
//
// Unsopported operations
//
//
- // /////////////////////////////////////////////////////////////////
+
reader = new ImagePyramidReader(testFile, new Hints(
Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.FALSE));
@@ -381,43 +381,43 @@
MismatchedDimensionException, NoSuchAuthorityCodeException {
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get the resource.
//
//
- // /////////////////////////////////////////////////////////////////
+
final URL testFile = TestData.getResource(this, TEST_FILE);
assertNotNull(testFile);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get a reader
//
//
- // /////////////////////////////////////////////////////////////////
+
final ImagePyramidReader reader = new ImagePyramidReader(
testFile,
new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.FALSE));
assertNotNull(reader);
//
- // /////////////////////////////////////////////////////////////////
+
//
// alpha on output
//
//
- // /////////////////////////////////////////////////////////////////
+
final ParameterValue<Color> transp = ImageMosaicFormat.INPUT_TRANSPARENT_COLOR.createValue();
transp.setValue(Color.black);
- // /////////////////////////////////////////////////////////////////
+
//
// Show the coverage
//
//
- // /////////////////////////////////////////////////////////////////
+
GridCoverage2D coverage = (GridCoverage2D) reader.read(new GeneralParameterValue[] { transp });
assertNotNull(coverage);
assertTrue("coverage dimensions different from what we expected",coverage.getGridGeometry().getGridRange().getSpan(0) == 250&& coverage.getGridGeometry().getGridRange().getSpan(1) == 250);
@@ -475,31 +475,31 @@
public void testCropHighestLevel() throws IOException,
MismatchedDimensionException, NoSuchAuthorityCodeException {
- // /////////////////////////////////////////////////////////////////
+
//
// Get the resource.
//
//
- // /////////////////////////////////////////////////////////////////
+
final URL testFile = TestData.getResource(this, TEST_FILE);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get a reader
//
//
- // /////////////////////////////////////////////////////////////////
+
final AbstractGridFormat format = new ImagePyramidFormat();
final ImagePyramidReader reader = (ImagePyramidReader) format.getReader(testFile);
assertNotNull(reader);
- // /////////////////////////////////////////////////////////////////
+
//
// crop
//
//
- // /////////////////////////////////////////////////////////////////
+
final ParameterValue<GridGeometry2D> gg = ImageMosaicFormat.READ_GRIDGEOMETRY2D.createValue();
final GeneralEnvelope oldEnvelop = reader.getOriginalEnvelope();
final GeneralEnvelope cropEnvelope = new GeneralEnvelope(new double[] {
@@ -514,12 +514,12 @@
250, 250)), cropEnvelope));
//
- // /////////////////////////////////////////////////////////////////
+
//
// Show the coverage
//
//
- // /////////////////////////////////////////////////////////////////
+
GridCoverage2D coverage = ((GridCoverage2D) reader
.read(new GeneralParameterValue[] { gg }));
assertNotNull("Null value returned instead of a coverage", coverage);
@@ -553,31 +553,31 @@
public void testCropLevel1() throws IOException,
MismatchedDimensionException, NoSuchAuthorityCodeException {
- // /////////////////////////////////////////////////////////////////
+
//
// Get the resource.
//
//
- // /////////////////////////////////////////////////////////////////
+
final URL testFile = TestData.getResource(this, TEST_FILE);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get a reader
//
//
- // /////////////////////////////////////////////////////////////////
+
final AbstractGridFormat format = new ImagePyramidFormat();
final ImagePyramidReader reader = (ImagePyramidReader) format.getReader(testFile);
assertNotNull(reader);
- // /////////////////////////////////////////////////////////////////
+
//
// crop
//
//
- // /////////////////////////////////////////////////////////////////
+
final ParameterValue<GridGeometry2D> gg = ImageMosaicFormat.READ_GRIDGEOMETRY2D.createValue();
final GeneralEnvelope oldEnvelop = reader.getOriginalEnvelope();
final GeneralEnvelope cropEnvelope = new GeneralEnvelope(new double[] {
@@ -592,12 +592,12 @@
125, 125)), cropEnvelope));
//
- // /////////////////////////////////////////////////////////////////
+
//
// Show the coverage
//
//
- // /////////////////////////////////////////////////////////////////
+
GridCoverage2D coverage = ((GridCoverage2D) reader
.read(new GeneralParameterValue[] { gg }));
assertNotNull("Null value returned instead of a coverage", coverage);
@@ -631,31 +631,31 @@
public void testCropLevel2() throws IOException,
MismatchedDimensionException, NoSuchAuthorityCodeException {
- // /////////////////////////////////////////////////////////////////
+
//
// Get the resource.
//
//
- // /////////////////////////////////////////////////////////////////
+
final URL testFile = TestData.getResource(this, TEST_FILE);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get a reader
//
//
- // /////////////////////////////////////////////////////////////////
+
final AbstractGridFormat format = new ImagePyramidFormat();
final ImagePyramidReader reader = (ImagePyramidReader) format.getReader(testFile);
assertNotNull(reader);
- // /////////////////////////////////////////////////////////////////
+
//
// crop
//
//
- // /////////////////////////////////////////////////////////////////
+
final ParameterValue<GridGeometry2D> gg = ImageMosaicFormat.READ_GRIDGEOMETRY2D
.createValue();
final GeneralEnvelope oldEnvelop = reader.getOriginalEnvelope();
@@ -671,12 +671,12 @@
62, 62)), cropEnvelope));
//
- // /////////////////////////////////////////////////////////////////
+
//
// Show the coverage
//
//
- // /////////////////////////////////////////////////////////////////
+
GridCoverage2D coverage = ((GridCoverage2D) reader
.read(new GeneralParameterValue[] { gg }));
assertNotNull("Null value returned instead of a coverage", coverage);
@@ -710,31 +710,31 @@
public void testCropLevel3() throws IOException,
MismatchedDimensionException, NoSuchAuthorityCodeException {
- // /////////////////////////////////////////////////////////////////
+
//
// Get the resource.
//
//
- // /////////////////////////////////////////////////////////////////
+
final URL testFile = TestData.getResource(this, TEST_FILE);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get a reader
//
//
- // /////////////////////////////////////////////////////////////////
+
final AbstractGridFormat format = new ImagePyramidFormat();
final ImagePyramidReader reader = (ImagePyramidReader) format.getReader(testFile);
assertNotNull(reader);
- // /////////////////////////////////////////////////////////////////
+
//
// crop
//
//
- // /////////////////////////////////////////////////////////////////
+
final ParameterValue<GridGeometry2D> gg = ImageMosaicFormat.READ_GRIDGEOMETRY2D.createValue();
final GeneralEnvelope oldEnvelop = reader.getOriginalEnvelope();
final GeneralEnvelope cropEnvelope = new GeneralEnvelope(new double[] {
@@ -749,12 +749,12 @@
25, 25)), cropEnvelope));
//
- // /////////////////////////////////////////////////////////////////
+
//
// Show the coverage
//
//
- // /////////////////////////////////////////////////////////////////
+
GridCoverage2D coverage = ((GridCoverage2D) reader
.read(new GeneralParameterValue[] { gg }));
assertNotNull("Null value returned instead of a coverage", coverage);
@@ -778,12 +778,12 @@
public void testDefaultParameterValueURLtoJAR() throws IOException,
MismatchedDimensionException, NoSuchAuthorityCodeException {
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get the resource.
//
//
- // /////////////////////////////////////////////////////////////////
+
final URL testJarFile = TestData.getResource(this, TEST_JAR_FILE);
assertNotNull(testJarFile);
@@ -793,12 +793,12 @@
assertNotNull(testFile);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get a reader
//
//
- // /////////////////////////////////////////////////////////////////
+
final AbstractGridFormat format = new ImagePyramidFormat();
assertTrue(format.accepts(testFile));
final ImagePyramidReader reader = (ImagePyramidReader) format
@@ -806,12 +806,12 @@
assertNotNull(reader);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Show the coverage
//
//
- // /////////////////////////////////////////////////////////////////
+
final GridCoverage2D coverage = (GridCoverage2D) reader.read(null);
assertNotNull("Null value returned instead of a coverage", coverage);
assertTrue("coverage dimensions different from what we expected",
@@ -834,12 +834,12 @@
public void testDefaultParameterValueStringtoURLtoJAR() throws IOException,
MismatchedDimensionException, NoSuchAuthorityCodeException {
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get the resource.
//
//
- // /////////////////////////////////////////////////////////////////
+
final URL testJarFile = TestData.getResource(this, TEST_JAR_FILE);
assertNotNull(testJarFile);
@@ -848,12 +848,12 @@
assertNotNull(spec);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Get a reader
//
//
- // /////////////////////////////////////////////////////////////////
+
final AbstractGridFormat format = new ImagePyramidFormat();
assertTrue(format.accepts(spec));
final ImagePyramidReader reader = (ImagePyramidReader) format
@@ -861,12 +861,12 @@
assertNotNull(reader);
//
- // /////////////////////////////////////////////////////////////////
+
//
// Show the coverage
//
//
- // /////////////////////////////////////////////////////////////////
+
final GridCoverage2D coverage = (GridCoverage2D) reader.read(null);
assertNotNull("Null value returned instead of a coverage", coverage);
assertTrue("coverage dimensions different from what we expected",
|