All pastes #459800 Raw Edit

Stuff

public text v1 · immutable
#459800 ·published 2007-04-26 18:12 UTC
rendered paste body
			int entry = 0;
			System.out.print(menu);
			while (entry != 9) {
				try 
				{//This try is to catch NumberFormatException.
					entry = Integer.parseInt(keyboard.readLine());
				} catch (NumberFormatException e) {
					System.out.println("Please only enter option number.");
				}
			
				//Switch the entry variable.
				switch (entry) {
				case 1://To Login
					System.out.println("Please enter password\n");
					String password = keyboard.readLine();
					try
					{
						jrss.login(password);
						System.out.println("Login successful.");
					}
					catch (RemoteException re)
					{
						System.out.println(re);
						keyboard.readLine();
					}
				break;
				case 2://Return details of files in the local working directory on the server
					try 
					{
						FileInfo fileInfo[] = jrss.ls();
						System.out.println("File name\tFile type\tFile size\tLast modified");
						System.out.println("_______________________________________________________________________");
						for (int i = 0; i < fileInfo.length;i++)
						{
							System.out.println(fileInfo[i].getFileName() +"\t"+fileInfo[i].getFileType()+"\t"+
							fileInfo[i].getFileSize()+"\t"+fileInfo[i].getModifyDate());
						}
						System.out.println("_______________________________________________________________________");
					}					
					catch (RemoteException re)
					{
						System.out.println(re);
					}

				break;
				
				
				case 3://Returns first <n> lines of a file
					String linesMsg[];
					System.out.println("Please enter file name under current direcotry:\n");
					String fileName = keyboard.readLine();
					System.out.println("Please enter number you like to read:\n");
					int lineNumber = 0;
					try 
					{//This try is to catch NumberFormatException.
						//Convert the input to Integer, if input is non-digits, throw exception;
						lineNumber = Integer.parseInt(keyboard.readLine());
					} catch (NumberFormatException e) {
						System.out.println("Please only enter digits.");
					}
					try 
					{
						linesMsg =jrss.lines(fileName,lineNumber);
						for (int i = 0; i < linesMsg.length; i++)
						{
							if (linesMsg[i] != null)
							{
								System.out.println(linesMsg[i]);
							}
						}
					}
					catch (RemoteException re)
					{
						System.out.println(re);
					}
				break;
				
				
				case 4://Change current working driectory on the server
					String childDirectory = keyboard.readLine();
					try
					{
						String cdMsg = jrss.cd(childDirectory);
						System.out.println(cdMsg);
					}
					catch (RemoteException re)
					{
						System.out.println(re);
					}
				break;
				
				
				case 5://Return working directory on the server
					try{
						String dir = jrss.pwd();
						System.out.println("The directory on server is: " + dir);
					}catch (RemoteException re)
					{
						System.out.println(re);
					}
				break;
				case 6://To logout from server
					try
					{
						if (jrss.logout())
						{
							System.out.println("Logout successful.");
						}
					}
					catch (RemoteException re)
					{
						System.out.println(re);
					}
					//loginState = "0";
				break;
				case 7://Quit client side application
					try
					{
						if (jrss.exit()) 
						{
							System.out.println("Client programme shut down successful!");
							System.exit(0);
						}					
					}
					catch (RemoteException re)
					{
						System.out.println(re);
					}
				break;
				case 8://Reprint menu;
					System.out.print(menu);
				break;

				default:
				System.out.println("Please select from 1-8 to operate.");
				
			}
		}