egovframework.oe1.utl.fcc.service.EgovStringUtil.java Source code

Java tutorial

Introduction

Here is the source code for egovframework.oe1.utl.fcc.service.EgovStringUtil.java

Source

/*
 * Copyright 2010 MOPAS(Ministry of Public Administration and Security).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package egovframework.oe1.utl.fcc.service;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.security.SecureRandom;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @Class Name : EgovStringUtil.java
 * @Description : ? ??   
 * @author    
 * @since 2009. 01. 13
 * @version 1.0
 * @see <pre>
 *  == ?(Modification Information) ==
 *   
 *   ?      ?           
 *  -------    --------    ---------------------------
 *   2009.01.13                ?
 *   2009.02.13     ?           
 * 
 * </pre>
 */
public class EgovStringUtil {

    /**
     *  ? <code>""</code>.
     */
    public static final String EMPTY = "";

    /** LOG */
    protected static Log log = LogFactory.getLog(EgovStringUtil.class);

    /**
     * <p>
     * Padding?     
     * </p>
     */
    // private static final int PAD_LIMIT = 8192;
    /**
     * <p>
     * An array of <code>String</code>s used for
     * padding.
     * </p>
     * <p>
     * Used for efficient space padding. The length of
     * each String expands as needed.
     * </p>
     */
    /*
     * private static final String[] PADDING = new
     * String[Character.MAX_VALUE]; static { // space
     * padding is most common, start with 64 chars
     * PADDING[32] =
     * "                                                                "
     * ; }
     */

    /**
     * ??  ? ? ??  ??  .
     * @param source
     *        ? ? 
     * @param output
     *        ??
     * @param slength
     *        ?
     * @return ? ? ??  ?
     */
    public static String cutString(String source, String output, int slength) {
        String returnVal = null;
        if (source != null) {
            if (source.length() > slength) {
                returnVal = source.substring(0, slength) + output;
            } else
                returnVal = source;
        }
        return returnVal;
    }

    /**
     * ??  ? ?  ??  
     * @param source
     *        ? ? 
     * @param slength
     *        ?
     * @return ? ? ??  ?
     */
    public static String cutString(String source, int slength) {
        String result = null;
        if (source != null) {
            if (source.length() > slength) {
                result = source.substring(0, slength);
            } else
                result = source;
        }
        return result;
    }

    /**
     * <p>
     * String? ("") ? null ? ?.
     * </p>
     * 
     * <pre>
     *  StringUtil.isEmpty(null)      = true
     *  StringUtil.isEmpty(&quot;&quot;)        = true
     *  StringUtil.isEmpty(&quot; &quot;)       = false
     *  StringUtil.isEmpty(&quot;bob&quot;)     = false
     *  StringUtil.isEmpty(&quot;  bob  &quot;) = false
     * </pre>
     * @param str
     *        - ? ? ??? null? 
     * @return <code>true</code> - ? String ?  ?
     *         ? null? 
     */
    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }

    /**
     * <p>
     *  ?? ??  ? ?(char) .
     * </p>
     * 
     * <pre>
     * StringUtil.remove(null, *)       = null
     * StringUtil.remove(&quot;&quot;, *)         = &quot;&quot;
     * StringUtil.remove(&quot;queued&quot;, 'u') = &quot;qeed&quot;
     * StringUtil.remove(&quot;queued&quot;, 'z') = &quot;queued&quot;
     * </pre>
     * @param str
     *          ?
     * @param remove
     *         ??  ? ?
     * @return ? ?? ? ?. ?? null? 
     *         ?? null
     */
    public static String remove(String str, char remove) {
        if (isEmpty(str) || str.indexOf(remove) == -1) {
            return str;
        }
        char[] chars = str.toCharArray();
        int pos = 0;
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] != remove) {
                chars[pos++] = chars[i];
            }
        }
        return new String(chars, 0, pos);
    }

    /**
     * <p>
     * ? ?  character(,) ? .
     * </p>
     * 
     * <pre>
     * StringUtil.removeCommaChar(null)       = null
     * StringUtil.removeCommaChar(&quot;&quot;)         = &quot;&quot;
     * StringUtil.removeCommaChar(&quot;asdfg,qweqe&quot;) = &quot;asdfgqweqe&quot;
     * </pre>
     * @param str
     *          ?
     * @return " , " ? ? ?? null?  ??
     *         null
     */
    public static String removeCommaChar(String str) {
        return remove(str, ',');
    }

    /**
     * <p>
     * ? ? ? character(-) ? .
     * </p>
     * 
     * <pre>
     * StringUtil.removeMinusChar(null)       = null
     * StringUtil.removeMinusChar(&quot;&quot;)         = &quot;&quot;
     * StringUtil.removeMinusChar(&quot;a-sdfg-qweqe&quot;) = &quot;asdfgqweqe&quot;
     * </pre>
     * @param str
     *          ?
     * @return " - " ? ? ?? null?  ??
     *         null
     */
    public static String removeMinusChar(String str) {
        return remove(str, '-');
    }

    /**
     * ? ?? ??  ??  ?  
     * @param source
     *        ? ?
     * @param subject
     *        ? ?? ??  ?
     * @param object
     *         ?
     * @return sb.toString()  ? ? ?
     */
    public static String replace(String source, String subject, String object) {
        StringBuffer rtnStr = new StringBuffer();
        String preStr = "";
        String nextStr = source;
        String srcStr = source;

        while (srcStr.indexOf(subject) >= 0) {
            preStr = srcStr.substring(0, srcStr.indexOf(subject));
            nextStr = srcStr.substring(srcStr.indexOf(subject) + subject.length(), srcStr.length());
            srcStr = nextStr;
            rtnStr.append(preStr).append(object);
        }
        rtnStr.append(nextStr);
        return rtnStr.toString();
    }

    /**
     * ? ?? ??  ?    ?  
     * @param source
     *        ? ?
     * @param subject
     *        ? ?? ??  ?
     * @param object
     *         ?
     * @return sb.toString()  ? ? ? / source
     *         ??   ? ?
     */
    public static String replaceOnce(String source, String subject, String object) {
        StringBuffer rtnStr = new StringBuffer();
        String preStr = "";
        String nextStr = source;
        if (source.indexOf(subject) >= 0) {
            preStr = source.substring(0, source.indexOf(subject));
            nextStr = source.substring(source.indexOf(subject) + subject.length(), source.length());
            rtnStr.append(preStr).append(object).append(nextStr);
            return rtnStr.toString();
        } else {
            return source;
        }
    }

    /**
     * <code>subject</code>? ?? ??? ? object .
     * @param source
     *        ? ?
     * @param subject
     *        ? ?? ??  ?
     * @param object
     *         ?
     * @return sb.toString()  ? ? ?
     */
    public static String replaceChar(String source, String subject, String object) {
        StringBuffer rtnStr = new StringBuffer();
        String preStr = "";
        String nextStr = source;
        String srcStr = source;

        char chA;

        for (int i = 0; i < subject.length(); i++) {
            chA = subject.charAt(i);

            if (srcStr.indexOf(chA) >= 0) {
                preStr = srcStr.substring(0, srcStr.indexOf(chA));
                nextStr = srcStr.substring(srcStr.indexOf(chA) + 1, srcStr.length());
                srcStr = rtnStr.append(preStr).append(object).append(nextStr).toString();
            }
        }
        return srcStr;
    }

    /**
     * <p>
     * <code>str</code>  <code>searchStr</code>?
     * (index)  .
     * </p>
     * <p>
     *   <code>null</code>? ?  <code>-1</code>?
     * .
     * </p>
     * 
     * <pre>
     * StringUtil.indexOf(null, *)          = -1
     * StringUtil.indexOf(*, null)          = -1
     * StringUtil.indexOf(&quot;&quot;, &quot;&quot;)           = 0
     * StringUtil.indexOf(&quot;aabaabaa&quot;, &quot;a&quot;)  = 0
     * StringUtil.indexOf(&quot;aabaabaa&quot;, &quot;b&quot;)  = 2
     * StringUtil.indexOf(&quot;aabaabaa&quot;, &quot;ab&quot;) = 1
     * StringUtil.indexOf(&quot;aabaabaa&quot;, &quot;&quot;)   = 0
     * </pre>
     * @param str
     *         ?
     * @param searchStr
     *         ??
     * @return  ?   ???    ? ??
     *          null?  -1
     */
    public static int indexOf(String str, String searchStr) {
        if (str == null || searchStr == null) {
            return -1;
        }
        return str.indexOf(searchStr);
    }

    /**
     * <p>
     * ??? decode  ?? ?  ?.
     * <code>sourStr</code> <code>compareStr</code>?
     * ?  <code>returStr</code>? , 
     * <code>defaultStr</code>? .
     * </p>
     * 
     * <pre>
     * StringUtil.decode(null, null, &quot;foo&quot;, &quot;bar&quot;)= &quot;foo&quot;
     * StringUtil.decode(&quot;&quot;, null, &quot;foo&quot;, &quot;bar&quot;) = &quot;bar&quot;
     * StringUtil.decode(null, &quot;&quot;, &quot;foo&quot;, &quot;bar&quot;) = &quot;bar&quot;
     * StringUtil.decode(&quot;?&quot;, &quot;?&quot;, null, &quot;bar&quot;) = null
     * StringUtil.decode(&quot;?&quot;, &quot;?  &quot;, &quot;foo&quot;, null) = null
     * StringUtil.decode(&quot;?&quot;, &quot;?&quot;, &quot;foo&quot;, &quot;bar&quot;) = &quot;foo&quot;
     * StringUtil.decode(&quot;?&quot;, &quot;?  &quot;, &quot;foo&quot;, &quot;bar&quot;) = &quot;bar&quot;
     * </pre>
     * @param sourceStr
     *        ? ?
     * @param compareStr
     *        ? ? ?
     * @param returnStr
     *        sourceStr compareStr? ? ?   ?
     * @param defaultStr
     *        sourceStr compareStr? ?    ?
     * @return sourceStr compareStr? ? ??(equal) 
     *         returnStr? , <br/>
     *          defaultStr? .
     */
    public static String decode(String sourceStr, String compareStr, String returnStr, String defaultStr) {
        if (sourceStr == null && compareStr == null) {
            return returnStr;
        }

        if (sourceStr == null && compareStr != null) {
            return defaultStr;
        }

        if (sourceStr.trim().equals(compareStr)) {
            return returnStr;
        }

        return defaultStr;
    }

    /**
     * <p>
     * ??? decode  ?? ?  ?.
     * <code>sourStr</code> <code>compareStr</code>?
     * ?  <code>returStr</code>? , 
     * <code>sourceStr</code>? .
     * </p>
     * 
     * <pre>
     * StringUtil.decode(null, null, &quot;foo&quot;) = &quot;foo&quot;
     * StringUtil.decode(&quot;&quot;, null, &quot;foo&quot;) = &quot;&quot;
     * StringUtil.decode(null, &quot;&quot;, &quot;foo&quot;) = null
     * StringUtil.decode(&quot;?&quot;, &quot;?&quot;, &quot;foo&quot;) = &quot;foo&quot;
     * StringUtil.decode(&quot;?&quot;, &quot;? &quot;, &quot;foo&quot;) = &quot;?&quot;
     * StringUtil.decode(&quot;?&quot;, &quot;?&quot;, &quot;foo&quot;) = &quot;?&quot;
     * </pre>
     * @param sourceStr
     *        ? ?
     * @param compareStr
     *        ? ? ?
     * @param returnStr
     *        sourceStr compareStr? ? ?   ?
     * @return sourceStr compareStr? ? ??(equal) 
     *         returnStr? , <br/>
     *          sourceStr? .
     */
    public static String decode(String sourceStr, String compareStr, String returnStr) {
        return decode(sourceStr, compareStr, returnStr, sourceStr);
    }

    /**
     * ? null? ? null?  ""   
     * @param object
     *        ? ?
     * @return resultVal ?
     */
    public static String isNullToString(Object object) {
        String string = "";
        if (object != null) {
            string = object.toString().trim();
        }
        return string;
    }

    /**
     *<pre>
     * ?? ? String? null?  &quot;&quot; .
     * &#064;param src null? ?  String .
     * &#064;return  String? null ?  &quot;&quot;  String .
     *</pre>
     */
    public static String nullConvert(Object src) {
        // if (src != null &&
        // src.getClass().getName().equals("java.math.BigDecimal"))
        // {
        if (src != null && src instanceof java.math.BigDecimal) {
            return ((BigDecimal) src).toString();
        }

        if (src == null || src.equals("null"))
            return "";
        else
            return ((String) src).trim();
    }

    /**
     *<pre>
     * ?? ? String? null?  &quot;&quot; .
     * &#064;param src null? ?  String .
     * &#064;return  String? null ?  &quot;&quot;  String .
     *</pre>
     */
    public static String nullConvert(String src) {

        if (src == null || src.equals("null") || "".equals(src) || " ".equals(src))
            return "";
        else
            return src.trim();
    }

    /**
     *<pre>
     * ?? ? String? null?  &quot;0&quot; .
     * &#064;param src null? ?  String .
     * &#064;return  String? null ?  &quot;0&quot;  String .
     *</pre>
     */
    public static int zeroConvert(Object src) {

        if (src == null || src.equals("null"))
            return 0;
        else
            return Integer.parseInt(((String) src).trim());
    }

    /**
     *<pre>
     * ?? ? String? null?  &quot;&quot; .
     * &#064;param src null? ?  String .
     * &#064;return  String? null ?  &quot;&quot;  String .
     *</pre>
     */
    public static int zeroConvert(String src) {

        if (src == null || src.equals("null") || "".equals(src) || " ".equals(src))
            return 0;
        else
            return Integer.parseInt(src.trim());
    }

    /**
     * <p>
     * ?? {@link Character#isWhitespace(char)}? ??
     *  ? .
     * </p>
     * 
     * <pre>
     * StringUtil.removeWhitespace(null)         = null
     * StringUtil.removeWhitespace(&quot;&quot;)           = &quot;&quot;
     * StringUtil.removeWhitespace(&quot;abc&quot;)        = &quot;abc&quot;
     * StringUtil.removeWhitespace(&quot;   ab  c  &quot;) = &quot;abc&quot;
     * </pre>
     * @param str
     *        the String to delete whitespace from, may
     *        be null
     * @return the String without whitespaces,
     *         <code>null</code> if null String input
     */
    public static String removeWhitespace(String str) {
        if (isEmpty(str)) {
            return str;
        }
        int sz = str.length();
        char[] chs = new char[sz];
        int count = 0;
        for (int i = 0; i < sz; i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                chs[count++] = str.charAt(i);
            }
        }
        if (count == sz) {
            return str;
        }
        return new String(chs, 0, count);
    }

    /**
     * Html     ? ??? ?  
     * @param strString
     * @return HTML   ?
     */
    public static String checkHtmlView(String strString) {
        String strNew = "";

        try {
            StringBuffer strTxt = new StringBuffer("");

            char chrBuff;
            int len = strString.length();

            for (int i = 0; i < len; i++) {
                chrBuff = (char) strString.charAt(i);

                switch (chrBuff) {
                case '<':
                    strTxt.append("&lt;");
                    break;
                case '>':
                    strTxt.append("&gt;");
                    break;
                case '"':
                    strTxt.append("&quot;");
                    break;
                case 10:
                    strTxt.append("<br>");
                    break;
                case ' ':
                    strTxt.append("&nbsp;");
                    break;
                // case '&' :
                // strTxt.append("&amp;");
                // break;
                default:
                    strTxt.append(chrBuff);
                }
            }

            strNew = strTxt.toString();

        } catch (Exception ex) {
            return null;
        }

        return strNew;
    }

    /**
     * ??  ?? ?   .
     * @param source
     *        ? ?
     * @param separator
     *        ?
     * @return result ?  ? 
     */
    public static String[] split(String source, String separator) throws NullPointerException {
        String[] returnVal = null;
        int cnt = 1;

        int index = source.indexOf(separator);
        int index0 = 0;
        while (index >= 0) {
            cnt++;
            index = source.indexOf(separator, index + 1);
        }
        returnVal = new String[cnt];
        cnt = 0;
        index = source.indexOf(separator);
        while (index >= 0) {
            returnVal[cnt] = source.substring(index0, index);
            index0 = index + 1;
            index = source.indexOf(separator, index + 1);
            cnt++;
        }
        returnVal[cnt] = source.substring(index0);
        return returnVal;
    }

    /**
     * <p>
     * {@link String#toLowerCase()} ? ? .
     * </p>
     * <p>
     * A <code>null</code> input String returns
     * <code>null</code>.
     * </p>
     * 
     * <pre>
     * StringUtil.lowerCase(null)  = null
     * StringUtil.lowerCase(&quot;&quot;)    = &quot;&quot;
     * StringUtil.lowerCase(&quot;aBc&quot;) = &quot;abc&quot;
     * </pre>
     * @param str
     *        the String to lower case, may be null
     * @return the lower cased String,
     *         <code>null</code> if null String input
     */
    public static String lowerCase(String str) {
        if (str == null) {
            return null;
        }
        return str.toLowerCase();
    }

    /**
     * <p>
     * {@link String#toUpperCase()} ? ? .
     * </p>
     * <p>
     * A <code>null</code> input String returns
     * <code>null</code>.
     * </p>
     * 
     * <pre>
     * StringUtil.upperCase(null)  = null
     * StringUtil.upperCase(&quot;&quot;)    = &quot;&quot;
     * StringUtil.upperCase(&quot;aBc&quot;) = &quot;ABC&quot;
     * </pre>
     * @param str
     *        the String to upper case, may be null
     * @return the upper cased String,
     *         <code>null</code> if null String input
     */
    public static String upperCase(String str) {
        if (str == null) {
            return null;
        }
        return str.toUpperCase();
    }

    /**
     * <p>
     * ? String? ? ? ?? ? ?(stripChars) ?
     * .
     * </p>
     * <p>
     * A <code>null</code> input String returns
     * <code>null</code>. An empty string ("") input
     * returns the empty string.
     * </p>
     * <p>
     * If the stripChars String is <code>null</code>,
     * whitespace is stripped as defined by
     * {@link Character#isWhitespace(char)}.
     * </p>
     * 
     * <pre>
     * StringUtil.stripStart(null, *)          = null
     * StringUtil.stripStart(&quot;&quot;, *)            = &quot;&quot;
     * StringUtil.stripStart(&quot;abc&quot;, &quot;&quot;)        = &quot;abc&quot;
     * StringUtil.stripStart(&quot;abc&quot;, null)      = &quot;abc&quot;
     * StringUtil.stripStart(&quot;  abc&quot;, null)    = &quot;abc&quot;
     * StringUtil.stripStart(&quot;abc  &quot;, null)    = &quot;abc  &quot;
     * StringUtil.stripStart(&quot; abc &quot;, null)    = &quot;abc &quot;
     * StringUtil.stripStart(&quot;yxabc  &quot;, &quot;xyz&quot;) = &quot;abc  &quot;
     * </pre>
     * @param str
     *        the String to remove characters from, may
     *        be null
     * @param stripChars
     *        the characters to remove, null treated as
     *        whitespace
     * @return the stripped String, <code>null</code>
     *         if null String input
     */
    public static String stripStart(String str, String stripChars) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return str;
        }
        int start = 0;
        if (stripChars == null) {
            while ((start != strLen) && Character.isWhitespace(str.charAt(start))) {
                start++;
            }
        } else if (stripChars.length() == 0) {
            return str;
        } else {
            while ((start != strLen) && (stripChars.indexOf(str.charAt(start)) != -1)) {
                start++;
            }
        }
        return str.substring(start);
    }

    /**
     * <p>
     * ? String? ? ? ?? ? ?(stripChars) ?
     * .
     * </p>
     * <p>
     * A <code>null</code> input String returns
     * <code>null</code>. An empty string ("") input
     * returns the empty string.
     * </p>
     * <p>
     * If the stripChars String is <code>null</code>,
     * whitespace is stripped as defined by
     * {@link Character#isWhitespace(char)}.
     * </p>
     * 
     * <pre>
     * StringUtil.stripEnd(null, *)          = null
     * StringUtil.stripEnd(&quot;&quot;, *)            = &quot;&quot;
     * StringUtil.stripEnd(&quot;abc&quot;, &quot;&quot;)        = &quot;abc&quot;
     * StringUtil.stripEnd(&quot;abc&quot;, null)      = &quot;abc&quot;
     * StringUtil.stripEnd(&quot;  abc&quot;, null)    = &quot;  abc&quot;
     * StringUtil.stripEnd(&quot;abc  &quot;, null)    = &quot;abc&quot;
     * StringUtil.stripEnd(&quot; abc &quot;, null)    = &quot; abc&quot;
     * StringUtil.stripEnd(&quot;  abcyx&quot;, &quot;xyz&quot;) = &quot;  abc&quot;
     * </pre>
     * @param str
     *        the String to remove characters from, may
     *        be null
     * @param stripChars
     *        the characters to remove, null treated as
     *        whitespace
     * @return the stripped String, <code>null</code>
     *         if null String input
     */
    public static String stripEnd(String str, String stripChars) {
        int end;
        if (str == null || (end = str.length()) == 0) {
            return str;
        }

        if (stripChars == null) {
            while ((end != 0) && Character.isWhitespace(str.charAt(end - 1))) {
                end--;
            }
        } else if (stripChars.length() == 0) {
            return str;
        } else {
            while ((end != 0) && (stripChars.indexOf(str.charAt(end - 1)) != -1)) {
                end--;
            }
        }
        return str.substring(0, end);
    }

    /**
     * <p>
     * ? String? , ? ? ?? ? ?(stripChars)
     * ? .
     * </p>
     * <p>
     * This is similar to {@link String#trim()} but
     * allows the characters to be stripped to be
     * controlled.
     * </p>
     * <p>
     * A <code>null</code> input String returns
     * <code>null</code>. An empty string ("") input
     * returns the empty string.
     * </p>
     * <p>
     * If the stripChars String is <code>null</code>,
     * whitespace is stripped as defined by
     * {@link Character#isWhitespace(char)}.
     * Alternatively use {@link #strip(String)}.
     * </p>
     * 
     * <pre>
     * StringUtil.strip(null, *)          = null
     * StringUtil.strip(&quot;&quot;, *)            = &quot;&quot;
     * StringUtil.strip(&quot;abc&quot;, null)      = &quot;abc&quot;
     * StringUtil.strip(&quot;  abc&quot;, null)    = &quot;abc&quot;
     * StringUtil.strip(&quot;abc  &quot;, null)    = &quot;abc&quot;
     * StringUtil.strip(&quot; abc &quot;, null)    = &quot;abc&quot;
     * StringUtil.strip(&quot;  abcyx&quot;, &quot;xyz&quot;) = &quot;  abc&quot;
     * </pre>
     * @param str
     *        the String to remove characters from, may
     *        be null
     * @param stripChars
     *        the characters to remove, null treated as
     *        whitespace
     * @return the stripped String, <code>null</code>
     *         if null String input
     */
    public static String strip(String str, String stripChars) {

        if (isEmpty(str)) {
            return str;
        }

        String srcStr = str;

        srcStr = stripStart(srcStr, stripChars);

        return stripEnd(srcStr, stripChars);

    }

    /**
     * ??  ?? ? ? ??   .
     * @param source
     *        ? ?
     * @param separator
     *        ?
     * @param arraylength
     *         ?
     * @return ?  ? 
     */
    public static String[] split(String source, String separator, int arraylength) throws NullPointerException {
        String[] returnVal = new String[arraylength];
        int cnt = 0;
        int index0 = 0;
        int index = source.indexOf(separator);
        while (index >= 0 && cnt < (arraylength - 1)) {
            returnVal[cnt] = source.substring(index0, index);
            index0 = index + 1;
            index = source.indexOf(separator, index + 1);
            cnt++;
        }
        returnVal[cnt] = source.substring(index0);
        if (cnt < (arraylength - 1)) {
            for (int i = cnt + 1; i < arraylength; i++) {
                returnVal[i] = "";
            }
        }
        return returnVal;
    }

    /**
     * ? A? Z?? ? ??  ?  ? ? ??
     * ? ??  
     * @param startChr
     *        -  ?
     * @param endChr
     *        - ?
     * @return ??
     * @exception MyException
     * @see
     */
    public static String getRandomStr(char startChr, char endChr) {

        int randomInt;
        String randomStr = null;

        // ? ? ? ? .
        int startInt = Integer.valueOf(startChr);
        int endInt = Integer.valueOf(endChr);

        // ?? ? ?
        if (startInt > endInt) {

            throw new IllegalArgumentException("Start String: " + startChr + " End String: " + endChr);
        }

        try {

            // ? ? ?
            SecureRandom rnd = new SecureRandom();

            do {

                // ? ? ? ? ? ? ?.
                randomInt = rnd.nextInt(endInt + 1);

            } while (randomInt < startInt); // ? ?
                                            // 'A'(65)
                                            //  
                                            // ? ?
                                            // ?.

            // ? ? ?   ?  
            randomStr = (char) randomInt + "";

        } catch (Exception e) {

            log.debug(e.getMessage());

        }

        // ?? 
        return randomStr;

    }

    /**
     * ??  ?(EUC-KR[KSC5601],UTF-8..)? 
     * ?    ?? ?? ? ?  String
     * temp = new
     * String(?.getBytes(" ?")," ?");
     * String temp = new
     * String(?.getBytes("8859_1"),"KSC5601"); =>
     * UTF-8 ? EUC-KR
     * @param srcString
     *        - ?
     * @param srcCharsetNm
     *        - ? CharsetNm
     * @param charsetNm
     *        - CharsetNm
     * @return ?() ?
     * @exception MyException
     * @see
     */
    public static String getEncdDcd(String srcString, String srcCharsetNm, String cnvrCharsetNm) {

        String rtnStr = null;

        if (srcString == null)
            return null;

        try {
            rtnStr = new String(srcString.getBytes(srcCharsetNm), cnvrCharsetNm);
        } catch (UnsupportedEncodingException e) {
            rtnStr = null;
        }

        return rtnStr;

    }

    /**
         * ?  ?? ?? ?  ? ('<' -> & lT) ?
         * @param    srcString       - '<' 
         * @return    ?('<' -> "&lt"
         * @exception MyException 
         * @see  
         */
    public static String getSpclStrCnvr(String srcString) {

        String rtnStr = null;

        try {
            StringBuffer strTxt = new StringBuffer("");

            char chrBuff;
            int len = srcString.length();

            for (int i = 0; i < len; i++) {
                chrBuff = (char) srcString.charAt(i);

                switch (chrBuff) {
                case '<':
                    strTxt.append("&lt;");
                    break;
                case '>':
                    strTxt.append("&gt;");
                    break;
                case '&':
                    strTxt.append("&amp;");
                    break;
                default:
                    strTxt.append(chrBuff);
                }
            }

            rtnStr = strTxt.toString();

        } catch (Exception e) {
            log.debug(e.getMessage());
        }

        return rtnStr;

    }

    /**
     * ??? ?   ?17??TIMESTAMP?
     *  
     * @param
     * @return Timestamp 
     * @exception MyException
     * @see
     */

    public static String getTimeStamp() {

        String rtnStr = null;

        // ?    (?--? :::(?? ))
        String pattern = "yyyyMMddhhmmssSSS";

        try {

            SimpleDateFormat sdfCurrent = new SimpleDateFormat(pattern, Locale.KOREA);

            Timestamp ts = new Timestamp(System.currentTimeMillis());

            rtnStr = sdfCurrent.format(ts.getTime());

        } catch (Exception e) {

            log.debug(e.getMessage());

        }

        return rtnStr;
    }

    /**
     * ? ? ... ? 
     * @param str
     * @param maxLen
     * @return
     */
    public static String trimTitle(String str, int maxLen) {
        byte[] bytes = str.getBytes();
        int len = bytes.length;
        boolean in2Byte = false;
        int in3Byte = 0;
        String ret = str;
        int maxLen1 = maxLen;
        if (maxLen1 != 0) {
            if (len > maxLen1) {
                maxLen1 -= 3;
                for (int i = 0; i < maxLen1; i++) {
                    byte b = bytes[i];
                    if (b < 0) {
                        in2Byte = !in2Byte;
                        in3Byte++;
                    }

                    if (i == (maxLen1 - 1)) {
                        /*
                         * if (in2Byte) { ret = new
                         * String(bytes, 0, i); } else
                         * { ret = new String(bytes, 0,
                         * i+1); }
                         */
                        int mod = in3Byte % 3;
                        if (mod == 0) {
                            ret = new String(bytes, 0, i + 1);
                        } else if (mod == 1) {
                            ret = new String(bytes, 0, i + 3);
                        } else {
                            ret = new String(bytes, 0, i + 2);
                        }
                    }
                }
                ret += "...";
            }
        }
        return ret;
    }

}