Всем привет. Я не могу понять, что он от меня хочет. Вроде делаешь всё как-то, итог правильный. Но ему что-то не нравится. Есть гуру по валидаторам?
package com.javarush.task.task31.task3105;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
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 filePath = args[0];
String zipPath = args[1];
ZipInputStream readZip = new ZipInputStream(new FileInputStream(zipPath));
ZipEntry entry;
Map<String, ByteArrayOutputStream> list = new TreeMap<>();
while ((entry = readZip.getNextEntry()) != null) {
if (!filePath.contains(entry.getName())) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
readZip.read(buffer, 0, buffer.length);
int counter = 0;
for (byte b : buffer) {
if (b != 0) counter++;
else break;
}
stream.write(buffer, 0, counter);
list.put(entry.getName(), stream);
stream.close();
}
}
readZip.close();
ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(zipPath));
File file = new File(filePath);
boolean isCreated = false;
for (Map.Entry<String, ByteArrayOutputStream> pair : list.entrySet()) {
zip.putNextEntry(new ZipEntry(pair.getKey()));
if (filePath.contains(pair.getKey().substring(pair.getKey().lastIndexOf("/")+1))) {
isCreated = true;
Files.copy(file.toPath(), zip);
} else {
zip.write(pair.getValue().toByteArray());
}
}
if (!isCreated) {
zip.putNextEntry(new ZipEntry("new/" + file.getName()));
Files.copy(file.toPath(), zip);
}
zip.close();
}
}