All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dromara.hutool.extra.compress.archiver.Archiver Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2023 looly([email protected])
 * Hutool is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

package org.dromara.hutool.extra.compress.archiver;

import org.dromara.hutool.core.text.StrUtil;

import java.io.Closeable;
import java.io.File;
import java.util.function.Predicate;

/**
 * 数据归档封装,归档即将几个文件或目录打成一个压缩包
 *
 * @author looly
 */
public interface Archiver extends Closeable {

	/**
	 * 将文件或目录加入归档,目录采取递归读取方式按照层级加入
	 *
	 * @param file 文件或目录
	 * @return this
	 */
	default Archiver add(final File file) {
		return add(file, null);
	}

	/**
	 * 将文件或目录加入归档,目录采取递归读取方式按照层级加入
	 *
	 * @param file   文件或目录
	 * @param predicate 文件过滤器,指定哪些文件或目录可以加入,{@link Predicate#test(Object)}为{@code true}时加入,null表示全部加入
	 * @return this
	 */
	default Archiver add(final File file, final Predicate predicate) {
		return add(file, StrUtil.SLASH, predicate);
	}

	/**
	 * 将文件或目录加入归档包,目录采取递归读取方式按照层级加入
	 *
	 * @param file   文件或目录
	 * @param path   文件或目录的初始路径,null表示位于根路径
	 * @param filter 文件过滤器,指定哪些文件或目录可以加入,{@link Predicate#test(Object)}为{@code true}保留,null表示全部加入
	 * @return this
	 */
	Archiver add(File file, String path, Predicate filter);

	/**
	 * 结束已经增加的文件归档,此方法不会关闭归档流,可以继续添加文件
	 *
	 * @return this
	 */
	Archiver finish();

	/**
	 * 无异常关闭
	 */
	@Override
	void close();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy