本文整理汇总了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;
}
示例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);
}