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

pull/24/merge
Project Nayuki 7 years ago
parent 9628e25971
commit 0f73afa367

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

Loading…
Cancel
Save