/** Load from the named resource. */ private MimeTypeFile loadResource(String name) { InputStream clis = null; try { clis = SecuritySupport.getResourceAsStream(this.getClass(), name); if (clis != null) { MimeTypeFile mf = new MimeTypeFile(clis); if (LogSupport.isLoggable()) LogSupport.log("MimetypesFileTypeMap: successfully " + "loaded mime types file: " + name); return mf; } else { if (LogSupport.isLoggable()) LogSupport.log("MimetypesFileTypeMap: not loading " + "mime types file: " + name); } } catch (IOException e) { if (LogSupport.isLoggable()) LogSupport.log("MimetypesFileTypeMap: can't load " + name, e); } catch (SecurityException sex) { if (LogSupport.isLoggable()) LogSupport.log("MimetypesFileTypeMap: can't load " + name, sex); } finally { try { if (clis != null) clis.close(); } catch (IOException ex) { } // ignore it } return null; }
/** * Find the name of service provider using Jar Service Provider Mechanism * * @return instance of provider class if found or null */ private static String findJarServiceProviderName(String factoryId) { SecuritySupport ss = SecuritySupport.getInstance(); String serviceId = SERVICES_PATH + factoryId; InputStream is = null; // First try the Context ClassLoader ClassLoader cl = findClassLoader(); is = ss.getResourceAsStream(cl, serviceId); // If no provider found then try the current ClassLoader if (is == null) { ClassLoader current = ObjectFactory.class.getClassLoader(); if (cl != current) { cl = current; is = ss.getResourceAsStream(cl, serviceId); } } if (is == null) { // No provider found return null; } if (DEBUG) debugPrintln("found jar resource=" + serviceId + " using ClassLoader: " + cl); // Read the service provider name in UTF-8 as specified in // the jar spec. Unfortunately this fails in Microsoft // VJ++, which does not implement the UTF-8 // encoding. Theoretically, we should simply let it fail in // that case, since the JVM is obviously broken if it // doesn't support such a basic standard. But since there // are still some users attempting to use VJ++ for // development, we have dropped in a fallback which makes a // second attempt using the platform's default encoding. In // VJ++ this is apparently ASCII, which is a subset of // UTF-8... and since the strings we'll be reading here are // also primarily limited to the 7-bit ASCII range (at // least, in English versions), this should work well // enough to keep us on the air until we're ready to // officially decommit from VJ++. [Edited comment from // jkesselm] BufferedReader rd; try { rd = new BufferedReader(new InputStreamReader(is, "UTF-8")); } catch (java.io.UnsupportedEncodingException e) { rd = new BufferedReader(new InputStreamReader(is)); } String factoryClassName = null; try { // XXX Does not handle all possible input as specified by the // Jar Service Provider specification factoryClassName = rd.readLine(); } catch (IOException x) { // No provider found return null; } finally { try { // try to close the reader. rd.close(); } // Ignore the exception. catch (IOException exc) { } } if (factoryClassName != null && !"".equals(factoryClassName)) { if (DEBUG) debugPrintln("found in resource, value=" + factoryClassName); // Note: here we do not want to fall back to the current // ClassLoader because we want to avoid the case where the // resource file was found using one ClassLoader and the // provider class was instantiated using a different one. return factoryClassName; } // No provider found return null; }
/* 307: */ /* 308: */ private static String findJarServiceProviderName(String factoryId) /* 309: */ { /* 310:537 */ SecuritySupport ss = SecuritySupport.getInstance(); /* 311:538 */ String serviceId = "META-INF/services/" + factoryId; /* 312:539 */ InputStream is = null; /* 313: */ /* 314: */ /* 315:542 */ ClassLoader cl = findClassLoader(); /* 316: */ /* 317:544 */ is = ss.getResourceAsStream(cl, serviceId); /* 318:547 */ if (is == null) /* 319: */ { /* 320:548 */ ClassLoader current = ObjectFactory.class.getClassLoader(); /* 321:549 */ if (cl != current) /* 322: */ { /* 323:550 */ cl = current; /* 324:551 */ is = ss.getResourceAsStream(cl, serviceId); /* 325: */ } /* 326: */ } /* 327:555 */ if (is == null) { /* 328:557 */ return null; /* 329: */ } /* 330:560 */ debugPrintln("found jar resource=" + serviceId + " using ClassLoader: " + cl); /* 331: */ BufferedReader rd; /* 332: */ try /* 333: */ { /* 334:581 */ rd = new BufferedReader(new InputStreamReader(is, "UTF-8")); /* 335: */ } /* 336: */ catch (UnsupportedEncodingException e) /* 337: */ { /* 338:583 */ rd = new BufferedReader(new InputStreamReader(is)); /* 339: */ } /* 340:586 */ String factoryClassName = null; /* 341: */ try /* 342: */ { /* 343:590 */ factoryClassName = rd.readLine(); /* 344: */ } /* 345: */ catch (IOException x) /* 346: */ { /* 347:593 */ return null; /* 348: */ } /* 349: */ finally /* 350: */ { /* 351: */ try /* 352: */ { /* 353:598 */ rd.close(); /* 354: */ } /* 355: */ catch (IOException exc) { } /* 356: */ } /* 357:604 */ if ((factoryClassName != null) && (!"".equals(factoryClassName))) /* 358: */ { /* 359:606 */ debugPrintln("found in resource, value=" + factoryClassName); /* 360: */ /* 361: */ /* 362: */ /* 363: */ /* 364: */ /* 365: */ /* 366:613 */ return factoryClassName; /* 367: */ } /* 368:617 */ return null; /* 369: */ }