提高程序的稳定性
This commit is contained in:
@@ -7,8 +7,8 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
public class OutputMetre extends OutputStream {
|
||||
|
||||
private OutputStream out;
|
||||
private AtomicLong total;
|
||||
public OutputMetre(OutputStream outputStream,AtomicLong v) {
|
||||
private AtomicLong[] total;
|
||||
public OutputMetre(OutputStream outputStream,AtomicLong ...v) {
|
||||
this.out=outputStream;
|
||||
this.total=v;
|
||||
}
|
||||
@@ -16,19 +16,22 @@ public class OutputMetre extends OutputStream {
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
out.write(b);
|
||||
total.incrementAndGet();
|
||||
for(AtomicLong x:total)
|
||||
x.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b) throws IOException {
|
||||
out.write(b);
|
||||
total.addAndGet(b.length);
|
||||
for(AtomicLong x:total)
|
||||
x.addAndGet(b.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
out.write(b, off, len);
|
||||
total.addAndGet(len);
|
||||
for(AtomicLong x:total)
|
||||
x.addAndGet(len);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user