compress(OutputStream output, Map<String, InputStream> inputs) 추가
parent
ad015986ee
commit
091a5049b0
@ -0,0 +1,52 @@
|
||||
package cokr.xit.base.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ZIPTest {
|
||||
private static final String
|
||||
imgDir = "src/test/resources/images",
|
||||
resultDir = "src/test/resources/results";
|
||||
|
||||
@Test
|
||||
void compressDir() {
|
||||
new ZIP().compress(resultDir + "/img-dir.zip", imgDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
void compressFiles() {
|
||||
List<String> paths = Stream.of(new File(imgDir).listFiles())
|
||||
.map(file -> file.getAbsolutePath())
|
||||
.toList();
|
||||
new ZIP().compress(resultDir + "/img-files.zip", paths.toArray(new String[paths.size()]));
|
||||
}
|
||||
|
||||
@Test
|
||||
void compressInputStreams() {
|
||||
Map<String, InputStream> fileMap = Stream.of(new File(imgDir).listFiles())
|
||||
.collect(Collectors.toMap(
|
||||
file -> file.getName(),
|
||||
file -> {
|
||||
try {
|
||||
return new FileInputStream(file);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
try (FileOutputStream out = new FileOutputStream(new File(resultDir + "/inputstreams.zip"))) {
|
||||
new ZIP().compress(out, fileMap);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 197 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 271 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 225 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 284 KiB |
Loading…
Reference in New Issue