用JspSmart组件实现文件上传和下载

由于www.jspsmart.com停止运营,我将其源代码写出来。JspSmart的源代码只有五个类,分别为File,Files,Request,SmartUploadException和主要业务类SmartUpload,软件包名为com.jspsmart.upload

File.java

import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;

// Referencedclassesofpackagecom.jspsmart.upload:
// SmartUploadException,SmartUpload

public class File
... {

privateSmartUploadm_parent;
privateintm_startData;
privateintm_endData;
privateintm_size;
privateStringm_fieldname;
privateStringm_filename;
privateStringm_fileExt;
privateStringm_filePathName;
privateStringm_contentType;
privateStringm_contentDisp;
privateStringm_typeMime;
privateStringm_subTypeMime;
privateStringm_contentString;
privatebooleanm_isMissing;
publicstaticfinalintSAVEAS_AUTO=0;
publicstaticfinalintSAVEAS_VIRTUAL=1;
publicstaticfinalintSAVEAS_PHYSICAL=2;

File()
...{
m_startData
=0;
m_endData
=0;
m_size
=0;
m_fieldname
=newString();
m_filename
=newString();
m_fileExt
=newString();
m_filePathName
=newString();
m_contentType
=newString();
m_contentDisp
=newString();
m_typeMime
=newString();
m_subTypeMime
=newString();
m_contentString
=newString();
m_isMissing
=true;
}


publicvoidsaveAs(Strings)
throwsIOException,SmartUploadException
...{
saveAs(s,
0);
}


publicvoidsaveAs(Strings,inti)
throwsIOException,SmartUploadException
...{
Strings1
=newString();
s1
=m_parent.getPhysicalPath(s,i);
if(s1==null)
thrownewIllegalArgumentException("Thereisnospecifieddestinationfile(1140).");
try
...{
java.io.Filefile
=newjava.io.File(s1);
FileOutputStreamfileoutputstream
=newFileOutputStream(file);
fileoutputstream.write(m_parent.m_binArray,m_startData,m_size);
fileoutputstream.close();
}

catch(IOExceptionioexception)
...{
thrownewSmartUploadException("Filecan'tbesaved(1120).");
}

}


publicvoidfileToField(ResultSetresultset,Strings)
throwsServletException,IOException,SmartUploadException,SQLException
...{
longl=0L;
inti=0x10000;
intj=0;
intk=m_startData;
if(resultset==null)
thrownewIllegalArgumentException("TheRecordSetcannotbenull(1145).");
if(s==null)
thrownewIllegalArgumentException("ThecolumnNamecannotbenull(1150).");
if(s.length()==0)
thrownewIllegalArgumentException("ThecolumnNamecannotbeempty(1155).");
l
=BigInteger.valueOf(m_size).divide(BigInteger.valueOf(i)).longValue();
j
=BigInteger.valueOf(m_size).mod(BigInteger.valueOf(i)).intValue();
try
...{
for(inti1=1;(long)i1<l;i1++)
...{
resultset.updateBinaryStream(s,
newByteArrayInputStream(m_parent.m_binArray,k,i),i);
k
=k!=0?k:1;
k
=i1*i+m_startData;
}


if(j>0)
resultset.updateBinaryStream(s,
newByteArrayInputStream(m_parent.m_binArray,k,j),j);
}

catch(SQLExceptionsqlexception)
...{
byteabyte0[]=newbyte[m_size];
System.arraycopy(m_parent.m_binArray,m_startData,abyte0,
0,m_size);
resultset.updateBytes(s,abyte0);
}

catch(Exceptionexception)
...{
thrownewSmartUploadException("UnabletosavefileintheDataBase(1130).");
}

}


publicbooleanisMissing()
...{
returnm_isMissing;
}


publicStringgetFieldName()
...{
returnm_fieldname;
}


publicStringgetFileName()
...{
returnm_filename;
}


publicStringgetFilePathName()
...{
returnm_filePathName;
}


publicStringgetFileExt()
...{
returnm_fileExt;
}


publicStringgetContentType()
...{
returnm_contentType;
}


publicStringgetContentDisp()
...{
returnm_contentDisp;
}


publicStringgetContentString()
...{
Strings
=newString(m_parent.m_binArray,m_startData,m_size);
returns;
}


publicStringgetTypeMIME()
throwsIOException
...{
returnm_typeMime;
}


publicStringgetSubTypeMIME()
...{
returnm_subTypeMime;
}


publicintgetSize()
...{
returnm_size;
}


protectedintgetStartData()
...{
returnm_startData;
}


protectedintgetEndData()
...{
returnm_endData;
}


protectedvoidsetParent(SmartUploadsmartupload)
...{
m_parent
=smartupload;
}


protectedvoidsetStartData(inti)
...{
m_startData
=i;
}


protectedvoidsetEndData(inti)
...{
m_endData
=i;
}


protectedvoidsetSize(inti)
...{
m_size
=i;
}


protectedvoidsetIsMissing(booleanflag)
...{
m_isMissing
=flag;
}


protectedvoidsetFieldName(Strings)
...{
m_fieldname
=s;
}


protectedvoidsetFileName(Strings)
...{
m_filename
=s;
}


protectedvoidsetFilePathName(Strings)
...{
m_filePathName
=s;
}


protectedvoidsetFileExt(Strings)
...{
m_fileExt
=s;
}


protectedvoidsetContentType(Strings)
...{
m_contentType
=s;
}

<im
分享到:
评论

你可能感兴趣的:(java,sql,servlet,J#)