struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dilan" <di...@waterfind.com.au>
Subject Can't get FormFile to work
Date Fri, 08 Jul 2005 02:04:57 GMT

Hello,

I'm using
http://struts.apache.org/api/org/apache/struts/upload/FormFile.html 
and i have use both 
getFileData()
and getInputStream() 
each of the implementation, bigger files around 5K appear to be corrupted,
any reason behind that?

Can some one please help, for getInputStream() i used following code;



public byte[] read2array(FormFile file) throws Exception {
      InputStream in = null;
      byte[] out = new byte[0]; 
      try{
      
         in = new BufferedInputStream(file.getInputStream());
         // the length of a buffer can vary
         int bufLen = 1;//20000*1024;
         byte[] buf = new byte[bufLen];
         byte[] tmp = null;
         int len    = 0;
         while((len = in.read(buf,0,bufLen)) != -1){
            // extend array
            tmp = new byte[out.length + len];
            // copy data
            System.arraycopy(out,0,tmp,0,out.length);
            System.arraycopy(buf,0,tmp,out.length,len);
            out = tmp;
            tmp = null;            
         }
      }finally{
         // always close the stream 
         if (in != null) {
			 try{ 
				in.close();
				file.destroy();
			 }catch (Exception e){}
 
		 }
      }
      return out;  
 }

Regards,


Dilan



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message