Defaultbeanfactory, check_charset 备忘
来源:互联网 发布:原材料价格查询软件 编辑:程序博客网 时间:2024/06/05 20:07
java项目获取实例化对象
</pre><pre code_snippet_id="1937090" snippet_file_name="blog_20161019_3_8507335" name="code" class="html">public class DefaultBeanFactory {private final static String APP_CTX = "default";private static String seletor;public final static Object getBean(String beanName){return getBean(beanName,APP_CTX);}public final static Object getBean(String beanName,String ctxName){return getFactory(ctxName).getBean(beanName);}protected final static BeanFactory getFactory(String ctxName){BeanFactoryLocator beanFactoryLocator = seletor == null ? SingletonBeanFactoryLocator.getInstance():SingletonBeanFactoryLocator.getInstance(seletor);BeanFactoryReference ref = beanFactoryLocator.useBeanFactory(ctxName);return ref.getFactory();}public final static BeanFactory getFactory(){BeanFactoryLocator beanFactoryLocator = seletor == null ? SingletonBeanFactoryLocator.getInstance():SingletonBeanFactoryLocator.getInstance(seletor);BeanFactoryReference ref = beanFactoryLocator.useBeanFactory(APP_CTX);return ref.getFactory();}public final static boolean isSingleton(String beanName){return isSingleton(beanName,APP_CTX);}public final static boolean isSingleton(String beanName,String ctxName){return getFactory(ctxName).isSingleton(beanName);}public static void setSeletor(String seletor) {DefaultBeanFactory.seletor = seletor;}}
检测文件编码---
public class LookupCharset {private Logger log = Logger.getLogger(getClass());/** 字符集对象 */private Charset charset = Charset.defaultCharset();/** 找到某个字符集的布尔变量 */private boolean found = false;/** * 构造方法 * * @param file */public LookupCharset(File file) {lookup(file);}/** * 获取字符集 * * @return */public Charset getCharset() {return charset;}/** * 查找指定文件的字符集 * * @param file */protected void lookup(File file) {// Initalize the nsDetector() ;nsDetector det = new nsDetector(nsPSMDetector.ALL);// 语言线索常量// Set an observer...// The Notify() will be called when a matching charset is found.det.Init(new nsICharsetDetectionObserver() {// nsICharsetDetectionObserver.Notify编码识别成功后掉用public void Notify(String charsetName) {charset = Charset.forName(charsetName);found = true;}});BufferedInputStream imp = null;try {// 读取文件imp = new BufferedInputStream(new FileInputStream(file));byte[] buf = new byte[1024];int len = imp.read(buf, 0, buf.length); // 读取一个缓存区的数据boolean isAscii = det.isAscii(buf, len);// 先测试Asciiif (!isAscii) {det.DoIt(buf, buf.length, false);// 测试}det.DataEnd();// 测试结束!if (isAscii) {charset = Charset.forName("ASCII");found = true;}if (!found) {// 没找到设定一个最有可能的编码!!String prob[] = det.getProbableCharsets();charset = Charset.forName(prob[0]);}} catch (IOException e) {log.error(e);} finally {try {if (imp != null) {imp.close();}} catch (IOException e) {log.error(e);}}}}
实例:
DefaultBeanFactory.getBean("monitorService");
BundleConfig functionBundle = new BundleConfig("function");(附件jar)读取property文件
0 0
- Defaultbeanfactory, check_charset 备忘
- 备忘
- 备忘
- 备忘
- 备忘
- 备忘
- 备忘
- 备忘
- 备忘
- 备忘
- 备忘
- 备忘
- 备忘
- 备忘
- 备忘
- 备忘
- 备忘
- 备忘
- Service里常驻Notification,可以在后台低内存的时候不被kill
- 使用Log4Net - 文件日志
- C++类静态成员与类静态成员函数
- 设计模式总结(1)之设计模式分类
- 自己写BootLoader
- Defaultbeanfactory, check_charset 备忘
- javascript 对象、面向对象、变量和属性的关系
- nodejs-EventEmitter
- 天天写「业务代码」,如何成为「技术大牛」?
- 互联网广告系统综述八机器学习与数据
- 使用Python的multiprocessing.connections实现远程方法调用(RPC)
- opencv中的 HOGDescriptor 类
- 从SharePoint 2013迁移到SharePoint Online - 评估工具
- debuggerd