java bug about ImageIo

package com.lingtu.model;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Vector;

import javax.imageio.ImageIO;

//http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4826548

public class IconResp {


public static String[] iconArray = new String[500];
public static Vector iconvec = new Vector();

public static void main(String[] args) {
// TODO Auto-generated method stub
new IconResp().getAllIcon();
}

public Vector getAllIcon(){
if (iconvec.size()==0) {
setIconVec();
}
for (int i = 0; i < iconvec.size(); i++) {
System.out.println(iconvec.get(i).toString());
}
return iconvec;
}

public void resetIconResp(){
iconvec.clear();
setIconVec();
}

public String[] getAllIconOnly1Level(){
if (iconArray[0]==null){
setIconArrayOnly1Level();
}
for (int i = 0; i < iconArray.length; i++) {
System.out.println(i+":"+iconArray[i]);
}
return iconArray;
}

public void setIconArrayOnly1Level(){
File f = new File(Const.ICON_RESP_PATH);
if (f.exists()&&f.isDirectory()) {
for (int i = 0; i < f.listFiles().length; i++) {
if (f.listFiles()[i].isFile()) {
String lowerExtName = f.listFiles()[i].getName();
lowerExtName=lowerExtName.substring(lowerExtName.length()-4, lowerExtName.length())
.toLowerCase();
if(".jpg.gif.png".indexOf(lowerExtName)!=-1)
iconArray[i] = f.listFiles()[i].getName() + "," + getWH(Const.ICON_RESP_PATH + File.separator + f.listFiles()[i].getName());
}
}
}
}

public void setIconVec(){
File f = new File(Const.ICON_RESP_PATH);
if (f.exists()&&f.isDirectory()) {
for (int i = 0; i < f.listFiles().length; i++) {
if (f.listFiles()[i].isFile()) {
String lowerExtName = f.listFiles()[i].getName();
lowerExtName=lowerExtName.substring(lowerExtName.length()-4, lowerExtName.length())
.toLowerCase();
if(Const.ICON_IMAGE_TYPE.indexOf(lowerExtName)!=-1)
iconvec.add(Const.ICON_ROOT_NAME + "," + "," + f.listFiles()[i].getName() + "," + getWH(Const.ICON_RESP_PATH + File.separator + f.listFiles()[i].getName()));
}else if(f.listFiles()[i].isDirectory()){
File f2 = f.listFiles()[i];
for (int j = 0; j < f2.listFiles().length; j++) {
if (f2.listFiles()[j].isFile()) {
String lowerExtName = f2.listFiles()[j].getName();
lowerExtName=lowerExtName.substring(lowerExtName.length()-4, lowerExtName.length())
.toLowerCase();
if(Const.ICON_IMAGE_TYPE.indexOf(lowerExtName)!=-1)
iconvec.add(f2.getName()+","+ f2.getName() + "," + f2.listFiles()[j].getName() + "," + getWH(Const.ICON_RESP_PATH + File.separator + f2.getName()+ File.separator + f2.listFiles()[j].getName()));
}
}
}
}
}
}

//得到形如 "width,height" 的字符串
public String getWH ( String strFileName){
//System.out.println(strFileName);
int iPicWidth = 0;
int iPicHeight = 0;
try {
strFileName = strFileName.replaceAll("\\\\", "\\\\\\\\");
File fPic = new File( strFileName);
InputStream in = new FileInputStream(fPic);
BufferedImage sourceImg = null;
if(in != null){
try {
sourceImg = ImageIO.read(in);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
if(sourceImg != null){
iPicWidth = sourceImg.getWidth();
iPicHeight = sourceImg.getHeight();
return iPicWidth + "," + iPicHeight;
}else{
System.out.println(strFileName+ "sourceImg is null!");
}
}
} catch (FileNotFoundException e) {
System.out.println("文件不存在!" + strFileName);
} catch (Exception e) {
return "1,1";
}
return "1,1";
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值