⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadutility.java

📁 JSP源码-jspupload.zip
💻 JAVA
字号:
//Source file: D:/MyWork/com/jspupload/UploadUtility.java

/////////////////////////////////////////////////////////////////////
// Author  : Sean B.C. Ryu (幅豪冕)
// E-Mail  : stater@chollian.net
// Date    : 2000.9.10
// Update  : 2000.9.20
// Version : 1.0
// Title   : JSP File Uploader
// Class   : UploadUtility
// Update History :
//      File Content甫 积己且 锭, 1官捞飘 菊阑 佬绰 滚弊 荐沥(2000.9.20)
//
// 捞 颇老篮 JSP File Uploader狼 老何 涝聪促.
// 夯 橇肺弊伐 傈眉俊 措茄 历累鼻篮 幅豪冕俊霸 乐嚼聪促.
// 捞 橇肺弊伐 肚绰 家胶狼 荤侩捞唱 硅器绰 磊蜡酚嚼聪促.
// 窍瘤父 公窜栏肺 函版窍角 荐 绰 绝嚼聪促.
// 窜 捞 橇肺弊伐阑 捞侩窍咯 傍何窍脚 饶, 犁累己窍绰 巴俊 措秦辑绰
// 包咯窍瘤 臼摆嚼聪促.
// 榴芭款 Java 傍何啊 登辨 瑚聪促.
////////////////////////////////////////////////////////////////////


package com.jspupload;

import java.util.Vector;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

/**
Utility Class
*/
public class UploadUtility 
{
   
   public UploadUtility() 
   {
   }
   
   /**
   @roseuid 39C1814400B5
   */
   public static Vector getFileList(HttpServletRequest request) throws CannotReadFileException,NoFileContentException 
   {
    Vector fileList = new Vector();
    
    //
    // content stream 狼 郴侩阑 byte 硅凯肺 函券窃.
    //
    int contentLength = request.getContentLength();
    byte [] binaryTemp = new byte[contentLength];
    InputStream is = null;
    try
    {
        int totalReadSize = 0;
        int readSize = 0;
        while(totalReadSize < contentLength)
        {
            is = request.getInputStream();
            readSize = is.read(binaryTemp, totalReadSize, contentLength - totalReadSize);
            totalReadSize += readSize;
        }
    }
    catch(IOException ioe)
    {
        ioe.printStackTrace();
    }
    
    // 
    // Boundary甫 茫绰促.
    //
    int currentIndex = 0;
    String boundary = new String();
    while( (currentIndex < contentLength) && (binaryTemp[currentIndex] != 13) )
    {
        boundary += (char)binaryTemp[currentIndex];
        currentIndex++;
    }
    
    if (currentIndex == 0)
    {
        throw new NoFileContentException();
    }
    
    //
    // 颇老按眉甫 积己窍绊 郴侩阑 盲款促.
    //
    while( (currentIndex < contentLength) && ((char)binaryTemp[currentIndex + 1] != '-'))
    {
        currentIndex += 2;

        // 庆歹 单捞磐甫 掘绰促.
        String dataHeaderStr = new String();
        while( (binaryTemp[currentIndex] != 13) || (binaryTemp[currentIndex+2] != 13) )
        {
            dataHeaderStr += (char)binaryTemp[currentIndex];
            currentIndex++;
        }
        
        currentIndex += 4;
        DataHeader dataHeader = new DataHeader(dataHeaderStr);
        
        File file = null;
        
        if (dataHeader.isFile())
        {
            
            file = new File(dataHeader);
            System.out.println("Mime Type : " + file.getMimeType());
        }
            
        // binary 单捞磐甫 掘绢柯促.
        int binaryStartPosition = currentIndex;
        int binaryEndPosition = currentIndex;
        int boundaryKeyPosition = 0;
            
        boolean binaryEndFound = false;
            
        while( (currentIndex < contentLength) && !binaryEndFound)
        {
            if(binaryTemp[currentIndex] == boundary.charAt(boundaryKeyPosition))
            {
                if( boundaryKeyPosition == boundary.length()-1 )
                {
                    binaryEndPosition = currentIndex - boundary.length() + 1 - 3;
                    binaryEndFound = true;
                }
                else
                {   
                    boundaryKeyPosition++;
                }
            }
            else
            {
                boundaryKeyPosition = 0;
            }
            currentIndex++;
        }
            
        int totalBinarySize = binaryEndPosition - binaryStartPosition + 1;
        
        if( (file != null) && (dataHeader.isFile()) )
        {
            file.setSize(totalBinarySize);
            if( !file.getName().equals("") && (file.getName() != null))
            {
                byte [] binaryArray = new byte[totalBinarySize];
                for(int i = 0; i < totalBinarySize; i++)
                {
                    binaryArray[i] = binaryTemp[binaryStartPosition + i];
                }

                file.setContents(binaryArray);            
                fileList.addElement(file);
            }
        }
    }
    
   	return fileList;
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -