001package net.gdface.utils; 002 003import java.io.ByteArrayInputStream; 004import java.io.File; 005import java.io.FileNotFoundException; 006import java.io.IOException; 007import java.util.Iterator; 008 009import javax.imageio.ImageIO; 010import javax.imageio.ImageReader; 011import javax.imageio.stream.MemoryCacheImageInputStream; 012 013public class FaceUtilitsX { 014 015 /** 016 * 通过 {@link ImageIO#getImageReaders(Object)}获å–图åƒç±»åž‹ï¼Œè¿”å›žæ–‡ä»¶æ ¼å¼å,如"jpeg","gif"<br> 017 * 用于ä¿å˜å›¾åƒæ–‡ä»¶æ—¶çš„åŽç¼€å 018 * @param img å›¾åƒæ•°æ® 019 * @return 020 * @throws IllegalArgumentException {@code img}为null或空å—符串"" 021 * @throws IOException 022 * @see ImageIO#getImageReaders(Object) 023 * @see ImageReader#getFormatName() 024 */ 025 public static String getFormatName(byte[] img) throws IllegalArgumentException, IOException{ 026 Assert.notEmpty(img, "img"); 027 028 Iterator<ImageReader> it = ImageIO.getImageReaders(new MemoryCacheImageInputStream( 029 new ByteArrayInputStream(img))); 030 if (!it.hasNext()) 031 throw new IOException("UNRECOGNIZED IMG FORMAT"); 032 ImageReader reader = it.next(); 033 try{ 034 return reader.getFormatName(); 035 }finally{ 036 reader.dispose(); 037 } 038 039 } 040 041 /** 042 * å½“ç±»è¢«åŠ è½½çš„æ—¶å€™,æ ¹æ®çŽ¯å¢ƒå˜é‡â€˜is_building’判æ–当剿˜¯è¿è¡Œçжæ€è¿˜æ˜¯ä»£ç 编译构建状æ€<br> 043 * 如果没有定义环境å˜é‡ï¼Œåˆ™é»˜è®¤ä¸ºfalse<br> 044 * 045 * @return 046 */ 047 public static final boolean isBuilding() { 048 if (null == FaceUtilitsX.IS_BUILDING) { 049 FaceUtilitsX.IS_BUILDING = Boolean.valueOf(FaceUtilitsX.getRuntimeProperty("is_building")); 050 } 051 return FaceUtilitsX.IS_BUILDING; 052 } 053 054 private static Boolean IS_BUILDING=null; 055 056 /** 057 * 通过环境å˜é‡CATALINA_HOME,获å–axis2/WEB-INF/confçš„ä½ç½®<br> 058 * 如果没有定义CATALINA_HOME或没有找到/webapps/axis2/WEB-INF/conf,则抛出{@link FileNotFoundException} 059 * @return 返回conf文件夹ä½ç½® 060 * @throws FileNotFoundException 061 */ 062 public static File getAxis2Conf() throws FileNotFoundException{ 063 String tomcat=System.getenv("CATALINA_HOME"); 064 if(Judge.isEmpty(tomcat)) 065 throw new FileNotFoundException("NOT DEFINED environment variable CATALINA_HOME,can't locate configuration file"); 066 File conf = new File(tomcat+"/webapps/axis2/WEB-INF/conf"); 067 if(!conf.exists()||!conf.isDirectory()) 068 throw new FileNotFoundException(String.format("NOT FOUND %s for configuration file",conf)); 069 return conf; 070 071 } 072 073 /** 074 * å½“ç±»è¢«åŠ è½½çš„æ—¶å€™,æ ¹æ®çŽ¯å¢ƒå˜é‡â€˜notLoadCodeTableâ€™åˆ¤æ–æ˜¯å¦è¦åŠ è½½code表<br> 075 * 如果没有定义环境å˜é‡ï¼Œåˆ™é»˜è®¤ä¸ºfalse<br> 076 * @return 077 */ 078 public static final boolean notLoadCodeTable() { 079 return Boolean.valueOf(FaceUtilitsX.getRuntimeProperty("notLoadCodeTable")); 080 } 081 082 public static final String getRuntimeProperty(String key){ 083 String value = System.getProperty(key); 084 if (null == value) 085 value = System.getenv(key); 086 System.out.printf("environment variable(java property) %s=%b\n", key, Boolean.valueOf(value)); 087 return value; 088 } 089 090}