java文件上传 jsp-smartupload UTF-8 程序源码(1)
http://hi.baidu.com/wangdeen/blog/item/33b8f11f9c8c7ffce1fe0b61.html
java文件上传 jsp-smartupload UTF-8 程序源码(2)
http://hi.baidu.com/wangdeen/blog/item/6c454854b8978f5d574e0070.html
public void downloadField(ResultSet resultset,String s,String s1,String s2) throws ServletException,IOException,SQLException
{
if(resultset == null)
{
throw new IllegalArgumentException("The RecordSet cannot be null (1045).");
}
if(s == null)
{
throw new IllegalArgumentException("The columnName cannot be null (1050).");
}
if(s.length() == 0)
{
throw new IllegalArgumentException("The columnName cannot be empty (1055).");
}
byte abyte0[] = resultset.getBytes(s);
if(s1 == null)
{
m_response.setContentType("application/x-msdownload");
}
else
{
if(s1.length() == 0)
{
m_response.setContentType("application/x-msdownload");
}
else
{
m_response.setContentType(s1);
}
}
m_response.setContentLength(abyte0.length);
if(s2 == null)
{
m_response.setHeader("Content-Disposition","attachment;");
}
else
{
if(s2.length() == 0)
{
m_response.setHeader("Content-Disposition","attachment;");
}
else
{
m_response.setHeader("Content-Disposition","attachment; filename=" + s2);
}
}
m_response.getOutputStream().write(abyte0,0,abyte0.length);
}
public void fieldToFile(ResultSet resultset,String s,String s1) throws ServletException,IOException,SmartUploadException,SQLException
{
try
{
if(m_application.getRealPath(s1) != null)
{
s1 = m_application.getRealPath(s1);
}
InputStream inputstream = resultset.getBinaryStream(s);
FileOutputStream fileoutputstream = new FileOutputStream(s1);
int i;
while((i = inputstream.read()) != -1)
{
fileoutputstream.write(i);
}
fileoutputstream.close();
}
catch(Exception exception)
{
throw new SmartUploadException("Unable to save file from the DataBase (1020).");
}
}
private String getDataFieldValue(String s,String s1)
{
String s2 = ""; // = new String();
String s3 = ""; // = new String();
int i = 0;
//boolean flag = false;
//boolean flag1 = false;
//boolean flag2 = false;
s2 = s1 + "=" + '"';
i = s.indexOf(s2);
if(i > 0)
{
int j = i + s2.length();
int k = j;
s2 = "\"";
int l = s.indexOf(s2,j);
if(k > 0 && l > 0)
{
s3 = s.substring(k,l);
}
}
return s3;
}
private String getFileExt(String s)
{
String s1; // = new String();
int i = 0;
int j = 0;
if(s == null)
{
return null;
}
i = s.lastIndexOf('.') + 1;
j = s.length();
s1 = s.substring(i,j);
if(s.lastIndexOf('.') > 0)
{
return s1;
}
else
{
return "";
}
}
private String getContentType(String s)
{
String s1 = ""; // = new String();
String s2 = ""; // = new String();
int i = 0;
//boolean flag = false;
s1 = "Content-Type:";
i = s.indexOf(s1) + s1.length();
if(i != -1)
{
int j = s.length();
s2 = s.substring(i,j);
}
return s2;
}
private String getTypeMIME(String s)
{
//String s1 = new String();
int i = 0;
i = s.indexOf("/");
if(i != -1)
{
return s.substring(1,i);
}
else
{
return s;
}
}
private String getSubTypeMIME(String s)
{
//String s1 = new String();
//boolean flag = false;
int i = 0;
i = s.indexOf("/") + 1;
if(i != -1)
{
int j = s.length();
return s.substring(i,j);
}
else
{
return s;
}
}
private String getContentDisp(String s)
{
//String s1 = new String();
String s1 = "";
int i = 0;
int j = 0;
i = s.indexOf(":") + 1;
j = s.indexOf(";");
s1 = s.substring(i,j);
return s1;
}
private void getDataSection()
{
//boolean flag = false;
//String s = "";
//String s = new String();
int i = m_currentIndex;
int j = 0;
int k = m_boundary.length();
m_startData = m_currentIndex;
m_endData = 0;
while(i < m_totalBytes)
{
if(m_binArray[i] == (byte)m_boundary.charAt(j))
{
if(j == k - 1)
{
m_endData = ((i - k) + 1) - 3;
break;
}
i++;
j++;
}
else
{
i++;
j = 0;
}
}
m_currentIndex = m_endData + k + 3;
}
private String getDataHeader()
{
//boolean flag = false;
int i = m_currentIndex;
int j = 0;
for (boolean flag1 = false; !flag1;)
if (m_binArray[m_currentIndex] == 13
&& m_binArray[m_currentIndex + 2] == 13) {
flag1 = true;
j = m_currentIndex - 1;
m_currentIndex = m_currentIndex + 2;
} else {
m_currentIndex++;
}
String s = null;
//s = new String(m_binArray, i, (j - i) + 1);
try
{
s = new String(m_binArray, i, (j - i) + 1,this.getCharset());
}
catch(Exception e)
{
s = "";
}
return s;
}
private String getFileName(String s)
{
//String s1 = ""; // = new String();
//String s2 = ""; // = new String();
//boolean flag = false;
//boolean flag1 = false;
//boolean flag2 = false;
int i = 0;
i = s.lastIndexOf('/');
if(i != -1)
{
return s.substring(i + 1,s.length());
}
i = s.lastIndexOf('\\');
if(i != -1)
{
return s.substring(i + 1,s.length());
}
else
{
return s;
}
}
public void setDeniedFilesList(String s) throws ServletException,IOException,SQLException
{
//String s1 = "";
if(s != null)
{
String s2 = "";
for(int i = 0;i < s.length();i++)
{
if(s.charAt(i) == ',')
{
if(!m_deniedFilesList.contains(s2))
{
m_deniedFilesList.addElement(s2);
}
s2 = "";
}
else
{
s2 = s2 + s.charAt(i);
}
}
//if(s2 != "")
if(!s2.equals(""))
{
m_deniedFilesList.addElement(s2);
}
}
else
{
m_deniedFilesList = null;
}
}
public void setAllowedFilesList(String s)
{
//String s1 = "";
if(s != null)
{
String s2 = "";
for(int i = 0;i < s.length();i++)
{
if(s.charAt(i) == ',')
{
if(!m_allowedFilesList.contains(s2))
{
m_allowedFilesList.addElement(s2);
}
s2 = "";
}
else
{
s2 = s2 + s.charAt(i);
}
}
//if(s2 != "")
if(!s2.equals(""))
{
m_allowedFilesList.addElement(s2);
}
}
else
{
m_allowedFilesList = null;
}
}
public void setDenyPhysicalPath(boolean flag)
{
m_denyPhysicalPath = flag;
}
public void setForcePhysicalPath(boolean flag)
{
//m_forcePhysicalPath = flag;
}
public void setContentDisposition(String s)
{
m_contentDisposition = s;
}
public void setTotalMaxFileSize(long l)
{
m_totalMaxFileSize = l;
}
public void setMaxFileSize(long l)
{
m_maxFileSize = l;
}
java文件上传 jsp-smartupload UTF-8 程序源码(4)
http://hi.baidu.com/wangdeen/blog/item/47a8982516870e6935a80f72.html