Statistics
| Revision:

root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / compiler / ByteCountingOutputStream.java @ 15280

History | View | Annotate | Download (2.09 KB)

1
/*
2
 *  $Id
3
 *  IzPack
4
 *  Copyright (C) 2001-2004 Julien Ponge
5
 *
6
 *  File :               ByteCountingOutputStream.java
7
 *  Description :        Counts bytes that are written
8
 *  Author's email :     julien@izforge.com
9
 *  Author's Website :   http://www.izforge.com
10
 *
11
 *  Portions are Copyright (c) 2001 Johannes Lehtinen
12
 *  johannes.lehtinen@iki.fi
13
 *  http://www.iki.fi/jle/
14
 *
15
 *  Portions are Copyright (c) 2002 Paul Wilkinson
16
 *  paulw@wilko.com
17
 *
18
 *  This program is free software; you can redistribute it and/or
19
 *  modify it under the terms of the GNU General Public License
20
 *  as published by the Free Software Foundation; either version 2
21
 *  of the License, or any later version.
22
 *
23
 *  This program is distributed in the hope that it will be useful,
24
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 *  GNU General Public License for more details.
27
 *
28
 *  You should have received a copy of the GNU General Public License
29
 *  along with this program; if not, write to the Free Software
30
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
31
 */
32
package com.izforge.izpack.compiler;
33

    
34
import java.io.OutputStream;
35
import java.io.IOException;
36

    
37
/**
38
 * Stream which countes the bytes written through it. Be sure to flush before
39
 * checking size.
40
 */
41
public class ByteCountingOutputStream extends OutputStream
42
{
43
  private long count;
44
  private OutputStream os;
45

    
46
  public ByteCountingOutputStream(OutputStream os)
47
  {
48
    this.os = os;
49
  }
50

    
51
  public void write(byte[] b, int off, int len) throws IOException
52
  {
53
    os.write(b, off, len);
54
    count += len;
55
  }
56

    
57
  public void write(byte[] b) throws IOException
58
  {
59
    os.write(b);
60
    count += b.length;
61
  }
62

    
63
  public void write(int b) throws IOException
64
  {
65
    os.write(b);
66
    count++;
67
  }
68

    
69
  public void close() throws IOException
70
  {
71
    os.close();
72
  }
73

    
74
  public void flush() throws IOException
75
  {
76
    os.flush();
77
  }
78

    
79
  public long getByteCount()
80
  {
81
    return count;
82
  }
83
}