IO.java
01 /*
02  * Java Genetic Algorithm Library (jenetics-3.7.0).
03  * Copyright (c) 2007-2016 Franz Wilhelmstötter
04  *
05  * Licensed under the Apache License, Version 2.0 (the "License");
06  * you may not use this file except in compliance with the License.
07  * You may obtain a copy of the License at
08  *
09  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * Author:
18  *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
19  */
20 package org.jenetics.tool.trial;
21 
22 import java.io.BufferedReader;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.InputStreamReader;
27 import java.io.OutputStream;
28 import java.nio.file.Path;
29 import java.util.stream.Collectors;
30 
31 /**
32  @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
33  @version 3.4
34  @since 3.4
35  */
36 public class IO {
37 
38     public static String toText(final InputStream streamthrows IOException {
39         final InputStreamReader reader = new InputStreamReader(stream);
40         final BufferedReader buffer = new BufferedReader(reader);
41 
42         return buffer.lines().collect(Collectors.joining("\n"));
43     }
44 
45     public static void write(final String value, final Path path)
46         throws IOException
47     {
48         try (OutputStream out = new FileOutputStream(path.toFile())) {
49             out.write(value.getBytes("UTF-8"));
50         }
51     }
52 
53 }