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/06/30 03:30:14 UTC
Re: currupted data when using FormFile
Hello,
I'm trying to upload files using org.apache.struts.upload.FormFile
When I'm getting files larger than 20K or so, data get corrupted, is there
is a way to fix this,
This is the class I'm using to copy the data in to byte array;
public byte[] read2array(UploadTransferForm uForm) throws Exception {
InputStream in = null;
byte[] out = new byte[0];
try{
in = new
BufferedInputStream(uForm.getFileUpload().getInputStream());
// the length of a buffer can vary
int bufLen = 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();}catch (Exception e){}
}
return out;
}
Hope some one able to help;
Regards,
Dilan
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org