1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package io.earcam.instrumental.lade.jpms;
20
21 import java.io.IOException;
22 import java.lang.module.ModuleDescriptor;
23 import java.lang.module.ModuleReader;
24 import java.lang.module.ModuleReference;
25 import java.net.URI;
26 import java.util.Optional;
27 import java.util.Set;
28 import java.util.stream.Stream;
29
30 import io.earcam.unexceptional.Exceptional;
31
32 final class InMemoryModuleReference extends ModuleReference {
33
34 private class InMemoryModuleReader implements ModuleReader {
35 @Override
36 public Stream<String> list() throws IOException
37 {
38 return list.stream();
39 }
40
41
42 @Override
43 public Optional<URI> find(String name) throws IOException
44 {
45 return list()
46 .filter(r -> r.startsWith(location().get().toString()))
47 .map(Exceptional::uri)
48 .filter(r -> r.toString().endsWith(name))
49 .findAny();
50 }
51
52
53 @Override
54 public void close()
55 {
56
57 }
58 }
59
60 private final Set<String> list;
61
62
63 InMemoryModuleReference(ModuleDescriptor descriptor, URI location, Set<String> list)
64 {
65 super(descriptor, location);
66 this.list = list;
67 }
68
69
70 @Override
71 public ModuleReader open() throws IOException
72 {
73 return new InMemoryModuleReader();
74 }
75 }