Не проходит по четвертому пунтку
package com.javarush.task.task31.task3105;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.InflaterInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
/*
Добавление файла в архив
*/
public class Solution {
public static void main(String[] args) throws IOException {
Path filePath = Paths.get(args[0]);
Path zipPath = Paths.get(args[1]);
// Path filePath = Paths.get("D:\\MyDownloads\\result.mp3");
// Path zipPath = Paths.get("D:\\MyDownloads\\test.zip");
Path newFilePath = Paths.get("new\\" + filePath.getFileName());
Map<String,ByteArrayOutputStream> map = new HashMap<>();
FileInputStream fileInputStream = new FileInputStream(zipPath.toString());
ZipInputStream zin = new ZipInputStream(fileInputStream);
ZipEntry entry;
for(;(entry = zin.getNextEntry())!= null;) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
String fileName = entry.getName();
byte [] buffer = new byte[1024];
for(int i = zin.read(buffer); i != -1; i = zin.read(buffer)) {
byteArrayOutputStream.write(buffer);
}
byteArrayOutputStream.close();
map.put(fileName,byteArrayOutputStream);
zin.closeEntry();
}
fileInputStream.close();
zin.close();
if(map.containsKey(filePath.getFileName().toString())) {
FileInputStream fileInputStream1 = new FileInputStream(filePath.toString());
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte buffer[] = new byte[1024];
for(int i = fileInputStream1.read(buffer); i!=-1; i = fileInputStream1.read(buffer)) {
byteArrayOutputStream.write(buffer);
}
byteArrayOutputStream.close();
map.put(filePath.getFileName().toString(),byteArrayOutputStream);
}
FileOutputStream fileOutputStream = new FileOutputStream(zipPath.toAbsolutePath().toString());
ZipOutputStream zout = new ZipOutputStream(fileOutputStream);
for (Map.Entry<String, ByteArrayOutputStream> stringByteArrayOutputStreamEntry : map.entrySet()) {
ZipEntry entry1 = new ZipEntry(stringByteArrayOutputStreamEntry.getKey());
zout.putNextEntry(entry1);
zout.write(stringByteArrayOutputStreamEntry.getValue().toByteArray());
zout.closeEntry();
}
if(!(map.containsKey(filePath.getFileName().toString()))) {
ZipEntry newZipEntry = new ZipEntry(newFilePath.toString());
zout.putNextEntry(newZipEntry);
Files.copy(filePath, zout);
zout.closeEntry();
}
zout.close();
}
}