com.jn.agileway.zip.format.ZipFormats Maven / Gradle / Ivy
package com.jn.agileway.zip.format;
import com.jn.langx.io.resource.Resource;
import com.jn.langx.io.resource.Resources;
import com.jn.langx.util.Strings;
import com.jn.langx.util.collection.Collects;
import com.jn.langx.util.function.Consumer;
import com.jn.langx.util.function.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class ZipFormats {
private static final Logger logger = LoggerFactory.getLogger(ZipFormats.class);
private ZipFormats() {
}
/**
* key: ZipFormat#getFormat()
*/
private static Map registry = new ConcurrentHashMap();
private static Set supportedFormats = new TreeSet(new Comparator() {
@Override
public int compare(String o1, String o2) {
if (o1.equals(o2)) {
return 0;
}
if (Strings.startsWith(o1, o2)) {
return -1;
}
if (Strings.startsWith(o2, o1)) {
return 1;
}
return o2.compareTo(o1);
}
});
static {
loadBuiltinZipFormats();
loadCustomizedZipFormats();
}
private static void loadBuiltinZipFormats() {
Resource resource = Resources.loadClassPathResource("/zipformats.yml");
InputStream stream = null;
try {
stream = resource.getInputStream();
Iterable