Mercurial > hg > blitz_condensed
comparison src/org/prevayler/implementation/ByteCountStream.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 /* | |
2 The copyright of all source code included in this Prevayler distribution is | |
3 held by Klaus Wuestefeld, except the files that specifically state otherwise. | |
4 All rights are reserved. "PREVAYLER" is a trademark of Klaus Wuestefeld. | |
5 | |
6 | |
7 BSD License: | |
8 | |
9 Redistribution and use in source and binary forms, with or without | |
10 modification, are permitted provided that the following conditions are met: | |
11 | |
12 - Redistributions of source code must retain the above copyright notice, this | |
13 list of conditions and the following disclaimer. | |
14 | |
15 - Redistributions in binary form must reproduce the above copyright notice, | |
16 this list of conditions and the following disclaimer in the documentation | |
17 and/or other materials provided with the distribution. | |
18 | |
19 - Neither the name of Prevayler nor the names of its contributors may be used | |
20 to endorse or promote products derived from this software without specific | |
21 prior written permission. | |
22 | |
23 | |
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
34 POSSIBILITY OF SUCH DAMAGE. | |
35 */ | |
36 | |
37 package org.prevayler.implementation; | |
38 | |
39 import java.io.*; | |
40 | |
41 /** A FileOutputStream that counts the number of bytes written and forces all buffers to synchronize with the underlying device when flushed. | |
42 */ | |
43 final class ByteCountStream extends FileOutputStream { | |
44 | |
45 public ByteCountStream(File file) throws IOException { | |
46 super(file); | |
47 } | |
48 | |
49 public void flush() throws IOException { | |
50 /* | |
51 "The flush method of OutputStream does nothing." - JDK1.3 API | |
52 documentation. I'm calling it just in case it starts doing something | |
53 in a future version of FileOutputStream or OutputStream. | |
54 */ | |
55 super.flush(); | |
56 | |
57 /* | |
58 As we're JDK 1.4, this saves a bit of time because we don't bother | |
59 flushing meta data (we only care about flushing content) | |
60 */ | |
61 getChannel().force(false); | |
62 | |
63 // Original | |
64 // getFD().sync(); //"Force all system buffers to synchronize with the underlying device." - JDK1.3 API documentation. | |
65 } | |
66 | |
67 public void write(byte[] b) throws IOException { | |
68 super.write(b); | |
69 bytesWritten += b.length; | |
70 } | |
71 | |
72 public void write(byte[] b, int off, int len) throws IOException { | |
73 super.write(b, off, len); | |
74 bytesWritten += len; | |
75 } | |
76 | |
77 public void write(int b) throws IOException { | |
78 super.write(b); | |
79 ++bytesWritten; | |
80 } | |
81 | |
82 public long bytesWritten() { | |
83 return bytesWritten; | |
84 } | |
85 | |
86 private long bytesWritten; | |
87 } |