• 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

60.0
/exist-core/src/main/java/org/exist/dom/persistent/XMLDeclarationImpl.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.dom.persistent;
25

26
import org.exist.storage.io.VariableByteInput;
27
import org.exist.storage.io.VariableByteOutputStream;
28

29
import javax.annotation.Nullable;
30
import java.io.IOException;
31

32
/**
33
 * XML Declaration of an XML document
34
 * available with SAX in Java 14+.
35
 *
36
 * @author <a href="mailto:adam@evolvedbinary.com">Adam Retter</a>
37
 */
38
public class XMLDeclarationImpl {
39

40
    @Nullable private final String version;
41
    @Nullable private final String encoding;
42
    @Nullable private final String standalone;
43

44
    public XMLDeclarationImpl(@Nullable final String version, @Nullable final String encoding, @Nullable final String standalone) {
1✔
45
        this.version = version;
1✔
46
        this.encoding = encoding;
1✔
47
        this.standalone = standalone;
1✔
48
    }
1✔
49

50
    /**
51
     * Get the version from the XML Declaration.
52
     *
53
     * @return the version (if present), or null.
54
     */
55
    @Nullable
56
    public String getVersion() {
57
        return version;
1✔
58
    }
59

60
    /**
61
     * Get the encoding from the XML Declaration.
62
     *
63
     * @return the encoding (if present), or null.
64
     */
65
    @Nullable
66
    public String getEncoding() {
67
        return encoding;
1✔
68
    }
69

70
    /**
71
     * Get the standalone from the XML Declaration.
72
     *
73
     * @return the standalone (if present), or null.
74
     */
75
    @Nullable
76
    public String getStandalone() {
77
        return standalone;
1✔
78
    }
79

80
    /**
81
     * Write the XML Declaration to the output stream.
82
     *
83
     * @param ostream the output stream.
84
     *
85
     * @throws IOException if an error occurs whilst writing to the output stream.
86
     */
87
    public void write(final VariableByteOutputStream ostream) throws IOException {
88
        ostream.writeUTF(version != null ? version : "");
1!
89
        ostream.writeUTF(encoding != null ? encoding : "");
1✔
90
        ostream.writeUTF(standalone != null ? standalone : "");
1✔
91
    }
1✔
92

93
    /**
94
     * Read an XML Declaration from the input stream.
95
     *
96
     * @param istream the input stream.
97
     *
98
     * @throws IOException if an error occurs whilst reading from the input stream.
99
     */
100
    public static XMLDeclarationImpl read(final VariableByteInput istream) throws IOException {
101
        String version = istream.readUTF();
1✔
102
        if(version.length() == 0) {
1!
103
            version = null;
×
104
        }
105
        String encoding = istream.readUTF();
1✔
106
        if(encoding.length() == 0) {
1✔
107
            encoding = null;
1✔
108
        }
109
        String standalone = istream.readUTF();
1✔
110
        if(standalone.length() == 0) {
1!
111
            standalone = null;
1✔
112
        }
113

114
        return new XMLDeclarationImpl(version, encoding, standalone);
1✔
115
    }
116

117
    @Override
118
    public String toString() {
119
        final StringBuilder builder = new StringBuilder();
×
120

121
        builder.append("<?xml");
×
122

123
        if (version != null) {
×
124
            builder.append(" version=\"").append(version).append("\"");
×
125
        }
126

127
        if (encoding != null) {
×
128
            builder.append(" encoding=\"").append(encoding).append("\"");
×
129
        }
130

131
        if (standalone != null) {
×
132
            builder.append(" standalone=\"").append(standalone).append("\"");
×
133
        }
134

135
        builder.append("?>");
×
136

137
        return builder.toString();
×
138
    }
139
}
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