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

📄 upload.java

📁 JAVA邮件系统
💻 JAVA
字号:
//取得文件上载信息:
class Upload
{
	byte[] bBoundary = new byte[100];
	byte[] bFileName = new byte[100];
	byte[] bPath = new byte[100];
	int nStart=0,nBoundaryLength;

	Upload(byte[] bInf)
	{
		int nPlace;
		byte[] bTmp= {0x0d,0x0a};
		byte[] bTmp2={0x22,0x0d,0x0a};
		byte[] bTmp3={0x0d,0x0a,0x0d,0x0a};
		//取得分界byte数组:
		bBoundary[0] = 0x0d;
		bBoundary[1] = 0x0a;
		nPlace = this.findInArray(bInf,bTmp,0,bInf.length);
		//取得开始边界 和结束边界:
		byte[] bBegin = new byte[nPlace];
		if(nPlace!=-1) {
			for(int i=0;i<nPlace;i++){
				bBoundary[i+2] = bInf[i];
				bBegin[i]=bInf[i];
			}
			bBoundary[nPlace+2]=0x2d;
			bBoundary[nPlace+3]=0x2d;
			bBoundary[nPlace+4]=0x0d;
			bBoundary[nPlace+5]=0x0a;
			nBoundaryLength=nPlace+6;
		}
		
		//取得上传路径:
		int nPlace2;
		nPlace2 = this.findInArray(bInf,"name=\"into\"",0,bInf.length);
		if(nPlace2!=-1)
			nPlace = this.findInArray(bInf,bTmp,nPlace2+15,bInf.length);
		else
			nPlace=-1;
		if(nPlace!=-1)
			for(int i=nPlace2+15;i<nPlace;i++){
				bPath[i-nPlace2-15]=bInf[i];
			}
		
		//取得文件名:
		nPlace2 = this.findInArray(bInf,"name=\"file\"; filename=\"",0,bInf.length);
		if(nPlace2!=-1)
			nPlace = this.findInArray(bInf,bTmp2,nPlace2,bInf.length);
		else
			nPlace = -1;
		int nFileBegin=0;
		
		if(nPlace!=-1){
			for(int i=nPlace-1;i>0;i--)
				if(bInf[i]==0x5c||bInf[i]==0x22) {
					nFileBegin=i+1;
					break;
				}
			for(int i=nFileBegin;i<nPlace;i++) {
				bFileName[i-nFileBegin]=bInf[i];
			}
		}
		
		//正文开始的地方
		nPlace = this.findInArray(bInf,bTmp3,nPlace2,bInf.length);
		if(nPlace!=-1)
			nStart=nPlace+4;
	}
	
	public String getFilePath()
	{
		return new String (bPath);
	}
	
	public String getFileName()
	{
		return new String (bFileName);
	}
	
	public byte[] getBoundary()
	{
		byte[] bTmp = new byte[nBoundaryLength];
		for(int i=0;i<nBoundaryLength;i++)
			bTmp[i]=bBoundary[i];
		return bTmp;
	}
	
	public int getStartPlace()
	{
		return nStart;
	}
	
	public int findInArray(byte[] Src,String Des,int nBeginSearch,int nEndSearch){
		if( Src==null || Des == null )
			return -1;
		if( nBeginSearch+nEndSearch>Src.length )
			nEndSearch = Src.length -nBeginSearch;
		byte[] bDes = Des.getBytes();
		for(int i=nBeginSearch;i<nBeginSearch+nEndSearch;i++ ){
			if( Src[i]==bDes[0] ){
				boolean same = true;
				for( int j=0;j<bDes.length ;j++ ){
					if(i+j>=Src.length)
						return -1;
					if( Src[i+j] != bDes[j] ){
						same = false;
						break;
					}
				}
				if( same)
					return i; 
			}
		}
		return -1;
	}
	
	public int findInArray(byte[] Src,byte[] bDes,int nBeginSearch,int nEndSearch){
		if( Src==null || bDes == null )
			return -1;
		if( nBeginSearch+nEndSearch>Src.length )
			nEndSearch = Src.length -nBeginSearch;
		for(int i=nBeginSearch;i<nBeginSearch+nEndSearch;i++ ){
			if( Src[i]==bDes[0] ){
				boolean same = true;
				for( int j=0;j<bDes.length ;j++ ){
					if(i+j>=Src.length)
						return -1;
					if( Src[i+j] != bDes[j] ){
						same = false;
						break;
					}
				}
				if( same)
					return i; 
			}
		}
		return -1;
	}
	
	public int findInArray(byte[] Src,byte[] bDes,int nBeginSearch,int nEndSearch,int nDesLength){
		if( Src==null || bDes == null )
			return -1;
		if( nBeginSearch+nEndSearch>Src.length )
			nEndSearch = Src.length -nBeginSearch;
		if(nDesLength==0)
			nDesLength=bDes.length;
		for(int i=nBeginSearch;i<nBeginSearch+nEndSearch;i++ ){
			if( Src[i]==bDes[0] ){
				boolean same = true;
				for( int j=0;j<nDesLength;j++ ){
					if(i+j>=Src.length)
						return -1;
					if( Src[i+j] != bDes[j] ){
						same = false;
						break;
					}
				}
				if( same)
					return i; 
			}
		}
		return -1;
	}
}

⌨️ 快捷键说明

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