/** * Reads a line from the standard input and returns it. */ @Impure private static @Nonnull String readLine() { try { final @Nullable String input = reader.readLine(); if (input == null) { throw new IOException("The end of the standard input has been reached."); } Log.information("Read the line $ from the console.", input); return input; } catch (@Nonnull IOException exception) { throw UncheckedExceptionBuilder.withCause(exception).build(); } }
/** * Writes the given message to the standard output without terminating the line. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void write(@Nonnull CharSequence message, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { final @Nonnull String formattedMessage = Strings.format(message, arguments); System.out.print(formattedMessage); Log.information("Wrote the string $ to the console.", formattedMessage); }
/** * Writes the given message to the standard output and terminates the line. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void writeLine(@Nonnull CharSequence message, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { final @Nonnull String formattedMessage = Strings.format(message, arguments); System.out.println(formattedMessage); Log.information("Wrote the line $ to the console.", formattedMessage); }