Updated Java worker program to close input stream and reduce indentation.

This commit is contained in:
Project Nayuki 2017-11-23 06:27:20 +00:00
parent 9628e25971
commit 0f73afa367
1 changed files with 59 additions and 55 deletions

View File

@ -38,14 +38,18 @@ public final class QrCodeGeneratorWorker {
public static void main(String[] args) {
// Set up input stream and start loop
Scanner input = new Scanner(System.in, "US-ASCII");
try (Scanner input = new Scanner(System.in, "US-ASCII")) {
input.useDelimiter("\r\n|\n|\r");
while (true) {
while (processCase(input));
}
}
private static boolean processCase(Scanner input) {
// Read data length or exit
int length = input.nextInt();
if (length == -1)
break;
return false;
if (length > Short.MAX_VALUE)
throw new RuntimeException();
@ -93,7 +97,7 @@ public final class QrCodeGeneratorWorker {
System.out.println(-1);
}
System.out.flush();
}
return true;
}
}