diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/WriterActiveObject.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/WriterActiveObject.java new file mode 100644 index 0000000..430df08 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/WriterActiveObject.java @@ -0,0 +1,53 @@ +package de.dhbwstuttgart.typeinference.unify; + +import java.io.IOException; +import java.io.Writer; +import java.util.concurrent.ForkJoinPool; + +public class WriterActiveObject { + private Writer writer; + private ForkJoinPool pool; + + public WriterActiveObject(Writer writer, ForkJoinPool pool){ + this.writer = writer; + this.pool = pool; + } + + public void close(){ + pool.execute(()->{ + try { + writer.close(); + } catch (IOException e) { + System.out.println(e.getMessage()); + } + }); + } + + public void write(String message){ + pool.execute(()->{ + try { + writer.write(message); + writer.flush(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } + + public void writeNonThreaded(String message){ + try { + writer.write(message); + writer.flush(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public void closeNonThreaded(){ + try { + writer.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} \ No newline at end of file