1 9 package org.lucane.server.web; 10 11 import java.io.FilterInputStream ; 12 import java.io.IOException ; 13 import java.io.InputStream ; 14 import java.io.OutputStream ; 15 16 import javax.activation.DataSource ; 17 18 28 public class MultipartInputStream 29 extends FilterInputStream 30 implements DataSource { 31 32 private int m_Limit; 34 private String m_ContentType; 35 private int m_BytesRead=0; 36 37 48 public MultipartInputStream(InputStream in, String ctype, int readlimit) { 49 super((InputStream )in); 50 m_ContentType=ctype; 51 m_Limit=readlimit; 52 } 54 60 public String getName() { 61 return("form_data"); 62 } 64 72 public String getContentType() { 73 return m_ContentType; 74 } 76 84 public InputStream getInputStream() 85 throws IOException { 86 87 return (InputStream )this; 88 } 90 99 public OutputStream getOutputStream() 100 throws IOException { 101 102 throw new IOException ("Cannot output to this source."); 103 } 105 117 public int read() throws IOException { 118 m_BytesRead++; 119 checkLimit(); 120 return super.read(); 121 } 123 140 public int read(byte b[],int off , int len) 141 throws IOException { 142 m_BytesRead+=len; 143 checkLimit(); 144 return super.read(b,off,len); 145 } 147 153 private void checkLimit() 154 throws IOException { 155 156 if(m_BytesRead>m_Limit) { 157 throw new IOException ("Input limit exceeded."); 158 } 159 } 161 } | Popular Tags |