Home / Class/ ReaderThread Class — spring-boot Architecture

ReaderThread Class — spring-boot Architecture

Architecture documentation for the ReaderThread class in ProcessRunner.java from the spring-boot codebase.

Entity Profile

Source Code

core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/ProcessRunner.java lines 133–182

	private static class ReaderThread extends Thread {

		private final InputStream source;

		private final @Nullable Consumer<String> outputConsumer;

		private final StringBuilder output = new StringBuilder();

		private final CountDownLatch latch = new CountDownLatch(1);

		ReaderThread(InputStream source, String name, @Nullable Consumer<String> outputConsumer) {
			this.source = source;
			this.outputConsumer = outputConsumer;
			setName("OutputReader-" + name);
			setDaemon(true);
			start();
		}

		@Override
		public void run() {
			try (BufferedReader reader = new BufferedReader(
					new InputStreamReader(this.source, StandardCharsets.UTF_8))) {
				String line = reader.readLine();
				while (line != null) {
					this.output.append(line);
					this.output.append("\n");
					if (this.outputConsumer != null) {
						this.outputConsumer.accept(line);
					}
					line = reader.readLine();
				}
				this.latch.countDown();
			}
			catch (IOException ex) {
				throw new UncheckedIOException("Failed to read process stream", ex);
			}
		}

		@Override
		public String toString() {
			try {
				this.latch.await();
				return this.output.toString();
			}
			catch (InterruptedException ex) {
				return "";
			}
		}

	}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free