ByteArrayWrapper.java
3.05 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.agl.util;
import com.adobe.agl.impl.Utility;
public class ByteArrayWrapper
implements Comparable {
public byte[] bytes;
public int size;
public ByteArrayWrapper ensureCapacity(int capacity) {
if (this.bytes == null || this.bytes.length < capacity) {
byte[] newbytes = new byte[capacity];
ByteArrayWrapper.copyBytes(this.bytes, 0, newbytes, 0, this.size);
this.bytes = newbytes;
}
return this;
}
public final ByteArrayWrapper set(byte[] src, int start, int limit) {
this.size = 0;
this.append(src, start, limit);
return this;
}
public final ByteArrayWrapper append(byte[] src, int start, int limit) {
int len = limit - start;
this.ensureCapacity(this.size + len);
ByteArrayWrapper.copyBytes(src, start, this.bytes, this.size, len);
this.size += len;
return this;
}
public final byte[] releaseBytes() {
byte[] result = this.bytes;
this.bytes = null;
this.size = 0;
return result;
}
public String toString() {
StringBuffer result = new StringBuffer();
for (int i = 0; i < this.size; ++i) {
if (i != 0) {
result.append(" ");
}
result.append(Utility.hex(this.bytes[i] & 255, 2));
}
return result.toString();
}
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null) {
return false;
}
try {
ByteArrayWrapper that = (ByteArrayWrapper)other;
if (this.size != that.size) {
return false;
}
for (int i = 0; i < this.size; ++i) {
if (this.bytes[i] == that.bytes[i]) continue;
return false;
}
return true;
}
catch (ClassCastException e) {
return false;
}
}
public int hashCode() {
int result = this.bytes.length;
for (int i = 0; i < this.size; ++i) {
result = 37 * result + this.bytes[i];
}
return result;
}
public int compareTo(Object other) {
if (this == other) {
return 0;
}
ByteArrayWrapper that = (ByteArrayWrapper)other;
int minSize = this.size < that.size ? this.size : that.size;
for (int i = 0; i < minSize; ++i) {
if (this.bytes[i] == that.bytes[i]) continue;
return (this.bytes[i] & 255) - (that.bytes[i] & 255);
}
return this.size - that.size;
}
private static final void copyBytes(byte[] src, int srcoff, byte[] tgt, int tgtoff, int length) {
if (length < 64) {
int i = srcoff;
int n = tgtoff;
while (--length >= 0) {
tgt[n] = src[i];
++i;
++n;
}
} else {
System.arraycopy(src, srcoff, tgt, tgtoff, length);
}
}
}