• Jackrabbit 文件上传下载


    1. 在配置文件config.properties中: file.rmi=http://localhost:7000/rmi

    2. 下载 jackrabbit-standalone-2.10.1.jar,打开服务:java -jar jackrabbit-standalone-2.10.1.jar --port 7000

    3. 

    public class JackRabbitFileServiceImpl implements FileService {
    
        private static Repository repository;
    
        public static Session initSession(){  
            Session session=null;
            if(null==repository){
                try {
                    repository =  new URLRemoteRepository(ReadConfig.getValue("file.rmi"));
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            try {
                session=repository.login(new SimpleCredentials("admin","admin".toCharArray()));
            } catch (LoginException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (RepositoryException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return session;
        }
        
        @Override
        public String save(InputStream is, long filesize) {
            String fileId=KeyProvider.getPrimaryKey();
            try{
                Session session=initSession();
                Node root = session.getRootNode();
                String mimeType = "application/octet-stream";
                Node fileNode = root.addNode(fileId, "nt:file");
    
                Node resNode = fileNode.addNode("jcr:content", "nt:resource");
                resNode.setProperty("jcr:mimeType", mimeType);
                resNode.setProperty("jcr:encoding", "");
                resNode.setProperty("jcr:data", is);
    
                Calendar lastModified = Calendar.getInstance();
                resNode.setProperty("jcr:lastModified", lastModified);
    
                session.save();
                is.close();
                session.logout();
            }catch(Exception e){
                e.printStackTrace();
            }
            return fileId;
        }
    
        @Override
        public InputStream getFileById(String fileId) {
            InputStream is=null;
            try{
                Session session=initSession();
                Node root = session.getRootNode();
                if(root!=null){
                    NodeIterator filenodes = root.getNodes(fileId);
                    while (filenodes.hasNext()) {
        
                        Node n = filenodes.nextNode();
                        NodeIterator ni1 = n.getNodes();
                        while (ni1.hasNext()) {
        
                            Node n1 = ni1.nextNode();
        
                            if (n1.getName().equals("jcr:content")) {
                                is = n1.getProperty("jcr:data")
                                        .getStream();
                            }
                        }
                    }
                }
                session.logout();
            }catch(Exception e){
                e.printStackTrace();
            }
            return is;
        }
        
    }


  • 相关阅读:
    tornado开发学习之2.输入输出,数据库操作,内置模板,综合示例
    使用Python读取和写入mp3文件的id3v1信息
    在CentOS中部署Python和配置PyCharm开发环境
    Quartz Cron 表达式(时间格式的写法)
    使用Atomikos Transactions Essentials实现多数据源JTA分布式事务
    Grub4dos 硬盘引导 iso 文件
    NFS配置
    C++程序加载Flash动画
    在boost.foreach中操作迭代器
    WebContents类
  • 原文地址:https://www.cnblogs.com/PeterPan-luo/p/4546007.html
Copyright © 2020-2023  润新知