You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by se...@apache.org on 2001/11/26 04:28:25 UTC
cvs commit: jakarta-james/src/java/org/apache/james/smtpserver SizeLimitedInputStream.java
serge 01/11/25 19:28:25
Modified: src/java/org/apache/james/smtpserver
SizeLimitedInputStream.java
Log:
Added a read(byte[], off, len) implementation.
Revision Changes Path
1.2 +26 -5 jakarta-james/src/java/org/apache/james/smtpserver/SizeLimitedInputStream.java
Index: SizeLimitedInputStream.java
===================================================================
RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SizeLimitedInputStream.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SizeLimitedInputStream.java 2001/05/11 09:47:16 1.1
+++ SizeLimitedInputStream.java 2001/11/26 03:28:25 1.2
@@ -16,10 +16,12 @@
* @author Matthew Pangaro <ma...@lokitech.com>
*/
public class SizeLimitedInputStream extends InputStream {
- /** Maximum number of bytes to read.
+ /**
+ * Maximum number of bytes to read.
*/
private long maxmessagesize = 0;
- /** Running total of bytes read from wrapped stream.
+ /**
+ * Running total of bytes read from wrapped stream.
*/
private long bytesread = 0;
@@ -27,7 +29,8 @@
*/
private InputStream in = null;
- /** Constructor for the stream. Wraps an underlying stream.
+ /**
+ * Constructor for the stream. Wraps an underlying stream.
* @param in InputStream to use as basis for new Stream.
* @param maxmessagesize Message size limit, in Kilobytes
*/
@@ -36,8 +39,27 @@
this.maxmessagesize = maxmessagesize;
}
- /** Overrides the read method of InputStream to call the read() method of the
+ /**
+ * Overrides the read method of InputStream to call the read() method of the
* wrapped input stream.
+ * @throws IOException Throws a MessageSizeException, which is a sub-type of IOException
+ * @return Returns the number of bytes read.
+ */
+ public int read(byte[] b, int off, int len) throws IOException {
+ int l = in.read(b, off, len);
+
+ bytesread += l;
+
+ if (maxmessagesize > 0 && bytesread > maxmessagesize) {
+ throw new MessageSizeException();
+ }
+
+ return l;
+ }
+
+ /**
+ * Overrides the read method of InputStream to call the read() method of the
+ * wrapped input stream.
* @throws IOException Throws a MessageSizeException, which is a sub-type of IOException.
* @return Returns the int character value of the byte read.
*/
@@ -50,4 +72,3 @@
}
}
}
-
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>