]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.gnuplot/src/org/simantics/gnuplot/InputStreamToFileCopier.java
Added missing plug-ins from old SVN repository trunk
[simantics/platform.git] / bundles / org.simantics.gnuplot / src / org / simantics / gnuplot / InputStreamToFileCopier.java
1 package org.simantics.gnuplot;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.nio.file.Files;
6 import java.nio.file.Path;
7 import java.nio.file.StandardCopyOption;
8
9 /**
10  * @author Tuukka Lehtonen
11  * @since 1.24
12  */
13 class InputStreamToFileCopier implements Runnable {
14
15     private final InputStream in;
16     private final Path out;
17
18     public InputStreamToFileCopier(InputStream in, Path out) {
19         this.in = in;
20         this.out = out;
21     }
22
23     @Override
24     public void run() {
25         try {
26             if (out != null) {
27                 Files.copy(in, out, StandardCopyOption.REPLACE_EXISTING);
28             } else {
29                 drain(in);
30             }
31         } catch (IOException e) {
32             e.printStackTrace();
33         }
34     }
35
36     private static void drain(InputStream in) throws IOException {
37         while (in.read() >= 0);
38     }
39
40 }