SizeLimitedInputStreampublic class SizeLimitedInputStream extends InputStream Wraps an underlying input stream, limiting the allowable size
of incoming data. The size limit is configured in the conf file,
and when the limit is reached, a MessageSizeException is thrown. |
Fields Summary |
---|
private long | maxmessagesizeMaximum number of bytes to read. | private long | bytesreadRunning total of bytes read from wrapped stream. | private InputStream | inInputStream that will be wrapped. |
Constructors Summary |
---|
public SizeLimitedInputStream(InputStream in, long maxmessagesize)Constructor for the stream. Wraps an underlying stream.
this.in = in;
this.maxmessagesize = maxmessagesize;
|
Methods Summary |
---|
public int | read(byte[] b, int off, int len)Overrides the read method of InputStream to call the read() method of the
wrapped input stream.
int l = in.read(b, off, len);
bytesread += l;
if (maxmessagesize > 0 && bytesread > maxmessagesize) {
throw new MessageSizeException();
}
return l;
| public int | read()Overrides the read method of InputStream to call the read() method of the
wrapped input stream.
if (maxmessagesize > 0 && bytesread <= maxmessagesize) {
bytesread++;
return in.read();
} else {
throw new MessageSizeException();
}
|
|