ByteStringBuffer.java
4.32 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.internal.util;
import com.adobe.internal.util.ByteSequence;
import com.adobe.internal.util.ByteString;
import java.io.Serializable;
public class ByteStringBuffer
implements ByteSequence,
Comparable,
Serializable {
private byte[] value;
private int length;
private static final long serialVersionUID = -5059151845327279132L;
public ByteStringBuffer() {
this(16);
}
public ByteStringBuffer(int length) {
this.value = new byte[length];
}
@Override
public byte byteAt(int index) {
if (index < 0 || index >= this.length) {
throw new StringIndexOutOfBoundsException(index);
}
return this.value[index];
}
@Override
public int length() {
return this.length;
}
@Override
public ByteSequence subSequence(int start, int end) {
return null;
}
public ByteString substring(int begin, int end) {
if (begin < 0) {
throw new StringIndexOutOfBoundsException(begin);
}
if (end > this.length) {
throw new StringIndexOutOfBoundsException(end);
}
if (begin > end) {
throw new StringIndexOutOfBoundsException(end - begin);
}
return new ByteString(this.value, begin, end - begin);
}
@Override
public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin) {
try {
System.arraycopy(this.value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
}
catch (IndexOutOfBoundsException e) {
StringIndexOutOfBoundsException newException = new StringIndexOutOfBoundsException();
newException.initCause(e);
throw newException;
}
}
@Override
public byte[] getBytes() {
byte[] array = new byte[this.length];
System.arraycopy(this.value, 0, array, 0, this.length);
return array;
}
public void setByteAt(int index, byte b) {
if (index < 0 || index >= this.length) {
throw new StringIndexOutOfBoundsException(index);
}
this.value[index] = b;
}
public ByteStringBuffer append(byte b) {
int newLength = this.length + 1;
if (newLength > this.value.length) {
this.expandCapacity(newLength);
}
this.value[this.length++] = b;
return this;
}
public ByteStringBuffer append(byte[] b) {
return this.append(b, 0, b.length);
}
public ByteStringBuffer append(byte[] b, int offset, int length) {
if (offset < 0 || length < 0 || offset + length > b.length) {
throw new IndexOutOfBoundsException("Byte array index out of bounds.");
}
int newLength = this.length + length;
if (newLength > this.value.length) {
this.expandCapacity(newLength);
}
System.arraycopy(this.value, this.length, b, offset, length);
this.length += length;
return this;
}
public void ensureCapacity(int minimumCapacity) {
if (minimumCapacity > this.value.length) {
this.expandCapacity(minimumCapacity);
}
}
private void expandCapacity(int minimumCapacity) {
int newCapacity = (this.value.length + 1) * 2;
if (newCapacity < 0) {
newCapacity = Integer.MAX_VALUE;
} else if (minimumCapacity > newCapacity) {
newCapacity = minimumCapacity;
}
byte[] newValue = new byte[newCapacity];
System.arraycopy(this.value, 0, newValue, 0, this.length);
this.value = newValue;
}
public int compareTo(Object otherObject) {
return this.compareTo((ByteStringBuffer)otherObject);
}
public int compareTo(ByteStringBuffer otherByteString) {
int count = Math.min(this.length, otherByteString.length);
for (int i = 0; i < count; ++i) {
byte b1 = this.value[i];
byte b2 = otherByteString.value[i];
if (b1 == b2) continue;
return b1 - b2;
}
return this.length - otherByteString.length;
}
public boolean equals(Object otherObject) {
if (this == otherObject) {
return true;
}
if (otherObject instanceof ByteStringBuffer) {
return this.compareTo(otherObject) == 0;
}
return false;
}
}