import ch09.Employee;
import ch09.IoUtils;
import ch09.Point;
import ch09.PointDisk;
import org.junit.Test;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class Chapter09 {
@Test
public void ex01() throws IOException {
Path source = Paths.get("docs/ch09/music.mp3");
Path target = Paths.get("docs/ch09/music.target.mp3");
try (InputStream in = Files.newInputStream(source);
OutputStream out = Files.newOutputStream(target);) {
IoUtils.copyWithTemp(in, out);
}
}
@Test
public void ex02() throws IOException {
Path source = Paths.get("docs/ch09/alice.txt");
Path target = Paths.get("docs/ch09/alice.toc");
// íì¼ì íì¤ì© ì½ì¼ë©´ì ë¼ì¸ ë²í¸ë¥¼ ê°ì ¸ì¬ ì ìë java.io.LineNumberReader
try (LineNumberReader reader = new LineNumberReader(Files.newBufferedReader(source, StandardCharsets.UTF_8));) {
// Map<ë¼ì¸ë²í¸, List<ë¨ì´>> ë¡ ë³ííë¤.
Map> mapFrom = reader.lines()
// ë¹ì´ìë ë¼ì¸ íí°
.filter(v -> !v.trim().isEmpty())
// 모ë ì문ìë¡ ë³ê²½
.map(String::toLowerCase)
// Map<ë¼ì¸ë²í¸, List<문ì>> ì¼ë¡ ë³ê²½
.collect(Collectors.toMap(
// í¤ë¥¼ ë¼ì¸ ë²í¸ë¡ ì¬ì©
t -> reader.getLineNumber(),
// ê°ë¥¼ String -> List ì¼ë¡ ì¬ì© (ë¹ë¬¸ì íí°, ë¨ì´ ì¤ë³µ ì ê±°)
t -> Arrays.stream(t.split("\\PL+")).filter(v -> !v.trim().isEmpty()).distinct()
.collect(Collectors.toList())));
// Map<ë¼ì¸ë²í¸, List<ë¨ì´>> 를 Map<ë¨ì´, List<ë¼ì¸ë²í¸>> ë¡ ë³ê²½íë¤.
Map> mapTo = mapFrom.entrySet().stream()
// Map<ë¼ì¸ë²í¸, List<ë¨ì´> -> Stream