【Java开源代码栏目提醒】:网学会员鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“upBean.java”一文,供大家参考学习
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2004-9-28 23:56:53
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: upBean.java
package xiaoxiang.fileUpload;
import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
// Referenced classes of package xiaoxiang.fileUpload:
// files, Request, file
public class upBean {
public upBean() {
m_files = new files();
m_totalBytes = 0;
m_currentIndex = 0;
m_startData = 0;
m_endData = 0;
m_boundary = new String();
m_totalMaxFileSize = 0L;
m_maxFileSize = 0L;
m_allowedExtList = new Vector();
m_allowedFileTypeList = new Vector();
m_formRequest = new Request();
m_count = 0;
isCover = true;
realPath = new String();
}
public final void initialize(PageContext pagecontext)
throws ServletException {
m_application = pagecontext.getServletContext();
m_request = (HttpServletRequest) pagecontext.getRequest();
m_response = (HttpServletResponse) pagecontext.getResponse();
}
/**
* @deprecated Method setRealPath is deprecated
*/
public void setRealPath(String pRealPath) {
realPath = pRealPath;
}
public String getRealPath() {
return realPath;
}
public void setIsCover(boolean pIsCover) {
isCover = pIsCover;
}
public void upload() throws ServletException, IOException, Exception {
int i = 0;
long maxSize = 0L;
boolean isBoundaryEnd = false;
String sFileName = new String();
String fileExtName = new String();
String dataFieldValue = new String();
String contentType = new String();
String typeMIME = new String();
String subTypeMIME = new String();
m_totalBytes = m_request.getContentLength();
m_binArray = new byte[m_totalBytes];
int j;
for (; i < m_totalBytes; i += j)
try {
m_request.getInputStream();
j =
m_request.getInputStream().read(
m_binArray,
i,
m_totalBytes - i);
} catch (Exception exception) {
throw new Exception("Unable to upload.");
}
for (;
!isBoundaryEnd && m_currentIndex < m_totalBytes;
m_currentIndex++)
if (m_binArray[m_currentIndex] == 13)
isBoundaryEnd = true;
else
m_boundary += (char) m_binArray[m_currentIndex];
if (m_currentIndex == 1)
return;
for (m_currentIndex++;
m_currentIndex < m_totalBytes;
m_currentIndex += 2) {
String dataHeader = getDataHeader();
m_currentIndex += 2;
boolean isFileObject = dataHeader.indexOf("filename") > 0;
String fieldName = getDataFieldValue(dataHeader, "name");
if (isFileObject) {
dataFieldValue = getDataFieldValue(dataHeader, "filename");
sFileName = getFileName(dataFieldValue);
fileExtName = getFileExt(sFileName);
contentType = getContentType(dataHeader);
typeMIME = getTypeMIME(contentType);
subTypeMIME = getSubTypeMIME(contentType);
}
getDataSection();
m_size = (m_endData - m_startData) + 1;
if (isFileObject && sFileName.length() > 0) {
if (!m_allowedExtList.isEmpty()
&& !m_allowedExtList.contains(fileExtName))
throw new SecurityException(
"\u60A8\u7684\u6587\u4EF6\u540E\u7F00\u540D\u4E0D\u7B26\u5408\u6211\u4EEC\u7684\u8BBE\u5B9A.\u6211\u4EEC\u53EA\u5141\u8BB8\u4EE5\u4E0B\u540E\u7F00\u540D\u7684\u6587\u4EF6\uFF1A"
+ m_allowedExtList.toString());
if (!m_allowedFileTypeList.isEmpty()
&& !m_allowedFileTypeList.contains(subTypeMIME))
throw new SecurityException(
"\u60A8\u7684\u6587\u4EF6\u7C7B\u578B\u4E0D\u7B26\u5408\u6211\u4EEC\u7684\u8BBE\u5B9A.\u6211\u4EEC\u53EA\u5141\u8BB8\u4EE5\u4E0B\u7C7B\u578B\u7684\u6587\u4EF6\uFF1A"
+ m_allowedFileTypeList.toString());
if (m_maxFileSize > 0L
&& (long) ((m_endData - m_startData) + 1) > m_maxFileSize)
throw new SecurityException(
"\u60A8\u4E0A\u4F20\u7684\u8FD9\u4E2A\u6587\u4EF6\u8D85\u8FC7\u4E86\u6211\u4EEC\u7684\u9650\u5236 : "
+ sFileName
+ ".\u6587\u4EF6\u7684\u5355\u4E2A\u5927\u5C0F\u5E94\u5C0F\u4E8E"
+ (m_maxFileSize / 1000L + 1L)
+ "kb");
maxSize += (m_endData - m_startData) + 1;
if (m_totalMaxFileSize > 0L && maxSize > m_totalMaxFileSize)
throw new Secu