I've looked at other questions and tried to correct the code in ways that were suggest by those and it is not passing, still.
public List<FileProperties> getFileList() throws Exception {
if (!Files.isRegularFile(zipFile)) throw new NoSuchZipFileException();
List<FileProperties> files = new ArrayList<>();
try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(zipFile))) {
ZipEntry zipEntry;
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
copyData(zipInputStream, baos);
files.add(new FileProperties(zipEntry.getName(), zipEntry.getSize(),
zipEntry.getCompressedSize(), zipEntry.getMethod()));
}
zipInputStream.closeEntry();
}
return files;
}
package com.codegym.task.task31.task3110;
import com.codegym.task.task31.task3110.exception.NoSuchZipFileException;
import java.io.IOException;
public class Archiver {
public static void main(String[] args) throws IOException {
Operation operation = null;
do {
try {
operation = askOperation();
CommandExecutor.execute(operation);
} catch (NoSuchZipFileException e) {
ConsoleHelper.writeMessage("You didn't select an archive or you selected an invalid file.");
} catch (Exception e) {
ConsoleHelper.writeMessage("An error occurred. Please check the entered data.");
}
} while (operation != Operation.EXIT);
}
public static Operation askOperation() throws IOException {
ConsoleHelper.writeMessage("");
ConsoleHelper.writeMessage("Select an operation:");
ConsoleHelper.writeMessage(String.format("\t %d - Zip files into an archive", Operation.CREATE.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - Add a file to an archive", Operation.ADD.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - Remove a file from an archive", Operation.REMOVE.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - Extract an archive", Operation.EXTRACT.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - View the contents of an archive", Operation.CONTENT.ordinal()));
ConsoleHelper.writeMessage(String.format("\t %d - Exit", Operation.EXIT.ordinal()));
return Operation.values()[ConsoleHelper.readInt()];
}
}