Merge branch 'master' into BAEL-6541-convert-relative-path

This commit is contained in:
tienvn
2023-07-08 00:12:28 +07:00
529 changed files with 8371 additions and 1971 deletions
@@ -0,0 +1,31 @@
package com.baeldung.zipentries;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Scanner;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class ZipEntryReader {
public static void readZipEntries(String filePath) throws IOException {
try (ZipFile zipFile = new ZipFile(filePath)) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
// Check if entry is a directory
if (!entry.isDirectory()) {
// Read and process the entry contents using the inputStream
try (InputStream inputStream = zipFile.getInputStream(entry);
Scanner scanner = new Scanner(inputStream);) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
System.out.println(line);
}
}
}
}
}
}
}
@@ -0,0 +1,17 @@
package com.baeldung.zipentries;
import org.junit.Test;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
public class ZipEntryReaderUnitTest {
@Test
public void givenZipFile_thenReadEntriesAndValidateContent() throws URISyntaxException, IOException {
Path zipFilePath = Paths.get(getClass().getClassLoader().getResource("zipFile.zip").toURI());
ZipEntryReader.readZipEntries(zipFilePath.toString());
}
}