首页

关于imageio源码包Utilities工具包类判断类是否同一个接口、URL转存本地文件及获取对象类class名称简称等通用实现源码说明

标签:imageio,Utilities,工具包类,imageio-ext-utilities,URL转File     发布时间:2018-07-03   

一、前言

关于imageio的imageio-ext-utilities-1.0.6-1.jar源码包中it.geosolutions.imageio.utilities.Utilities工具包类,实现判断类是否同一个sameInterfaces接口、URL转存本地文件urlToFile方法及获取对象类class名称简称getShortClassName等通用实现源码说明,具体参见源码说明。

二、源码说明

package it.geosolutions.imageio.utilities;@b@@b@import java.io.File;@b@import java.io.UnsupportedEncodingException;@b@import java.net.URL;@b@import java.net.URLDecoder;@b@import java.util.Arrays;@b@@b@public final class Utilities@b@{@b@  private static final int MAX_SUBSAMPLING_FACTOR = 2147483647;@b@  private static final int MAX_LEVELS = 31;@b@  private static final String[] spacesFactory = new String[20];@b@@b@  public static boolean equals(Object object1, Object object2)@b@  {@b@    return ((object1 == object2) || ((object1 != null) && (object1.equals(object2))));@b@  }@b@@b@  public static boolean sameInterfaces(Class object1, Class object2, Class base)@b@  {@b@    Class c;@b@    if (object1 == object2)@b@      return true;@b@@b@    if ((object1 == null) || (object2 == null))@b@      return false;@b@@b@    Class[] c1 = object1.getInterfaces();@b@    Class[] c2 = object2.getInterfaces();@b@@b@    int n = 0;@b@    for (int i = 0; i < c2.length; ++i) {@b@      c = c2[i];@b@      if (base.isAssignableFrom(c)) {@b@        c2[(n++)] = c;@b@      }@b@@b@    }@b@@b@    for (i = 0; i < c1.length; ++i) {@b@      c = c1[i];@b@      if (base.isAssignableFrom(c)) {@b@        for (int j = 0; j < n; ++j)@b@          if (c.equals(c2[j])) {@b@            System.arraycopy(c2, j + 1, c2, j, --n - j);@b@            break label154:@b@          }@b@@b@        return false;@b@      }@b@    }@b@    label154: return (n == 0);@b@  }@b@@b@  public static String spaces(int length)@b@  {@b@    int last = spacesFactory.length - 1;@b@    if (length < 0)@b@      length = 0;@b@    if (length <= last) {@b@      if (spacesFactory[length] == null) {@b@        if (spacesFactory[last] == null) {@b@          blancs = new char[last];@b@          Arrays.fill(blancs, ' ');@b@          spacesFactory[last] = new String(blancs).intern();@b@        }@b@        spacesFactory[length] = spacesFactory[last].substring(0, length).intern();@b@      }@b@@b@      return spacesFactory[length];@b@    }@b@    char[] blancs = new char[length];@b@    Arrays.fill(blancs, ' ');@b@    return new String(blancs);@b@  }@b@@b@  public static String getShortName(Class classe)@b@  {@b@    if (classe == null)@b@      return "<*>";@b@@b@    int dimension = 0;@b@@b@    while ((el = classe.getComponentType()) != null) {@b@      Class el;@b@      classe = el;@b@      ++dimension;@b@    }@b@    String name = classe.getName();@b@    int lower = name.lastIndexOf(46);@b@    int upper = name.length();@b@    name = name.substring(lower + 1, upper).replace('$', '.');@b@    if (dimension != 0) {@b@      StringBuffer buffer = new StringBuffer(name);@b@      do@b@        buffer.append("[]");@b@      while (--dimension != 0);@b@      name = buffer.toString();@b@    }@b@    return name;@b@  }@b@@b@  public static File urlToFile(URL url)@b@  {@b@    String path3;@b@    String string = url.toExternalForm();@b@    try@b@    {@b@      string = URLDecoder.decode(string, "UTF-8");@b@    }@b@    catch (UnsupportedEncodingException e)@b@    {@b@    }@b@@b@    String simplePrefix = "file:/";@b@    String standardPrefix = simplePrefix + "/";@b@@b@    if (string.startsWith(standardPrefix)) {@b@      path3 = string.substring(standardPrefix.length());@b@    } else if (string.startsWith(simplePrefix)) {@b@      path3 = string.substring(simplePrefix.length() - 1);@b@    } else {@b@      String auth = url.getAuthority();@b@      String path2 = url.getPath().replace("%20", " ");@b@      if ((auth != null) && (!(auth.equals(""))))@b@        path3 = "//" + auth + path2;@b@      else@b@        path3 = path2;@b@@b@    }@b@@b@    return new File(path3);@b@  }@b@@b@  public static int getSubSamplingFactor2(int xSubsamplingFactor, int ySubsamplingFactor)@b@  {@b@    boolean resamplingIsRequired = false;@b@    int newSubSamplingFactor = 0;@b@@b@    boolean subSamplingFactorsAreDifferent = xSubsamplingFactor != ySubsamplingFactor;@b@@b@    newSubSamplingFactor = (xSubsamplingFactor <= ySubsamplingFactor) ? xSubsamplingFactor : ySubsamplingFactor;@b@@b@    boolean changedSubSamplingFactors = newSubSamplingFactor > 2147483647;@b@    if (newSubSamplingFactor > 2147483647)@b@      newSubSamplingFactor = 2147483647;@b@    int optimalSubsampling = findOptimalSubSampling(newSubSamplingFactor);@b@@b@    resamplingIsRequired = (subSamplingFactorsAreDifferent) || (changedSubSamplingFactors) || (optimalSubsampling != newSubSamplingFactor);@b@@b@    if (!(resamplingIsRequired))@b@    {@b@      newSubSamplingFactor = 0;@b@    }@b@    else@b@    {@b@      newSubSamplingFactor = optimalSubsampling;@b@    }@b@    return newSubSamplingFactor;@b@  }@b@@b@  private static int findOptimalSubSampling(int newSubSamplingFactor) {@b@    int optimalSubSamplingFactor = 1;@b@@b@    for (int level = 0; level < 31; ++level)@b@    {@b@      if (optimalSubSamplingFactor < newSubSamplingFactor) {@b@        optimalSubSamplingFactor = 1 << level;@b@      }@b@      else {@b@        if (optimalSubSamplingFactor > newSubSamplingFactor) {@b@          optimalSubSamplingFactor >>= 1;@b@          break; }@b@        if (optimalSubSamplingFactor == newSubSamplingFactor)@b@          break;@b@      }@b@    }@b@    return optimalSubSamplingFactor;@b@  }@b@@b@  public static String getShortClassName(Object object)@b@  {@b@    return getShortName((object != null) ? object.getClass() : null);@b@  }@b@@b@  public static String adjustAttributeName(String attributeName) {@b@    if (attributeName.contains("\\"))@b@      return attributeName.replace("\\", "_");@b@@b@    return attributeName;@b@  }@b@}
<<推荐下载>>
  • (1) 阿里巴巴Java开发手册8种不同版本
  • (2) Web前端开发视频教程
  • (3) 30+明星讲师PPT课件分享一线大厂架构实战经验
  • (4) java开发_架构篇_视频资源分享_v2208
  • (5) java开发_高级篇_视频资源分享_v2208
  • (6) java开发_进阶篇(中级)_视频资源分享_v2208
  • (7) java开发_入门篇_视频资源分享_v2208
  • (8) 微信小程序开发视频1+167源码+实战demo等下载
  • (9) easy-shopping电子商务java源码(附脚本和安装文档说明)下载
  • (10) java常用的72份知名实用的电子书下载
  • (11) java开发性能优化资料整理大全(8份电子文档+3份实战优化)下载
  • (12) 9个常用的算法设计资料和100以上视频课件内容下载
  • (13) vue开发必备常用手册16件下载
  • (14) 21种不同技术集群方案(es、flink、redis、nginx、zk、lvs、kafka、mysql、k8s等)参考资料下载
  • (15) 20种技术代码规范(js/java/dba/阿里/华为/oracle/mysql等)参考资料下载
  • (16) 微服务五套资料(0-1,架构设计,springcloud,nacos等)下载
  • (17) 架构师(28知识图谱+3套简历模板+6套架构实战文档等)完整资料整理下载
  • (18) 大数据18套实战基础知识+8套简历模板下载
  • (19) 并发编程全套(7套+阿里巴巴+亿级实战等)实战资料下载
  • (20) Kafka九套学习整理知识点全套(面试+笔记+代码api+命令+容备等)资料下载
  • (21) java全套9个不同方向类型的面试题(基础+核心+大厂+架构师+近万套题库等)下载
  • (22) JAVA开发常用API帮助文档大全(超52种以上技术资料,高手必备)下载
  • (23) springcloud超详细139件全套学习实战资料( 视频课件+源码demo+文档资料等)下载
  • 更多推荐>>
  • <<热门文章>>