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

📄 multiserver.java

📁 javaP2pgood.rar这个文件里面的代码我还没有看得懂
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
					String whole_String = v_file_name.get(1).toString();
					
					// Store file & directory path in full_path
					String  full_path = whole_String.substring(0, (whole_String.lastIndexOf("\\") + 1));
					
					// Store file & directory name without path in word variable
					String  word = whole_String.substring((whole_String.lastIndexOf("\\") + 1 ));			
					
					// Make file object of file which path present in full_path
			        path_file = new File(full_path);
			    
					
					// Find the position of "." in file
					int dot_index = word.indexOf('.');

		/* When "." not present in file then return -1 then enter in this condition otherwise enter
		 * in else part */
		if (dot_index == -1)
		{

			// whole word value store in left_half variable
			left_half = word;

			// write_half variable value become blank(" ")
			right_half = " ";

			// Find the position of "*" in left_half variable and store that variable in asterix_index
			int asterix_index = left_half.indexOf("*");

			// if left_half variable not content any "*" then its return -1 then not enter in this condition
			if (asterix_index != -1)
			{
				/* Store value in left_half first position to "*" position when check the left_half_flag 
				 * flag to true */
				left_half = left_half.substring(0,asterix_index);
				left_half_flag = true;
			}
		}
		else
		{
			// Store file name begining to "." position left part
		    left_half = word.substring(0,word.indexOf('.'));

			// Store file name last to "." position of right part of that file 
	  	    right_half = word.substring(word.indexOf('.') + 1);

			// left_half is equal to "*" or left_half is equal to "" then enter in this condition
		    if ((left_half.equals("*"))||(left_half.equals("")))
			 {
				 // left_half string value insilize by null(" ")
				 left_half = " ";
			 }
			 else
			 {
				// Find the position of "*" in left_half variable and store that variable in asterix_index
				int asterix_index = left_half.indexOf("*");

			    // if left_half variable not content any "*" then its return -1 then not enter in this condition
				if (asterix_index != -1)
				{

					/* Store value in left_half first position to "*" position when check the left_half_flag 
					 * flag to true */
					left_half = left_half.substring(0,asterix_index);
					left_half_flag = true;
				}
			  }
		   // right_half is equal to "*" or right_half is equal to "" then enter in this condition
		   if ((right_half.equals("*"))||(right_half.equals("")))
			{
			    // right_half string value insilize by null(" ")
				right_half = " ";
			}
			else
			{
				// Find the position of "*" in right_half variable and store that variable in asterix_index
				int asterix_index = right_half.indexOf("*");

			    // if right_half variable not content any "*" then its return -1 then not enter in this condition
				if (asterix_index != -1)
				{
					/* Store value in right_half first position to "*" position when check the right_half_flag 
					 * flag to true */
					right_half = right_half.substring(0,asterix_index);
					right_half_flag = true;
				}

			}
		 }

		// Store files name which are present in this path_file in files array  
	    files = path_file.list();


		// make object of String array which contents files & directories name filesize and mask  
		returnvalueoffiles = new String[files.length + 1][3];

		// Store all values in returnvalueoffiles array which return by wild_card function
		returnvalueoffiles =	check.wild_card(left_half,right_half,left_half_flag,right_half_flag, path_file);


			for(int y = 0; y < files.length + 1; y++)
				{
						/* data in this array returnvalueoffiles[y][0] not present in this then break the 
						 * the loop other wise go to else part  */	
						if(returnvalueoffiles[y][0] == null)
						{
							break;
						}
						else
						{
						
						// Store full path	with file & directories name in filename
						filename = path_file + "\\" + returnvalueoffiles[y][0];


						// Store size of file 
						filesize = returnvalueoffiles[y][1];


						// Store the writes of the files
						filemask = returnvalueoffiles[y][2];


						/* Call the returnHeader function from XmlWriter class this fuction return
						 * the header of xml file as string and store this value in stemp variable. */
						stemp = xmlwriter.returnHeader("SHOWFILES");
						
						/* Call the responseFString function from XmlWriter class this fuction 
						 * writes the xml file for Directroy. */
						xmlwriter.responseFString("SHOWFILES", filename, filesize, filemask);                             
						}
					 }
						
						String wholexmlwithoutheader = "";

						/* data in this array returnvalueoffiles[0][0] not present in this then enter
						 * in this condition it means there is no file and diretory is there otherwise 
						 * go to else part of this condition*/
						 if(returnvalueoffiles[0][0] == null)
							 {
								// Make one xml file without any files & directries list 
								stemp = xmlwriter.returnHeader("SHOWFILES");
								wholexmlwithoutheader = "</response></p2p_lng>";
							 }
						 else
							 {
					    		/* Call the returnResponse function this function return whole xml except header 
								 * of xml as string.Store this value in wholexmlwithoutheader veriable */
								wholexmlwithoutheader = xmlwriter.returnResponse();
							 }
					
								 /* Add two string veriable and store in any third string variable. This variable store whole
								  * xml file */
								 wholexmlwithoutheader = stemp+wholexmlwithoutheader;
					
								 // Find the length of xml file and send 0 to length of file xml file bytes to user
								 out.write(wholexmlwithoutheader.getBytes(),0,wholexmlwithoutheader.length());
								 
					 			 // Close the data_read stream which read from file.
								 out.close();
			
				}


		// vector value store is upload type then enter in this condition
		else if((v_file_name.get(t).toString()).equalsIgnoreCase("UPLOAD"))
			{
					// Store file & directory name with path in whole_String variable
					String upload_name = v_file_name.get(1).toString();

					
					// initilize the veriable of len
					int len = 0;
					
					// Make variable c_write as Byte array which send to user
					byte[] c_write = new byte[32];
			
					// open stream 	of upload_name file for writing
					data_write = new BufferedOutputStream(
					(new FileOutputStream(upload_name)));
					
				 // While loop run upto 32 Byte of all stored arrey value		
				 while ((len = in.read(c_write,0,32))>0)
				{
					// Send the out stream to user every 32 Byte
					data_write.write(c_write, 0, len);
			    }
				
				// Close the date_write stream
				data_write.close();

			}

		}
	} 
	catch (IOException e)
	{
		System.out.println("Exception ocurred" + e);
	} 
	
	}

}


public class MultiServer 
	{
		
		// Here inisilige the PORT
		static final int PORT = 7070;

	MultiServer()
		{
		}

	void multiaccess() throws IOException
		{
			
			/* Create a object of server socket on this port any client can connect and they can send
			* there request */
			ServerSocket s = new ServerSocket(PORT);
			System.out.println("Server Started");
		try
		{
			while (true)
			{
				
				System.out.println("Connection open first");
				// Create  a new socket for every client
				Socket soc = s.accept();
				System.out.println("Connection open" +soc);
				
				try
				{
				
					// Call the OneServer class and pass the connected client socket 
					new OneServer(soc);
				}
				catch (Exception e)
				{
		
				// Close the created socket
				soc.close();
				}
			}
		}
		catch (Exception e)
		{}

	}		
}

⌨️ 快捷键说明

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