1 24 package org.riotfamily.forms.fileupload; 25 26 import java.io.IOException ; 27 28 import javax.servlet.ServletInputStream ; 29 30 34 public class CountingServletInputStream extends ServletInputStream { 35 36 private ServletInputStream sourceStream; 37 38 private long bytesRead; 39 40 public CountingServletInputStream() { 41 } 42 43 public void setSourceStream(ServletInputStream sourceStream) { 44 this.sourceStream = sourceStream; 45 } 46 47 public int read() throws IOException { 48 if (sourceStream == null) { 49 throw new IllegalMonitorStateException ("No sourceStream set"); 50 } 51 int i = sourceStream.read(); 52 if (i >= 0) { 53 bytesRead ++; 54 } 55 return i; 56 } 57 58 public long getBytesRead() { 59 return bytesRead; 60 } 61 } 62 | Popular Tags |