Валя пишет что время ожидания вышло, а при запуске программы пишут что "invalid entry size (expected 6 but got 7 bytes)" в 41 строке
package com.javarush.task.task31.task3105;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
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 {
String fileName = args[0].substring(args[0].lastIndexOf("/") + 1);
HashMap<String, byte[]> files = new HashMap<>();
try (ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(args[1]));
FileInputStream fileInputStream= new FileInputStream(args[0])) {
ZipEntry entry;
while ((entry = zipInputStream.getNextEntry()) != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[100];
int countBytes;
while ((countBytes = zipInputStream.read(buffer)) != -1) {
baos.write(buffer, 0, countBytes);
}
files.put(entry.getName(), baos.toByteArray());
}
ZipEntry entryNew = new ZipEntry("new/" + fileName);
ByteArrayOutputStream baosNew = new ByteArrayOutputStream();
byte[] bufferNew = new byte[100];
int countBytesNew;
while ((countBytesNew = fileInputStream.read(bufferNew)) != -1) {
baosNew.write(bufferNew, 0, countBytesNew);
}
files.put(entryNew.getName(), baosNew.toByteArray());
}
try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(args[1]))) {
for (Map.Entry<String, byte[]> pair : files.entrySet()) {
zipOutputStream.putNextEntry(new ZipEntry(pair.getKey()));
zipOutputStream.write(pair.getValue());
}
}
}
}