yangys
2024-03-31 2969df3e404db3cd116f27db1495e523ce05bf86
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.qianwen.core.tool.support;
 
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
import com.qianwen.core.tool.utils.StringPool;
 
/* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/support/FastStringWriter.class */
public class FastStringWriter extends Writer {
    private char[] buf;
    private int count;
 
    public FastStringWriter() {
        this(64);
    }
 
    public FastStringWriter(int initialSize) {
        if (initialSize < 0) {
            throw new IllegalArgumentException("Negative initial size: " + initialSize);
        }
        this.buf = new char[initialSize];
    }
 
    @Override // java.io.Writer
    public void write(int c) {
        int newCount = this.count + 1;
        if (newCount > this.buf.length) {
            this.buf = Arrays.copyOf(this.buf, Math.max(this.buf.length << 1, newCount));
        }
        this.buf[this.count] = (char) c;
        this.count = newCount;
    }
 
    @Override // java.io.Writer
    public void write(char[] c, int off, int len) {
        if (off < 0 || off > c.length || len < 0 || off + len > c.length || off + len < 0) {
            throw new IndexOutOfBoundsException();
        }
        if (len == 0) {
            return;
        }
        int newCount = this.count + len;
        if (newCount > this.buf.length) {
            this.buf = Arrays.copyOf(this.buf, Math.max(this.buf.length << 1, newCount));
        }
        System.arraycopy(c, off, this.buf, this.count, len);
        this.count = newCount;
    }
 
    @Override // java.io.Writer
    public void write(String str, int off, int len) {
        int newCount = this.count + len;
        if (newCount > this.buf.length) {
            this.buf = Arrays.copyOf(this.buf, Math.max(this.buf.length << 1, newCount));
        }
        str.getChars(off, off + len, this.buf, this.count);
        this.count = newCount;
    }
 
    public void writeTo(Writer out) throws IOException {
        out.write(this.buf, 0, this.count);
    }
 
    @Override // java.io.Writer, java.lang.Appendable
    public FastStringWriter append(CharSequence csq) {
        String s = csq == null ? StringPool.NULL : csq.toString();
        write(s, 0, s.length());
        return this;
    }
 
    @Override // java.io.Writer, java.lang.Appendable
    public FastStringWriter append(CharSequence csq, int start, int end) {
        String s = (csq == null ? StringPool.NULL : csq).subSequence(start, end).toString();
        write(s, 0, s.length());
        return this;
    }
 
    @Override // java.io.Writer, java.lang.Appendable
    public FastStringWriter append(char c) {
        write(c);
        return this;
    }
 
    public void reset() {
        this.count = 0;
    }
 
    public char[] toCharArray() {
        return Arrays.copyOf(this.buf, this.count);
    }
 
    public int size() {
        return this.count;
    }
 
    public String toString() {
        return new String(this.buf, 0, this.count);
    }
 
    @Override // java.io.Writer, java.io.Flushable
    public void flush() {
    }
 
    @Override // java.io.Writer, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
    }
}