/
sazonovim
/
init-spring
Обзор
Документация
Войти
/
sazonovim
/
init-spring
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/main/java/pro/nikolaev/initspring/util/FilesUtils.java
61 строка
2 KB
Nikolaev Ilya V
updated metadata for next release
27 дек 2025, 23:38
27 дек 2025, 23:38
5660d89
Код
Авторство
О чём код?
/* * Copyright 2025 Ilya Nikolaev * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package pro.nikolaev.initspring.util; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @SuppressWarnings("ResultOfMethodCallIgnored") public final class FilesUtils { public static File createProjectDir(String location) { File projectDir = new File(location); if (!projectDir.exists()) { projectDir.mkdirs(); } return projectDir; } public static void unzipArchive(File archive, File destination) throws IOException { try (ZipInputStream zis = new ZipInputStream(new FileInputStream(archive))) { ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { Path archivePath = Path.of(entry.getName()); final boolean entryIsBaseDir = archivePath.getNameCount() == 1; if (entryIsBaseDir) { continue; } Path relativeToBaseDir = archivePath.subpath(1, archivePath.getNameCount()); Path newFileOrDir = destination.toPath().resolve(relativeToBaseDir); if (entry.isDirectory()) { Files.createDirectories(newFileOrDir); } else { Files.createDirectories(newFileOrDir.getParent()); Files.copy(zis, newFileOrDir); } zis.closeEntry(); } } } private FilesUtils() { } }