• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / elemental / 982

29 Apr 2025 08:34PM UTC coverage: 56.409% (+0.007%) from 56.402%
982

push

circleci

adamretter
[feature] Improve README.md badges

28451 of 55847 branches covered (50.94%)

Branch coverage included in aggregate %.

77468 of 131924 relevant lines covered (58.72%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.75
/exist-core/src/main/java/org/exist/util/StringInputSource.java
1
/*
2
 * Elemental
3
 * Copyright (C) 2024, Evolved Binary Ltd
4
 *
5
 * admin@evolvedbinary.com
6
 * https://www.evolvedbinary.com | https://www.elemental.xyz
7
 *
8
 * Use of this software is governed by the Business Source License 1.1
9
 * included in the LICENSE file and at www.mariadb.com/bsl11.
10
 *
11
 * Change Date: 2028-04-27
12
 *
13
 * On the date above, in accordance with the Business Source License, use
14
 * of this software will be governed by the Apache License, Version 2.0.
15
 *
16
 * Additional Use Grant: Production use of the Licensed Work for a permitted
17
 * purpose. A Permitted Purpose is any purpose other than a Competing Use.
18
 * A Competing Use means making the Software available to others in a commercial
19
 * product or service that: substitutes for the Software; substitutes for any
20
 * other product or service we offer using the Software that exists as of the
21
 * date we make the Software available; or offers the same or substantially
22
 * similar functionality as the Software.
23
 */
24
package org.exist.util;
25

26
import com.evolvedbinary.j8fu.Either;
27
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
28

29
import java.io.*;
30

31
import static com.evolvedbinary.j8fu.Either.Left;
32
import static com.evolvedbinary.j8fu.Either.Right;
33

34
/**
35
 * @author <a href="mailto:adam@evolvedbinary.com">Adam Retter</a>
36
 */
37
public class StringInputSource extends EXistInputSource {
38

39
    private final Either<byte[], String> source;
40

41
    /**
42
     * Creates a String Source from a string
43
     * the InputSource will be read using
44
     * {@link #getCharacterStream()}.
45
     *
46
     * @param string the input string.
47
     */
48
    public StringInputSource(final String string) {
49
        super();
1✔
50
        this.source = Right(string);
1✔
51
    }
1✔
52

53
    /**
54
     * Creates a String Source from bytes
55
     * the InputSource will be read using
56
     * {@link #getByteStream()}.
57
     *
58
     * @param string the input string.
59
     */
60
    public StringInputSource(final byte[] string) {
61
        super();
1✔
62
        this.source = Left(string);
1✔
63
    }
1✔
64

65
    @Override
66
    public Reader getCharacterStream() {
67
        assertOpen();
1✔
68

69
        if (source.isLeft()) {
1✔
70
            return null;
1✔
71
        } else {
72
            return new StringReader(source.right().get());
1✔
73
        }
74
    }
75

76
    /**
77
     * This method now does nothing, so collateral
78
     * effects from superclass with this one are avoided
79
     *
80
     * @throws IllegalStateException if the InputSource was previously closed
81
     */
82
    @Override
83
    public void setCharacterStream(final Reader r) {
84
        assertOpen();
×
85
        throw new IllegalStateException("StringInputSource is immutable");
×
86
    }
87

88
    @Override
89
    public InputStream getByteStream() {
90
        assertOpen();
1✔
91
        if (source.isLeft()) {
1✔
92
            return new UnsynchronizedByteArrayInputStream(source.left().get());
1✔
93
        } else {
94
            return null;
1✔
95
        }
96
    }
97

98
    /**
99
     * @see EXistInputSource#getByteStreamLength()
100
     *
101
     * @throws IllegalStateException if the InputSource was previously closed
102
     */
103
    @Override
104
    public long getByteStreamLength() {
105
        assertOpen();
1✔
106
        if (source.isLeft()) {
1!
107
            return source.left().get().length;
1✔
108
        } else {
109
            return -1;
×
110
        }
111
    }
112

113
    /**
114
     * Set a byte stream input.
115
     *
116
     * @param is the input stream.
117
     *
118
     * @throws IllegalStateException this class is immutable!
119
     */
120
    @Override
121
    public void setByteStream(final InputStream is) {
122
        assertOpen();
×
123
        throw new IllegalStateException("StringInputSource is immutable");
×
124
    }
125

126
    /**
127
     * This method now does nothing, so collateral
128
     * effects from superclass with this one are avoided
129
     *
130
     * @throws IllegalStateException if the InputSource was previously closed
131
     */
132
    @Override
133
    public void setSystemId(final String systemId) {
134
        assertOpen();
×
135
        // Nothing, so collateral effects are avoided!
136
    }
×
137

138
    /**
139
     * @see EXistInputSource#getSymbolicPath()
140
     *
141
     * @throws IllegalStateException if the InputSource was previously closed
142
     */
143
    @Override
144
    public String getSymbolicPath() {
145
        assertOpen();
×
146
        return null;
×
147
    }
148
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc