1 | /*- | |
2 | * #%L | |
3 | * io.earcam.utilitarian.site.search.offline | |
4 | * %% | |
5 | * Copyright (C) 2017 earcam | |
6 | * %% | |
7 | * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT) | |
8 | * | |
9 | * You <b>must</b> choose to accept, in full - any individual or combination of | |
10 | * the following licenses: | |
11 | * <ul> | |
12 | * <li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li> | |
13 | * <li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li> | |
14 | * <li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li> | |
15 | * <li><a href="https://opensource.org/licenses/MIT">MIT</a></li> | |
16 | * </ul> | |
17 | * #L% | |
18 | */ | |
19 | package io.earcam.utilitarian.site.search.offline; | |
20 | ||
21 | import java.io.ByteArrayOutputStream; | |
22 | import java.io.IOException; | |
23 | import java.io.InputStream; | |
24 | import java.io.OutputStream; | |
25 | import java.nio.charset.Charset; | |
26 | import java.util.Map; | |
27 | ||
28 | import io.earcam.unexceptional.Closing; | |
29 | import io.earcam.utilitarian.io.ReplaceAllOutputStream; | |
30 | ||
31 | public final class Resources { | |
32 | ||
33 | public static final String PROPERTY_USE_SCRIPT_ENGINE = "search.offline.scriptengine"; | |
34 | ||
35 | public static final String UI_SCRIPT_SEARCH_FILE = "ui.search.lunr.js"; | |
36 | ||
37 | public static final String RESOURCES_ROOT = "META-INF/resources/js/"; | |
38 | ||
39 | public static final String SCRIPT_INDEX = RESOURCES_ROOT + "index.lunr.js"; | |
40 | ||
41 | public static final String UI_SCRIPT_SEARCH = RESOURCES_ROOT + UI_SCRIPT_SEARCH_FILE; | |
42 | ||
43 | static final String SCRIPT_SEARCH = RESOURCES_ROOT + "json.search.lunr.js"; | |
44 | ||
45 | public static final String CONFIGURATION_ROOT = "META-INF/configuration/"; | |
46 | ||
47 | public static final String DEFAULT_CRAWLER_JSON = CONFIGURATION_ROOT + "default-crawler-maven.json"; | |
48 | public static final String DEFAULT_INDEXER_JSON = CONFIGURATION_ROOT + "default-indexer-maven.json"; | |
49 | ||
50 | ||
51 | private Resources() | |
52 | {} | |
53 | ||
54 | ||
55 | public static InputStream getResource(String resource) | |
56 | { | |
57 |
1
1. getResource : mutated return of Object value for io/earcam/utilitarian/site/search/offline/Resources::getResource to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return Resources.class.getClassLoader().getResourceAsStream(resource); |
58 | } | |
59 | ||
60 | ||
61 | public static String getResource(String resource, Charset charset, Map<String, String> searchReplace) | |
62 | { | |
63 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
64 | OutputStream output = baos; | |
65 | ||
66 | for(Map.Entry<String, String> e : searchReplace.entrySet()) { | |
67 | output = new ReplaceAllOutputStream(e.getKey().getBytes(charset), e.getValue().getBytes(charset), output); | |
68 | } | |
69 |
1
1. getResource : removed call to io/earcam/unexceptional/Closing::closeAfterAccepting → KILLED |
Closing.closeAfterAccepting(getResource(resource), output, Resources::drain); |
70 |
1
1. getResource : mutated return of Object value for io/earcam/utilitarian/site/search/offline/Resources::getResource to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new String(baos.toByteArray(), charset); |
71 | } | |
72 | ||
73 | ||
74 | private static void drain(InputStream input, OutputStream output) throws IOException | |
75 | { | |
76 | int b; | |
77 |
1
1. drain : negated conditional → KILLED |
while((b = input.read()) != -1) { |
78 |
1
1. drain : removed call to java/io/OutputStream::write → KILLED |
output.write(b); |
79 | } | |
80 | } | |
81 | } | |
Mutations | ||
57 |
1.1 |
|
69 |
1.1 |
|
70 |
1.1 |
|
77 |
1.1 |
|
78 |
1.1 |