< prev index next >

src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Module.java

Print this page
rev 3356 : [mq]: 8140281-deprecation-optional.get


 278                 this.jarfile = new JarFile(m.path().toFile(), false);
 279             } catch (IOException e) {
 280                 throw new UncheckedIOException(e);
 281             }
 282             this.provides = providers(jarfile);
 283         }
 284 
 285         @Override
 286         public Map<String, Set<String>> provides() {
 287             return provides;
 288         }
 289 
 290         private Map<String, Set<String>> providers(JarFile jf) {
 291             Map<String, Set<String>> provides = new HashMap<>();
 292             // map names of service configuration files to service names
 293             Set<String> serviceNames =  jf.stream()
 294                     .map(e -> e.getName())
 295                     .filter(e -> e.startsWith(SERVICES_PREFIX))
 296                     .distinct()
 297                     .map(this::toServiceName)
 298                     .filter(Optional::isPresent)
 299                     .map(Optional::get)
 300                     .collect(Collectors.toSet());
 301 
 302             // parse each service configuration file
 303             for (String sn : serviceNames) {
 304                 JarEntry entry = jf.getJarEntry(SERVICES_PREFIX + sn);
 305                 Set<String> providerClasses = new HashSet<>();
 306                 try (InputStream in = jf.getInputStream(entry)) {
 307                     BufferedReader reader
 308                             = new BufferedReader(new InputStreamReader(in, "UTF-8"));
 309                     String cn;
 310                     while ((cn = nextLine(reader)) != null) {
 311                         if (isJavaIdentifier(cn)) {
 312                             providerClasses.add(cn);
 313                         }
 314                     }
 315                 } catch (IOException e) {
 316                     throw new UncheckedIOException(e);
 317                 }
 318                 if (!providerClasses.isEmpty())
 319                     provides.put(sn, providerClasses);




 278                 this.jarfile = new JarFile(m.path().toFile(), false);
 279             } catch (IOException e) {
 280                 throw new UncheckedIOException(e);
 281             }
 282             this.provides = providers(jarfile);
 283         }
 284 
 285         @Override
 286         public Map<String, Set<String>> provides() {
 287             return provides;
 288         }
 289 
 290         private Map<String, Set<String>> providers(JarFile jf) {
 291             Map<String, Set<String>> provides = new HashMap<>();
 292             // map names of service configuration files to service names
 293             Set<String> serviceNames =  jf.stream()
 294                     .map(e -> e.getName())
 295                     .filter(e -> e.startsWith(SERVICES_PREFIX))
 296                     .distinct()
 297                     .map(this::toServiceName)
 298                     .flatMap(Optional::stream)

 299                     .collect(Collectors.toSet());
 300 
 301             // parse each service configuration file
 302             for (String sn : serviceNames) {
 303                 JarEntry entry = jf.getJarEntry(SERVICES_PREFIX + sn);
 304                 Set<String> providerClasses = new HashSet<>();
 305                 try (InputStream in = jf.getInputStream(entry)) {
 306                     BufferedReader reader
 307                             = new BufferedReader(new InputStreamReader(in, "UTF-8"));
 308                     String cn;
 309                     while ((cn = nextLine(reader)) != null) {
 310                         if (isJavaIdentifier(cn)) {
 311                             providerClasses.add(cn);
 312                         }
 313                     }
 314                 } catch (IOException e) {
 315                     throw new UncheckedIOException(e);
 316                 }
 317                 if (!providerClasses.isEmpty())
 318                     provides.put(sn, providerClasses);


< prev index next >