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

hazendaz / sitemesh2 / 59

22 Mar 2026 02:30AM UTC coverage: 40.347%. Remained the same
59

push

github

hazendaz
[mvn] Update maven wrapper

698 of 1891 branches covered (36.91%)

Branch coverage included in aggregate %.

1555 of 3693 relevant lines covered (42.11%)

0.42 hits per line

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

51.28
/src/main/java/com/opensymphony/module/sitemesh/util/CharArrayReader.java
1
/*
2
 * SPDX-License-Identifier: Apache-2.0
3
 * Copyright 2011-2026 Hazendaz
4
 */
5
package com.opensymphony.module.sitemesh.util;
6

7
import java.io.IOException;
8
import java.io.Reader;
9

10
/**
11
 * This class implements a character buffer that can be used as a character-input stream. Modified from the JDK source
12
 * in that it gets rid of the ensureOpen() method, so we get unexpected behaviour if the reader is closed.
13
 * <p>
14
 * The second modification is that since this class is used internally by FastPageParser in a single thread, we don't
15
 * need any locking or synchronization. Using this class instead of the standard CharArrayReader improves FastPageParser
16
 * performance by 15-20%.
17
 *
18
 * @author Hani Suleiman
19
 */
20
public class CharArrayReader extends Reader {
21
    /** The character buffer. */
22
    protected char buf[];
23

24
    /** The current buffer position. */
25
    protected int pos;
26

27
    /** The position of mark in buffer. */
28
    protected int markedPos = 0;
1✔
29

30
    /**
31
     * The index of the end of this buffer. There is not valid data at or beyond this index.
32
     */
33
    protected int count;
34

35
    /**
36
     * Create an CharArrayReader from the specified array of chars.
37
     *
38
     * @param buf
39
     *            Input buffer (not copied)
40
     */
41
    public CharArrayReader(char buf[]) {
×
42
        this.buf = buf;
×
43
        this.pos = 0;
×
44
        this.count = buf.length;
×
45
    }
×
46

47
    /**
48
     * Create an CharArrayReader from the specified array of chars.
49
     *
50
     * @param buf
51
     *            Input buffer (not copied)
52
     * @param offset
53
     *            Offset of the first char to read
54
     * @param length
55
     *            Number of chars to read
56
     */
57
    public CharArrayReader(char buf[], int offset, int length) {
1✔
58
        if (offset < 0 || offset > buf.length || length < 0 || offset + length < 0) {
1!
59
            throw new IllegalArgumentException();
×
60
        }
61
        this.buf = buf;
1✔
62
        this.pos = offset;
1✔
63
        this.count = Math.min(offset + length, buf.length);
1✔
64
        this.markedPos = offset;
1✔
65
    }
1✔
66

67
    /**
68
     * Read a single character.
69
     *
70
     * @throws IOException
71
     *             If an I/O error occurs
72
     */
73
    @Override
74
    public int read() throws IOException {
75
        if (pos >= count) {
1✔
76
            return -1;
1✔
77
        }
78
        return buf[pos++];
1✔
79
    }
80

81
    /**
82
     * Read characters into a portion of an array.
83
     *
84
     * @param b
85
     *            Destination buffer
86
     * @param off
87
     *            Offset at which to start storing characters
88
     * @param len
89
     *            Maximum number of characters to read
90
     *
91
     * @return The actual number of characters read, or -1 if the end of the stream has been reached
92
     *
93
     * @throws IOException
94
     *             If an I/O error occurs
95
     */
96
    @Override
97
    public int read(char b[], int off, int len) throws IOException {
98
        if (off < 0 || off > b.length || len < 0 || off + len > b.length || off + len < 0) {
1!
99
            throw new IndexOutOfBoundsException();
×
100
        }
101
        if (len == 0) {
1!
102
            return 0;
×
103
        }
104

105
        if (pos >= count) {
1✔
106
            return -1;
1✔
107
        }
108
        if (pos + len > count) {
1✔
109
            len = count - pos;
1✔
110
        }
111
        if (len <= 0) {
1!
112
            return 0;
×
113
        }
114
        System.arraycopy(buf, pos, b, off, len);
1✔
115
        pos += len;
1✔
116
        return len;
1✔
117
    }
118

119
    /**
120
     * Skip characters.
121
     *
122
     * @param n
123
     *            The number of characters to skip
124
     *
125
     * @throws IOException
126
     *             If an I/O error occurs
127
     *
128
     * @return The number of characters actually skipped
129
     */
130
    @Override
131
    public long skip(long n) throws IOException {
132
        if (pos + n > count) {
×
133
            n = count - pos;
×
134
        }
135
        if (n < 0) {
×
136
            return 0;
×
137
        }
138
        pos += n;
×
139
        return n;
×
140
    }
141

142
    /**
143
     * Tell whether this stream is ready to be read. Character-array readers are always ready to be read.
144
     *
145
     * @throws IOException
146
     *             If an I/O error occurs
147
     */
148
    @Override
149
    public boolean ready() throws IOException {
150
        return count - pos > 0;
×
151
    }
152

153
    /**
154
     * Tell whether this stream supports the mark() operation, which it does.
155
     */
156
    @Override
157
    public boolean markSupported() {
158
        return true;
×
159
    }
160

161
    /**
162
     * Mark the present position in the stream. Subsequent calls to reset() will reposition the stream to this point.
163
     *
164
     * @param readAheadLimit
165
     *            Limit on the number of characters that may be read while still preserving the mark. Because the
166
     *            stream's input comes from a character array, there is no actual limit; hence this argument is ignored.
167
     *
168
     * @throws IOException
169
     *             If an I/O error occurs
170
     */
171
    @Override
172
    public void mark(int readAheadLimit) throws IOException {
173
        markedPos = pos;
×
174
    }
×
175

176
    /**
177
     * Reset the stream to the most recent mark, or to the beginning if it has never been marked.
178
     *
179
     * @throws IOException
180
     *             If an I/O error occurs
181
     */
182
    @Override
183
    public void reset() throws IOException {
184
        pos = markedPos;
×
185
    }
×
186

187
    /**
188
     * Close the stream.
189
     */
190
    @Override
191
    public void close() {
192
        buf = null;
1✔
193
    }
1✔
194
}
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

© 2026 Coveralls, Inc