一、前言
基于apache的derby源码包中的org.apache.derby.iapi.util.PropertyUtil属性工具类,对属性进行排序sortProperties、属性间相互复制copyProperties、文件流加载loadWithTrimmedValues等操作。
二、源码说明
package org.apache.derby.iapi.util;@b@@b@import java.io.IOException;@b@import java.io.InputStream;@b@import java.util.Arrays;@b@import java.util.Enumeration;@b@import java.util.Properties;@b@@b@public class PropertyUtil@b@{@b@ public static String sortProperties(Properties paramProperties)@b@ {@b@ return sortProperties(paramProperties, null);@b@ }@b@@b@ public static String sortProperties(Properties paramProperties, String paramString)@b@ {@b@ String str1;@b@ int i = (paramProperties == null) ? 0 : paramProperties.size();@b@ int j = 0;@b@ Object localObject = new String[i];@b@ if (paramProperties != null)@b@ {@b@ Enumeration localEnumeration = paramProperties.propertyNames();@b@ while (localEnumeration.hasMoreElements())@b@ {@b@ if (j == i)@b@ {@b@ i *= 2;@b@ String[] arrayOfString = new String[i];@b@ System.arraycopy(localObject, 0, arrayOfString, 0, j);@b@ localObject = arrayOfString;@b@ }@b@ str1 = (String)localEnumeration.nextElement();@b@ localObject[(j++)] = str1;@b@ }@b@ Arrays.sort(localObject, 0, j);@b@ }@b@ StringBuffer localStringBuffer = new StringBuffer();@b@ if (paramString == null)@b@ localStringBuffer.append("{ ");@b@ for (int k = 0; k < j; ++k)@b@ {@b@ if ((k > 0) && (paramString == null))@b@ localStringBuffer.append(", ");@b@ str1 = localObject[k];@b@ if (paramString != null)@b@ localStringBuffer.append(paramString);@b@ localStringBuffer.append(str1);@b@ localStringBuffer.append("=");@b@ String str2 = paramProperties.getProperty(str1, "MISSING_VALUE");@b@ localStringBuffer.append(str2);@b@ if (paramString != null)@b@ localStringBuffer.append("\n");@b@ }@b@ if (paramString == null)@b@ localStringBuffer.append(" }");@b@ return ((String)localStringBuffer.toString());@b@ }@b@@b@ public static void copyProperties(Properties paramProperties1, Properties paramProperties2)@b@ {@b@ Enumeration localEnumeration = paramProperties1.propertyNames();@b@ while (localEnumeration.hasMoreElements())@b@ {@b@ Object localObject = localEnumeration.nextElement();@b@ paramProperties2.put(localObject, paramProperties1.get(localObject));@b@ }@b@ }@b@@b@ public static void loadWithTrimmedValues(InputStream paramInputStream, Properties paramProperties)@b@ throws IOException@b@ {@b@ if ((paramInputStream == null) || (paramProperties == null))@b@ return;@b@ Properties localProperties = new Properties();@b@ localProperties.load(paramInputStream);@b@ Enumeration localEnumeration = localProperties.propertyNames();@b@ while (localEnumeration.hasMoreElements())@b@ {@b@ String str1 = (String)localEnumeration.nextElement();@b@ String str2 = localProperties.getProperty(str1);@b@ str2 = str2.trim();@b@ paramProperties.put(str1, str2);@b@ }@b@ }@b@}