package com.jspsmart.upload;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
public class SmartUpload
{
protected byte[] m_binArray;
protected HttpServletRequest m_request;
protected HttpServletResponse m_response;
protected ServletContext m_application;
private int m_totalBytes;
private int m_currentIndex;
private int m_startData;
private int m_endData;
private String m_boundary;
private long m_totalMaxFileSize;
private long m_maxFileSize;
private Vector m_deniedFilesList;
private Vector m_allowedFilesList;
private boolean m_denyPhysicalPath;
private boolean m_forcePhysicalPath;
private String m_contentDisposition;
public static final int SAVE_AUTO = 0;
public static final int SAVE_VIRTUAL = 1;
public static final int SAVE_PHYSICAL = 2;
private Files m_files;
private Request m_formRequest;
public SmartUpload()
{
this.m_totalBytes = 0;
this.m_currentIndex = 0;
this.m_startData = 0;
this.m_endData = 0;
this.m_boundary = new String();
this.m_totalMaxFileSize = 0L;
this.m_maxFileSize = 0L;
this.m_deniedFilesList = new Vector();
this.m_allowedFilesList = new Vector();
this.m_denyPhysicalPath = false;
this.m_forcePhysicalPath = false;
this.m_contentDisposition = new String();
this.m_files = new Files();
this.m_formRequest = new Request();
}
public final void init(ServletConfig servletconfig)
throws ServletException
{
this.m_application = servletconfig.getServletContext();
}
public void service(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
this.m_request = httpservletrequest;
this.m_response = httpservletresponse;
}
public final void initialize(ServletConfig servletconfig, HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException
{
this.m_application = servletconfig.getServletContext();
this.m_request = httpservletrequest;
this.m_response = httpservletresponse;
}
public final void initialize(PageContext pagecontext)
throws ServletException
{
this.m_application = pagecontext.getServletContext();
this.m_request = ((HttpServletRequest)pagecontext.getRequest());
this.m_response = ((HttpServletResponse)pagecontext.getResponse());
}
public final void initialize(ServletContext servletcontext, HttpSession httpsession, HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, JspWriter jspwriter)
throws ServletException
{
this.m_application = servletcontext;
this.m_request = httpservletrequest;
this.m_response = httpservletresponse;
}
public void upload()
throws ServletException, IOException, SmartUploadException
{
int i = 0;
boolean flag = false;
long l = 0L;
boolean flag1 = false;
String s = new String();
String s2 = new String();
String s4 = new String();
String s5 = new String();
String s6 = new String();
String s7 = new String();
String s8 = new String();
String s9 = new String();
String s10 = new String();
boolean flag2 = false;
this.m_totalBytes = this.m_request.getContentLength();
this.m_binArray = new byte[this.m_totalBytes];
while (i < this.m_totalBytes) {
int j;
try {
this.m_request.getInputStream();
j = this.m_request.getInputStream().read(this.m_binArray, i, this.m_totalBytes - i);
}
catch (Exception exception)
{
throw new SmartUploadException("Unable to upload.");
}
i += j;
}
for (; (!(flag1)) && (this.m_currentIndex < this.m_totalBytes); this.m_currentIndex += 1)
if (this.m_binArray[this.m_currentIndex] == 13)
flag1 = true;
else
this.m_boundary += (char)this.m_binArray[this.m_currentIndex];
if (this.m_currentIndex == 1)
return;
for (this.m_currentIndex += 1; this.m_currentIndex < this.m_totalBytes; this.m_currentIndex += 2)
{
String s1 = getDataHeader();
this.m_currentIndex += 2;
boolean flag3 = s1.indexOf("filename") > 0;
String s3 = getDataFieldValue(s1, "name");
if (flag3)
{
s6 = getDataFieldValue(s1, "filename");
s4 = getFileName(s6);
s5 = getFileExt(s4);
s7 = getContentType(s1);
s8 = getContentDisp(s1);
s9 = getTypeMIME(s7);
s10 = getSubTypeMIME(s7);
}
getDataSection();
if ((flag3) && (s4.length() > 0))
{
if (this.m_deniedFilesList.contains(s5))
throw new SecurityException("The extension of the file is denied to be uploaded (1015).");
if ((!(this.m_allowedFilesList.isEmpty())) && (!(this.m_allowedFilesList.contains(s5))))
throw new SecurityException("The extension of the file is not allowed to be uploaded (1010).");
if ((this.m_maxFileSize > 0L) && (this.m_endData - this.m_startData + 1 > this.m_maxFileSize))
throw new SecurityException("Size exceeded for this file : " + s4 + " (1105).");
l += this.m_endData - this.m_startData + 1;
if ((this.m_totalMaxFileSize > 0L) && (l > this.m_totalMaxFileSize))
throw new SecurityException("Total File Size exceeded (1110).");
}
if (flag3)
{
File file = new File();
file.setParent(this);
file.setFieldName(s3);
file.setFileName(s4);
file.setFileExt(s5);
file.setFilePathName(s6);
file.setIsMissing(s6.length() == 0);
file.setContentType(s7);
file.setContentDisp(s8);
file.setTypeMIME(s9);
file.setSubTypeMIME(s10);
if (s7.indexOf("application/x-macbinary") > 0)
this.m_startData += 128;
file.setSize(this.m_endData - this.m_startData + 1);
file.setStartData(this.m_startData);
file.setEndData(this.m_endData);
this.m_files.addFile(file);
}
else {
String s11 = new String(this.m_binArray, this.m_startData, this.m_endData - this.m_startData + 1);
this.m_formRequest.putParameter(s3, s11);
}
if ((char)this.m_binArray[(this.m_currentIndex + 1)] == '-')
return;
}
}
public int save(String s)
throws ServletException, IOException, SmartUploadException
{
return save(s, 0);
}
public int save(String s, int i)
throws ServletException, IOException, SmartUploadException
{
int j = 0;
if (s == null)
s = this.m_application.getRealPath("/");
if (s.indexOf("/") != -1)
{
if (s.charAt(s.length() - 1) != '/')
s = s + "/";
}
else if (s.charAt(s.length() - 1) != '\\')
s = s + "\\";
for (int k = 0; k < this.m_files.getCount(); ++k)
if (!(this.m_files.getFile(k).isMissing()))
{
this.m_files.getFile(k).saveAs(s + this.m_files.getFile(k).getFileName(), i);
++j;
}
return j;
}
public int getSize()
{
return this.m_totalBytes;
}
public byte getBinaryData(int i)
{
byte byte0;
try
{
byte0 = this.m_binArray[i];
}
catch (Exception exception)
{
throw new ArrayIndexOutO
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ImageDemo.rar (43个子文件)
ImageDemo
.settings
src
com
jspsmart
upload
Files.java 1KB
Request.java 2KB
SmartUploadException.java 148B
File.java 6KB
SmartUpload.java 21KB
teetaa
util
ImageHepler.java 3KB
servlet
UpLoadUserHeadImage.java 2KB
ZoomImage.java 2KB
.project 1KB
WebRoot
css
main.css 2KB
uploadimage.jsp 6KB
image
_h.gif 255B
_c.gif 255B
track.gif 571B
bg_120.gif 794B
grip.gif 587B
c.gif 258B
blank.jpg 7KB
h.gif 258B
Thumbs.db 14KB
man.GIF 2KB
META-INF
MANIFEST.MF 39B
WEB-INF
web.xml 975B
classes
com
jspsmart
upload
SmartUploadException.class 386B
SmartUpload.class 17KB
Files.class 2KB
File.class 6KB
Request.class 2KB
teetaa
util
ImageHepler.class 3KB
servlet
ZoomImage.class 3KB
UpLoadUserHeadImage.class 3KB
lib
UploadPhoto
Thumbs.db 6KB
20090117105013734.jpg 30KB
index.html 2KB
js
ui.draggable.packed.js 10KB
JSintellisense
jquery-1.2.6-intellisense.js 133KB
CutPic.js 9KB
jquery1.2.6.pack.js 30KB
ui.core.packed.js 4KB
User
UserHeadImage
Thumbs.db 5KB
20090117105013734.jpg 3KB
.mymetadata 300B
.classpath 340B
.myeclipse
共 43 条
- 1
belie_xiang
- 粉丝: 7
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Flume进阶-自定义拦截器jar包
- Dubins曲线算法讲解和在运动规划中的使用.pdf
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.dta
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.xlsx
- Reeds+Shepp曲线算法讲解和实现.pdf
- 毕业设计基于SpringBoot+MyBatisPlus+MySQL+Vue的外卖配送信息系统源代码+数据库
- 词向量(Word Embeddings)是自然语言处理(NLP)领域的一种重要技术.txt
- Surfer,线性函数
- MyBatis 的动态 SQL 是其核心特性之一.txt
- 时代的sdddsddsddsd
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页