1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.icc;
18
19 import java.io.ByteArrayOutputStream;
20 import java.io.IOException;
21 import java.io.InputStream;
22
23 final class CachingInputStream extends InputStream {
24 private final InputStream is;
25 private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
26
27 CachingInputStream(final InputStream is) {
28 this.is = is;
29 }
30
31 @Override
32 public int available() throws IOException {
33 return is.available();
34 }
35
36 @Override
37 public void close() throws IOException {
38 is.close();
39 }
40
41 public byte[] getCache() {
42 return baos.toByteArray();
43 }
44
45 @Override
46 public int read() throws IOException {
47 final int result = is.read();
48 baos.write(result);
49 return result;
50 }
51
52 }