source: josm/trunk/src/org/tukaani/xz/CountingOutputStream.java@ 15147

Last change on this file since 15147 was 13350, checked in by stoecker, 7 years ago

see #15816 - add XZ support

File size: 1.2 KB
Line 
1/*
2 * CountingOutputStream
3 *
4 * Author: Lasse Collin <lasse.collin@tukaani.org>
5 *
6 * This file has been put into the public domain.
7 * You can do whatever you want with this file.
8 */
9
10package org.tukaani.xz;
11
12import java.io.OutputStream;
13import java.io.IOException;
14
15/**
16 * Counts the number of bytes written to an output stream.
17 * <p>
18 * The <code>finish</code> method does nothing.
19 * This is <code>FinishableOutputStream</code> instead
20 * of <code>OutputStream</code> solely because it allows
21 * using this as the output stream for a chain of raw filters.
22 */
23class CountingOutputStream extends FinishableOutputStream {
24 private final OutputStream out;
25 private long size = 0;
26
27 public CountingOutputStream(OutputStream out) {
28 this.out = out;
29 }
30
31 public void write(int b) throws IOException {
32 out.write(b);
33 if (size >= 0)
34 ++size;
35 }
36
37 public void write(byte[] b, int off, int len) throws IOException {
38 out.write(b, off, len);
39 if (size >= 0)
40 size += len;
41 }
42
43 public void flush() throws IOException {
44 out.flush();
45 }
46
47 public void close() throws IOException {
48 out.close();
49 }
50
51 public long getSize() {
52 return size;
53 }
54}
Note: See TracBrowser for help on using the repository browser.