org.hd.d.pg2k.svrCore
Class GenUtils.LengthLimitedOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by org.hd.d.pg2k.svrCore.GenUtils.LengthLimitedOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable
Enclosing class:
GenUtils

public static final class GenUtils.LengthLimitedOutputStream
extends java.io.FilterOutputStream

Prevents more than a specified number of bytes being written to the output stream. Attempting to exceed the limit will result in an IOException being thrown.

Specifically, this will veto the first write that would exceed the limit and all subsequent (non-zero) writes.

Data up until the limit will be written.

Thread-safe.


Field Summary
private  int bytesWritten
          The number of bytes written so far; non-negative.
private  int limit
          The maximum number of bytes to be written; non-negative.
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
GenUtils.LengthLimitedOutputStream(java.io.OutputStream out, int limit)
          Creates an output stream with the specified write limit.
 
Method Summary
 int getBytesWritten()
          Retrieve the number of bytes written so far; non-negative.
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.io.FilterOutputStream
close, flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

limit

private final int limit
The maximum number of bytes to be written; non-negative.


bytesWritten

private int bytesWritten
The number of bytes written so far; non-negative. Advances monotonically.

Accessed under the instance lock only.

Constructor Detail

GenUtils.LengthLimitedOutputStream

public GenUtils.LengthLimitedOutputStream(java.io.OutputStream out,
                                          int limit)
Creates an output stream with the specified write limit.

Parameters:
out - the output stream
limit - maximum number of bytes to be allowed; non-negative
Method Detail

getBytesWritten

public int getBytesWritten()
Retrieve the number of bytes written so far; non-negative.


write

public void write(int b)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream
Throws:
java.io.IOException

DHD Multimedia Gallery V1.57.21

Copyright (c) 1996-2011, Damon Hart-Davis. All rights reserved.