01: /*
02: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
03: *
04: * http://izpack.org/
05: * http://izpack.codehaus.org/
06: *
07: * Copyright 2001 Johannes Lehtinen
08: * Copyright 2002 Paul Wilkinson
09: *
10: * Licensed under the Apache License, Version 2.0 (the "License");
11: * you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software
17: * distributed under the License is distributed on an "AS IS" BASIS,
18: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19: * See the License for the specific language governing permissions and
20: * limitations under the License.
21: */
22:
23: package com.izforge.izpack.compiler;
24:
25: import java.io.IOException;
26: import java.io.OutputStream;
27:
28: /**
29: * Stream which countes the bytes written through it. Be sure to flush before checking size.
30: */
31: public class ByteCountingOutputStream extends OutputStream {
32:
33: private long count;
34:
35: private OutputStream os;
36:
37: public ByteCountingOutputStream(OutputStream os) {
38: this .os = os;
39: }
40:
41: public void write(byte[] b, int off, int len) throws IOException {
42: os.write(b, off, len);
43: count += len;
44: }
45:
46: public void write(byte[] b) throws IOException {
47: os.write(b);
48: count += b.length;
49: }
50:
51: public void write(int b) throws IOException {
52: os.write(b);
53: count += 4;
54: }
55:
56: public void close() throws IOException {
57: os.close();
58: }
59:
60: public void flush() throws IOException {
61: os.flush();
62: }
63:
64: public long getByteCount() {
65: return count;
66: }
67: }
|