2019-06-06 15:21:15 +03:00

43 lines
1.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package org.ansj.dic;
import org.ansj.dic.impl.File2Stream;
import org.ansj.dic.impl.Jar2Stream;
import org.ansj.dic.impl.Jdbc2Stream;
import org.ansj.dic.impl.Url2Stream;
import org.ansj.exception.LibraryException;
import java.io.InputStream;
/**
* 将路径转换为流如果你需要实现自己的加载器请实现这个类使用这个类可能需要自己依赖第三方包比如jdbc连接和nutz
*
* @author ansj
*
*/
public abstract class PathToStream {
public static InputStream stream(String path) {
try {
if (path.startsWith("file://")) {
return new File2Stream().toStream(path);
} else if (path.startsWith("jdbc://")) {
return new Jdbc2Stream().toStream(path);
} else if (path.startsWith("jar://")) {
return new Jar2Stream().toStream(path);
} else if (path.startsWith("class://")) {
((PathToStream) Class.forName(path.substring(8).split("\\|")[0]).newInstance()).toStream(path);
} else if (path.startsWith("http://") || path.startsWith("https://")) {
return new Url2Stream().toStream(path);
} else {
return new File2Stream().toStream(path);
}
} catch (Exception e) {
throw new LibraryException(e);
}
throw new LibraryException("not find method type in path " + path);
}
public abstract InputStream toStream(String path);
}