final IOException ex = new IOException(
"WorldImage:No source set to read this coverage.");
LOGGER.logp(Level.SEVERE, WorldImageReader.class.toString(),
"WorldImageReader", ex.getLocalizedMessage(), ex);
throw new DataSourceException(ex);
}
this.source=input;
// //
//
// managing hints
//
// //
if (this.hints == null)
this.hints= new Hints();
if (hints != null) {
this.hints.add(hints);
}
// GridCoverageFactory initialization
if (this.hints.containsKey(Hints.GRID_COVERAGE_FACTORY)) {
final Object factory = this.hints.get(Hints.GRID_COVERAGE_FACTORY);
if (factory != null && factory instanceof GridCoverageFactory) {
this.coverageFactory = (GridCoverageFactory) factory;
}
}
if (this.coverageFactory == null) {
this.coverageFactory = CoverageFactoryFinder.getGridCoverageFactory(this.hints);
}
coverageName = "image_coverage";
try {
boolean closeMe = true;
// /////////////////////////////////////////////////////////////////////
//
// Source management
//
// /////////////////////////////////////////////////////////////////////
if (input instanceof URL) {
// URL that point to a file
final URL sourceURL = ((URL) input);
if (sourceURL.getProtocol().compareToIgnoreCase("file") == 0) {
String auth = sourceURL.getAuthority();
String path = sourceURL.getPath();
if (auth != null && !auth.equals("")) {
path = "//"+auth+path;
}
this.source = input = new File(URLDecoder.decode(path, "UTF-8"));
} else if (sourceURL.getProtocol().equalsIgnoreCase("http")) {
// // getting a stream to the reader
// this.source = sourceURL.openStream();
// /////////////////////////////////////////////////////////////////////
//
// WMS Request? I want to be able to handle that case too
//
// /////////////////////////////////////////////////////////////////////
wmsRequest = WMSRequest(input);
}
}
// //
//
// Name, path, etc...
//
// //
if (input instanceof File) {
final File sourceFile = (File) input;
final String filename = sourceFile.getName();
final int i = filename.lastIndexOf('.');
final int length = filename.length();
if (i > 0 && i < length - 1) {
extension = filename.substring(i + 1).toLowerCase();
}
this.parentPath = sourceFile.getParent();
this.coverageName = filename;
final int dotIndex = coverageName.lastIndexOf(".");
coverageName = (dotIndex == -1) ? coverageName : coverageName
.substring(0, dotIndex);
} else if (input instanceof URL)
input = ((URL) input).openStream();
// //
//
// Get a stream in order to read from it for getting the basic
// information for this coverfage
//
// //
if (input instanceof ImageInputStream){
closeMe = false;
}else{
inStreamSPI= ImageIOExt.getImageInputStreamSPI(source);
if (inStreamSPI == null)
throw new DataSourceException(
"No input stream for the provided source");
inStream = inStreamSPI.createInputStreamInstance( this.source, ImageIO.getUseCache(), ImageIO.getCacheDirectory());
}
if (inStream == null)
throw new IllegalArgumentException(
"No input stream for the provided source");
// /////////////////////////////////////////////////////////////////////
//
// CRS
//
// /////////////////////////////////////////////////////////////////////
if (!wmsRequest) {
final Object tempCRS = this.hints.get(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM);
if (tempCRS != null) {
this.crs = (CoordinateReferenceSystem) tempCRS;
LOGGER.log(Level.WARNING, "Using forced coordinate reference system ");
} else
readCRS();
}
// /////////////////////////////////////////////////////////////////////
//
// Informations about multiple levels and such
//
// /////////////////////////////////////////////////////////////////////
getHRInfo();
// release the stream
if (closeMe)
inStream.close();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
throw new DataSourceException(e);
} catch (TransformException e) {
LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
throw new DataSourceException(e);
}
}