• 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

22.73
/src/main/java/com/opensymphony/module/sitemesh/util/CharArrayWriter.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.Writer;
9

10
/**
11
 * Unsynced version of the JDK's CharArrayWriter.
12
 */
13
public class CharArrayWriter extends Writer {
14
    /**
15
     * The buffer where data is stored.
16
     */
17
    protected char buf[];
18

19
    /**
20
     * The number of chars in the buffer.
21
     */
22
    protected int count;
23

24
    /**
25
     * Creates a new CharArrayWriter.
26
     */
27
    public CharArrayWriter() {
28
        this(32);
1✔
29
    }
1✔
30

31
    /**
32
     * Creates a new CharArrayWriter with the specified initial size.
33
     *
34
     * @param initialSize
35
     *            an int specifying the initial buffer size.
36
     *
37
     * @exception IllegalArgumentException
38
     *                if initialSize is negative
39
     */
40
    public CharArrayWriter(int initialSize) {
1✔
41
        if (initialSize < 0) {
1!
42
            throw new IllegalArgumentException("Negative initial size: " + initialSize);
×
43
        }
44
        buf = new char[initialSize];
1✔
45
    }
1✔
46

47
    /**
48
     * Writes a character to the buffer.
49
     */
50
    @Override
51
    public void write(int c) {
52
        int newcount = count + 1;
×
53
        if (newcount > buf.length) {
×
54
            char newbuf[] = new char[Math.max(buf.length << 1, newcount)];
×
55
            System.arraycopy(buf, 0, newbuf, 0, count);
×
56
            buf = newbuf;
×
57
        }
58
        buf[count] = (char) c;
×
59
        count = newcount;
×
60
    }
×
61

62
    /**
63
     * Writes characters to the buffer.
64
     *
65
     * @param c
66
     *            the data to be written
67
     * @param off
68
     *            the start offset in the data
69
     * @param len
70
     *            the number of chars that are written
71
     */
72
    @Override
73
    public void write(char c[], int off, int len) {
74
        if (off < 0 || off > c.length || len < 0 || off + len > c.length || off + len < 0) {
×
75
            throw new IndexOutOfBoundsException();
×
76
        }
77
        if (len == 0) {
×
78
            return;
×
79
        }
80
        int newcount = count + len;
×
81
        if (newcount > buf.length) {
×
82
            char newbuf[] = new char[Math.max(buf.length << 1, newcount)];
×
83
            System.arraycopy(buf, 0, newbuf, 0, count);
×
84
            buf = newbuf;
×
85
        }
86
        System.arraycopy(c, off, buf, count, len);
×
87
        count = newcount;
×
88
    }
×
89

90
    /**
91
     * Write a portion of a string to the buffer.
92
     *
93
     * @param str
94
     *            String to be written from
95
     * @param off
96
     *            Offset from which to start reading characters
97
     * @param len
98
     *            Number of characters to be written
99
     */
100
    @Override
101
    public void write(String str, int off, int len) {
102
        int newcount = count + len;
1✔
103
        if (newcount > buf.length) {
1!
104
            char newbuf[] = new char[Math.max(buf.length << 1, newcount)];
×
105
            System.arraycopy(buf, 0, newbuf, 0, count);
×
106
            buf = newbuf;
×
107
        }
108
        str.getChars(off, off + len, buf, count);
1✔
109
        count = newcount;
1✔
110
    }
1✔
111

112
    /**
113
     * Writes the contents of the buffer to another character stream.
114
     *
115
     * @param out
116
     *            the output stream to write to
117
     *
118
     * @throws IOException
119
     *             Signals that an I/O exception has occurred.
120
     */
121
    public void writeTo(Writer out) throws IOException {
122
        out.write(buf, 0, count);
×
123
    }
×
124

125
    /**
126
     * Resets the buffer so that you can use it again without throwing away the already allocated buffer.
127
     */
128
    public void reset() {
129
        count = 0;
×
130
    }
×
131

132
    /**
133
     * Returns a copy of the input data.
134
     *
135
     * @return an array of chars copied from the input data.
136
     */
137
    public char toCharArray()[] {
138
        char newbuf[] = new char[count];
×
139
        System.arraycopy(buf, 0, newbuf, 0, count);
×
140
        return newbuf;
×
141
    }
142

143
    /**
144
     * Returns the current size of the buffer.
145
     *
146
     * @return an int representing the current size of the buffer.
147
     */
148
    public int size() {
149
        return count;
×
150
    }
151

152
    /**
153
     * Converts input data to a string.
154
     *
155
     * @return the string.
156
     */
157
    @Override
158
    public String toString() {
159
        return new String(buf, 0, count);
1✔
160
    }
161

162
    /**
163
     * Flush the stream.
164
     */
165
    @Override
166
    public void flush() {
167
    }
×
168

169
    /**
170
     * Close the stream. This method does not release the buffer, since its contents might still be required.
171
     */
172
    @Override
173
    public void close() {
174
    }
1✔
175

176
}
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