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

本文介绍了已停运网站www.jspsmart.com上的JspSmart文件上传组件,该组件包含五个核心类:File, Files, Request, SmartUploadException 和 SmartUpload。重点剖析了File类的功能实现,包括文件保存、数据库字段转换等方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于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;

//  Referenced classes of package com.jspsmart.upload:
//  SmartUploadException, SmartUpload

public   class  File
... {

private SmartUpload m_parent;
private int m_startData;
private int m_endData;
private int m_size;
private String m_fieldname;
private String m_filename;
private String m_fileExt;
private String m_filePathName;
private String m_contentType;
private String m_contentDisp;
private String m_typeMime;
private String m_subTypeMime;
private String m_contentString;
private boolean m_isMissing;
public static final int SAVEAS_AUTO = 0;
public static final int SAVEAS_VIRTUAL = 1;
public static final int SAVEAS_PHYSICAL = 2;

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


public void saveAs(String s)
throws IOException, SmartUploadException
...{
saveAs(s, 
0);
}


public void saveAs(String s, int i)
throws IOException, SmartUploadException
...{
String s1 
= new String();
s1 
= m_parent.getPhysicalPath(s, i);
if(s1 == null)
throw new IllegalArgumentException("There is no specified destination file (1140).");
try
...{
java.io.File file 
= new java.io.File(s1);
FileOutputStream fileoutputstream 
= new FileOutputStream(file);
fileoutputstream.write(m_parent.m_binArray, m_startData, m_size);
fileoutputstream.close();
}

catch(IOException ioexception)
...{
throw new SmartUploadException("File can't be saved (1120).");
}

}


public void fileToField(ResultSet resultset, String s)
throws ServletException, IOException, SmartUploadException, SQLException
...{
long l = 0L;
int i = 0x10000;
int j = 0;
int k = m_startData;
if(resultset == null)
throw new IllegalArgumentException("The RecordSet cannot be null (1145).");
if(s == null)
throw new IllegalArgumentException("The columnName cannot be null (1150).");
if(s.length() == 0)
throw new IllegalArgumentException("The columnName cannot be empty (1155).");
= BigInteger.valueOf(m_size).divide(BigInteger.valueOf(i)).longValue();
= BigInteger.valueOf(m_size).mod(BigInteger.valueOf(i)).intValue();
try
...{
for(int i1 = 1; (long)i1 < l; i1++)
...{
resultset.updateBinaryStream(s, 
new ByteArrayInputStream(m_parent.m_binArray, k, i), i);
= k != 0 ? k : 1;
= i1 * i + m_startData;
}


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

catch(SQLException sqlexception)
...{
byte abyte0[] = new byte[m_size];
System.arraycopy(m_parent.m_binArray, m_startData, abyte0, 
0, m_size);
resultset.updateBytes(s, abyte0);
}

catch(Exception exception)
...{
throw new SmartUploadException("Unable to save file in the DataBase (1130).");
}

}


public boolean isMissing()
...{
return m_isMissing;
}


public String getFieldName()
...{
return m_fieldname;
}


public String getFileName()
...{
return m_filename;
}


public String getFilePathName()
...{
return m_filePathName;
}


public String getFileExt()
...{
return m_fileExt;
}


public String getContentType()
...{
return m_contentType;
}


public String getContentDisp()
...{
return m_contentDisp;
}


public String getContentString()
...{
String s 
= new String(m_parent.m_binArray, m_startData, m_size);
return s;
}


public String getTypeMIME()
throws IOException
...{
return m_typeMime;
}


public String getSubTypeMIME()
...{
return m_subTypeMime;
}


public int getSize()
...{
return m_size;
}


protected int getStartData()
...{
return m_startData;
}


protected int getEndData()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值