author | mullan |
Mon, 26 Sep 2011 17:20:45 -0700 | |
changeset 10694 | cf59e2badd14 |
parent 6898 | 92eff65fd33d |
child 18780 | f47b920867e7 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
5 |
/* |
|
6898
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
6 |
* Copyright 1999-2010 The Apache Software Foundation. |
2 | 7 |
* |
8 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9 |
* you may not use this file except in compliance with the License. |
|
10 |
* You may obtain a copy of the License at |
|
11 |
* |
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13 |
* |
|
14 |
* Unless required by applicable law or agreed to in writing, software |
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17 |
* See the License for the specific language governing permissions and |
|
18 |
* limitations under the License. |
|
19 |
* |
|
20 |
*/ |
|
21 |
package com.sun.org.apache.xml.internal.security.utils; |
|
22 |
||
1337 | 23 |
import java.io.OutputStream; |
2 | 24 |
|
25 |
/** |
|
6898
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
26 |
* A simple Unsynced ByteArrayOutputStream |
2 | 27 |
* @author raul |
28 |
* |
|
29 |
*/ |
|
1337 | 30 |
public class UnsyncByteArrayOutputStream extends OutputStream { |
6898
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
31 |
private static final int INITIAL_SIZE = 8192; |
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
6898
diff
changeset
|
32 |
private static ThreadLocal<byte[]> bufCache = new ThreadLocal<byte[]>() { |
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
6898
diff
changeset
|
33 |
protected synchronized byte[] initialValue() { |
6898
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
34 |
return new byte[INITIAL_SIZE]; |
1337 | 35 |
} |
36 |
}; |
|
6898
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
37 |
|
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
38 |
private byte[] buf; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
39 |
private int size = INITIAL_SIZE; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
40 |
private int pos = 0; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
41 |
|
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
42 |
public UnsyncByteArrayOutputStream() { |
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
6898
diff
changeset
|
43 |
buf = bufCache.get(); |
6898
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
44 |
} |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
45 |
|
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
46 |
public void write(byte[] arg0) { |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
47 |
int newPos = pos + arg0.length; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
48 |
if (newPos > size) { |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
49 |
expandSize(newPos); |
1337 | 50 |
} |
6898
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
51 |
System.arraycopy(arg0, 0, buf, pos, arg0.length); |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
52 |
pos = newPos; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
53 |
} |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
54 |
|
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
55 |
public void write(byte[] arg0, int arg1, int arg2) { |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
56 |
int newPos = pos + arg2; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
57 |
if (newPos > size) { |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
58 |
expandSize(newPos); |
2 | 59 |
} |
6898
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
60 |
System.arraycopy(arg0, arg1, buf, pos, arg2); |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
61 |
pos = newPos; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
62 |
} |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
63 |
|
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
64 |
public void write(int arg0) { |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
65 |
int newPos = pos + 1; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
66 |
if (newPos > size) { |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
67 |
expandSize(newPos); |
2 | 68 |
} |
6898
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
69 |
buf[pos++] = (byte)arg0; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
70 |
} |
2 | 71 |
|
6898
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
72 |
public byte[] toByteArray() { |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
73 |
byte result[] = new byte[pos]; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
74 |
System.arraycopy(buf, 0, result, 0, pos); |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
75 |
return result; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
76 |
} |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
77 |
|
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
78 |
public void reset() { |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
79 |
pos = 0; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
80 |
} |
2 | 81 |
|
6898
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
82 |
private void expandSize(int newPos) { |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
83 |
int newSize = size; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
84 |
while (newPos > newSize) { |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
85 |
newSize = newSize<<2; |
2 | 86 |
} |
6898
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
87 |
byte newBuf[] = new byte[newSize]; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
88 |
System.arraycopy(buf, 0, newBuf, 0, pos); |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
89 |
buf = newBuf; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
90 |
size = newSize; |
92eff65fd33d
6954275: XML signatures with reference data larger 16KB and cacheRef on fails to validate
mullan
parents:
1337
diff
changeset
|
91 |
} |
2 | 92 |
} |