File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\util\ByteArrayOutputStream2.java.html

1 package hudson.util;
2
3 import java.io.ByteArrayOutputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
6
7 /**
8 * {@link ByteArrayOutputStream} with access to its raw buffer.
9 * @since 1.349
10 */
11 public class ByteArrayOutputStream2 extends ByteArrayOutputStream {
12 public ByteArrayOutputStream2() {
13 }
14
15 public ByteArrayOutputStream2(int size) {
16 super(size);
17 }
18
19 public byte[] getBuffer() {
20 return buf;
21 }
22
23 /**
24 * Reads the given {@link InputStream} completely into the buffer.
25 */
26 public void readFrom(InputStream is) throws IOException {
27 while(true) {
28 if(count==buf.length) {
29 // realllocate
30 byte[] data = new byte[buf.length*2];
31 System.arraycopy(buf,0,data,0,buf.length);
32 buf = data;
33 }
34
35 int sz = is.read(buf,count,buf.length-count);
36 if(sz<0) return;
37 count += sz;
38 }
39 }
40 }
41