01: // Prevayler(TM) - The Open-Source Prevalence Layer.
02: // Copyright (C) 2001 Klaus Wuestefeld.
03: // This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
04:
05: package org.prevayler.implementation;
06:
07: import java.io.*;
08:
09: /** A FileOutputStream that counts the number of bytes written and forces all buffers to synchronize with the underlying device when flushed.
10: */
11: final class ByteCountStream extends FileOutputStream {
12:
13: public ByteCountStream(File file) throws IOException {
14: super (file);
15: }
16:
17: public void flush() throws IOException {
18: super .flush(); //"The flush method of OutputStream does nothing." - JDK1.3 API documentation. I'm calling it just in case it starts doing something in a future version of FileOutputStream or OutputStream.
19: getFD().sync(); //"Force all system buffers to synchronize with the underlying device." - JDK1.3 API documentation.
20: }
21:
22: public void write(byte[] b) throws IOException {
23: super .write(b);
24: bytesWritten += b.length;
25: }
26:
27: public void write(byte[] b, int off, int len) throws IOException {
28: super .write(b, off, len);
29: bytesWritten += len;
30: }
31:
32: public void write(int b) throws IOException {
33: super .write(b);
34: ++bytesWritten;
35: }
36:
37: public long bytesWritten() {
38: return bytesWritten;
39: }
40:
41: private long bytesWritten;
42: }
|