piffy

Divoratore

Jul 5th, 2021
699
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Classe che consuma un InputStream
  2. //Adattato da https://www.baeldung.com/run-shell-command-in-java
  3.  
  4. import java.io.BufferedReader;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7. import java.util.function.Consumer;
  8.  
  9.  
  10. public class Divoratore implements Runnable {
  11.     private InputStream inputStream;
  12.     private Consumer<String> consumatore;
  13.  
  14.     public Divoratore(InputStream inputStream, Consumer<String> consumer) {
  15.         this.inputStream = inputStream;
  16.         this.consumatore = consumer;
  17.     }
  18.  
  19.     @Override
  20.     public void run() {
  21.         new BufferedReader(new InputStreamReader(inputStream)).lines().forEach(consumatore);
  22.     }
  23. }
RAW Paste Data