You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Dilan <di...@waterfind.com.au> on 2005/07/08 04:04:57 UTC

Can't get FormFile to work

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