Ignore:
Timestamp:
2014-10-18T16:48:52+02:00 (10 years ago)
Author:
donvip
Message:

[josm_geotools] fix sonar issues

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/geotools/src/org/openstreetmap/josm/plugins/geotools/GeoToolsPlugin.java

    r30569 r30734  
    1717import com.sun.media.jai.imageioimpl.ImageReadWriteSpi;
    1818
     19/**
     20 * GeoTools plugin, bringing this library to other JOSM plugins.
     21 */
    1922public class GeoToolsPlugin extends Plugin {
     23
     24    /**
     25     * Constructs a new {@code GeoToolsPlugin}.
     26     * @param info plugin information
     27     */
    2028    public GeoToolsPlugin(PluginInformation info) {
    2129        super(info);
     
    2937        // See https://www.java.net/node/666373
    3038        System.setProperty("com.sun.media.jai.disableMediaLib", "true");
    31                
     39
    3240        // As the JAI jars are bundled in the geotools plugin, JAI initialization does not work,
    3341        // so we need to perform the tasks described here ("Initialization and automatic loading of registry objects"):
     
    3543        OperationRegistry registry = JAI.getDefaultInstance().getOperationRegistry();
    3644        if (registry == null) {
    37             System.err.println("geotools: error in JAI initialization. Cannot access default operation registry");
     45            Main.error("geotools: error in JAI initialization. Cannot access default operation registry");
    3846        } else {
    3947            // Update registry with com.sun.media.jai.imageioimpl.ImageReadWriteSpi (only class listed javax.media.jai.OperationRegistrySpi)
    40             // it would be safer to parse this file instead, but a JAI update is very unlikely as it has not been modified since 2005 
     48            // it would be safer to parse this file instead, but a JAI update is very unlikely as it has not been modified since 2005
    4149            new ImageReadWriteSpi().updateRegistry(registry);
    4250
    43             // Update registry with GeoTools registry file
    44             InputStream in = GeoToolsPlugin.class.getResourceAsStream("/META-INF/registryFile.jai");
    45             if (in == null) {
    46                 System.err.println("geotools: error in JAI initialization. Cannot access META-INF/registryFile.jai");
    47             } else {
    48                 try {
     51            // Update registry with GeoTools registry file
     52            try (InputStream in = GeoToolsPlugin.class.getResourceAsStream("/META-INF/registryFile.jai")) {
     53                if (in == null) {
     54                    Main.error("geotools: error in JAI initialization. Cannot access META-INF/registryFile.jai");
     55                } else {
    4956                    registry.updateFromStream(in);
    50                 } catch (IOException e) {
    51                     System.err.println("geotools: error in JAI initialization. Cannot update default operation registry");
    5257                }
    53                 try {
    54                     in.close();
    55                 } catch (IOException e) {
    56                     System.err.println("geotools: error in JAI initialization. Cannot close input stream");
    57                 }
     58            } catch (IOException e) {
     59                Main.error("geotools: error in JAI initialization: "+e.getMessage());
    5860            }
    59            
    60             // Print JAI registry contents
    61             //for (String mode : RegistryMode.getModeNames()) {
    62             //    System.out.println("geotools: JAI mode "+mode+": "+Arrays.toString(registry.getDescriptorNames(mode)));
    63             //}
    6461        }
    6562    }
    66    
     63
    6764    private void initGeoTools() {
    6865        // Force Axis order. Fix #8248
Note: See TracChangeset for help on using the changeset viewer.