当前位置: 首页>>代码示例>>Java>>正文


Java ServletContextResource.getFile方法代码示例

本文整理汇总了Java中org.springframework.web.context.support.ServletContextResource.getFile方法的典型用法代码示例。如果您正苦于以下问题:Java ServletContextResource.getFile方法的具体用法?Java ServletContextResource.getFile怎么用?Java ServletContextResource.getFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.context.support.ServletContextResource的用法示例。


在下文中一共展示了ServletContextResource.getFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getImageMap

import org.springframework.web.context.support.ServletContextResource; //导入方法依赖的package包/类
private Map<String, List<Image>> getImageMap() throws IOException {
    
    ServletContextResource imagesRes 
    = new ServletContextResource(getServletContext(), this.imageDirectory);
    
    File imagesFile = imagesRes.getFile();
    
    final Map<String, List<Image>> images = new TreeMap<String, List<Image>>();
    File[] imageFiles = imagesFile.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {

            FileSystemResource file = new FileSystemResource(new File(dir, name));
            
            for (String ext : exts) {
                if (name.toLowerCase().endsWith(ext)) { 
                    try {
                        BufferedImage img = ImageIO.read(file.getFile());
                        
                        String key = name.substring(0, name.length() - ext.length());
                        key = name.substring(0, key.length() - 2);
                        
                        List<Image> imageList = images.get(key);
                        if (imageList == null) {
                            imageList = new ArrayList<Image>(1);
                            images.put(key, imageList);
                        }
                        imageList.add(img);
                        return true;
                    } catch (IOException e) { 
                        return false;
                    }
                }
            }
            return false;
            
        }});


    return images;
    
}
 
开发者ID:luox12,项目名称:onecmdb,代码行数:43,代码来源:IconGenerator.java

示例2: addHandler

import org.springframework.web.context.support.ServletContextResource; //导入方法依赖的package包/类
public ModelAndView addHandler(HttpServletRequest request,
        HttpServletResponse respone, IconOptionsCommand optionsCommand) throws IOException {

    HashMap<String, Object> data = new HashMap<String, Object>();

    
    
    ServletContextResource depot
    = new ServletContextResource(getServletContext(), this.imageDirectory);

    
    
    
    String imageid = optionsCommand.getIconid();
    if (imageid != null) {
    
        
        final ByteArrayInputStream in = new ByteArrayInputStream(optionsCommand.getIconData());
        final BufferedImage image = ImageIO.read(in);
        
        for (double f = 16.0; f <= 48.0; f += 16)
        {
            
            Image scaled = image.getScaledInstance((int) f, (int) f, java.awt.Image.SCALE_AREA_AVERAGING);
            
            
            BufferedImage scaledImage = toBufferedImage(scaled);
            
            final File file = new File(depot.getFile(), imageid  + ((int) f) + ".png");
            ImageIO.write(scaledImage, "png", file);
            
        }

        data.put("successful", true);
    
    }
    
    
    
    return new ModelAndView("imageAdd", "imageAdd", data);

    
}
 
开发者ID:luox12,项目名称:onecmdb,代码行数:44,代码来源:IconGenerator.java


注:本文中的org.springframework.web.context.support.ServletContextResource.getFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。