com.dangdang.config.service.file.protocol.Protocols Maven / Gradle / Ivy
package com.dangdang.config.service.file.protocol;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.Maps;
/**
* Protocol factory
*
* @author Yuxuan Wang
*
*/
public final class Protocols {
private Map> protocols;
private static Protocols INSTANCE = new Protocols();
private static final String REGISTER_FILE = "META-INF/toolkit/com.dangdang.config.service.file.protocol.Protocol";
private Protocols() {
try {
Properties props = new Properties();
// Load register file contents
Enumeration registerFiles = this.getClass().getClassLoader().getResources(REGISTER_FILE);
URL registerFile = null;
while (registerFiles.hasMoreElements()) {
registerFile = registerFiles.nextElement();
Path path = Paths.get(registerFile.toURI());
try (InputStream in = Files.newInputStream(path)) {
props.load(in);
}
}
// Initialize protocol beans
protocols = Maps.newHashMap();
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy