JAVA 控制台循环输入

public void sendPWlistResultRet(String[] args) throws Exception {
		System.out.println("开始测试:");
		BufferedReader reader = null;

		PWlistResultRetPtc p = new PWlistResultRetPtc();

		boolean flag = true;
		while (flag) {
			Thread.sleep(3000);
			boolean flag2 = true;
			int flag3 = 0;
			while (flag2) {
				System.out.print("\t请输入'事件编号'(最长16,不能为空):");
				reader = new BufferedReader(new InputStreamReader(System.in));
				String eventId = reader.readLine().trim();
				if (isContinue(eventId)) {
					flag3 = 1;
					flag2 = false;
				} else if (isExit(eventId)) {
					flag3 = 2;
					flag2 = false;
				} else {
					if (eventId.length() > 0 && eventId.length() <= 16) {
						p.setEventId(eventId);
						flag2 = false;
					}
				}
			}
			if (flag3 == 1) {
				continue;
			} else if (flag3 == 2) {
				break;
			}
			flag3 = 0;
			flag2 = true;
			while (flag2) {
				System.out.print("\t请输入'文件名称'(最长64,不能为空):");
				reader = new BufferedReader(new InputStreamReader(System.in));
				String fileName = reader.readLine().trim();
				if (isContinue(fileName)) {
					flag3 = 1;
					flag2 = false;
				} else if (isExit(fileName)) {
					flag3 = 2;
					flag2 = false;
				} else {
					if (fileName.length() > 0 && fileName.length() <= 64) {
						p.setFileName(fileName);
						flag2 = false;
					}
				}
			}
			if (flag3 == 1) {
				continue;
			} else if (flag3 == 2) {
				break;
			}
			flag3 = 0;
			flag2 = true;
			while (flag2) {
				System.out.print("\t请输入'文件大小'(最大4倍整数,不能为空):");
				reader = new BufferedReader(new InputStreamReader(System.in));
				String fileSize = reader.readLine().trim();
				if (isContinue(fileSize)) {
					flag3 = 1;
					flag2 = false;
				} else if (isExit(fileSize)) {
					flag3 = 2;
					flag2 = false;
				} else {
					try {
						int size = Integer.parseInt(fileSize);
						if (size > 0 && size <= 9999) {
							p.setFileSize((short) size);
							flag2 = false;
						}
					} catch (Exception e) {

					}
				}
			}
			System.out.println("调用接口开始:");
			sendBytes(p.toBytes());
			System.out.println("调用接口结束!");
			flag = false;
		}
		System.out.println("结束测试");
	}

	public static void main(String[] args) throws Exception {
		System.out.println("测试开始:");
		BufferedReader reader = null;
		boolean flag = true;
		System.out.println("接口:\n  1:接口1\n  2:接口2\n  3: 接口3");
		while (flag) {
			System.out.print("请输入要测试的接口:");
			try {
				reader = new BufferedReader(new InputStreamReader(System.in));
				String command = reader.readLine().trim();

				TestWspMinaClient wmc = new TestWspMinaClient();
				wmc.connect();

				if (command.equalsIgnoreCase("1")) {
					wmc.sendLimitListSyncReq(args);
				} else if (command.equalsIgnoreCase("2")) {
					wmc.sendMWlistSyncReq(args);
				} else if (command.equalsIgnoreCase("3")) {
					wmc.sendPWlistResultRet(args);
				} else {
					System.out.println("输入参数错误!");
					continue;
				}
			} catch (Exception e) {
				e.printStackTrace();
				continue;
			}
			boolean flag2 = true;
			while (flag2) {
				try {
					System.out.print("是否继续测试,Y/N:");
					reader = new BufferedReader(new InputStreamReader(System.in));
					String yOrN = reader.readLine().trim();
					if (yOrN.equalsIgnoreCase("Y")) {
						flag2 = false;
					} else if (yOrN.equalsIgnoreCase("N")) {
						flag = false;
						flag2 = false;
					}
				} catch (Exception e) {
					e.printStackTrace();
					continue;
				}
			}
		}
		System.out.println("测试结束!");
	}

 

你可能感兴趣的:(Java)