html页面字符串转map,关于ftpserver-core源码包中StringUtils字符串工具类对数组、Map及Html格式化byte数组转换等处理...

一、前言

关于apache的ftpserver的核心源码包ftpserver-core中org.apache.ftpserver.util.StringUtils字符串工具类,对字符串常用数据类型替换replaceString、对HTML字符串格式化formatHtml、字符串对于二进制byte[]数组相互转换toHexString/toByteArray等处理。

二、代码示例package org.apache.ftpserver.util;@b@@b@import java.util.Map;@b@@b@public class StringUtils@b@{@b@  public static final String replaceString(String source, String oldStr, String newStr)@b@  {@b@    StringBuilder sb = new StringBuilder(source.length());@b@    int sind = 0;@b@    int cind = 0;@b@    while ((cind = source.indexOf(oldStr, sind)) != -1) {@b@      sb.append(source.substring(sind, cind));@b@      sb.append(newStr);@b@      sind = cind + oldStr.length();@b@    }@b@    sb.append(source.substring(sind));@b@    return sb.toString();@b@  }@b@@b@  public static final String replaceString(String source, Object[] args)@b@  {@b@    int startIndex = 0;@b@    int openIndex = source.indexOf(123, startIndex);@b@    if (openIndex == -1) {@b@      return source;@b@    }@b@@b@    int closeIndex = source.indexOf(125, startIndex);@b@    if ((closeIndex == -1) || (openIndex > closeIndex)) {@b@      return source;@b@    }@b@@b@    StringBuilder sb = new StringBuilder();@b@    sb.append(source.substring(startIndex, openIndex));@b@    while (true) {@b@      String intStr = source.substring(openIndex + 1, closeIndex);@b@      int index = Integer.parseInt(intStr);@b@      sb.append(args[index]);@b@@b@      startIndex = closeIndex + 1;@b@      openIndex = source.indexOf(123, startIndex);@b@      if (openIndex == -1) {@b@        sb.append(source.substring(startIndex));@b@        break;@b@      }@b@@b@      closeIndex = source.indexOf(125, startIndex);@b@      if ((closeIndex == -1) || (openIndex > closeIndex)) {@b@        sb.append(source.substring(startIndex));@b@        break;@b@      }@b@      sb.append(source.substring(startIndex, openIndex));@b@    }@b@    return sb.toString();@b@  }@b@@b@  public static final String replaceString(String source, Map args)@b@  {@b@    int startIndex = 0;@b@    int openIndex = source.indexOf(123, startIndex);@b@    if (openIndex == -1) {@b@      return source;@b@    }@b@@b@    int closeIndex = source.indexOf(125, startIndex);@b@    if ((closeIndex == -1) || (openIndex > closeIndex)) {@b@      return source;@b@    }@b@@b@    StringBuilder sb = new StringBuilder();@b@    sb.append(source.substring(startIndex, openIndex));@b@    while (true) {@b@      String key = source.substring(openIndex + 1, closeIndex);@b@      Object val = args.get(key);@b@      if (val != null) {@b@        sb.append(val);@b@      }@b@@b@      startIndex = closeIndex + 1;@b@      openIndex = source.indexOf(123, startIndex);@b@      if (openIndex == -1) {@b@        sb.append(source.substring(startIndex));@b@        break;@b@      }@b@@b@      closeIndex = source.indexOf(125, startIndex);@b@      if ((closeIndex == -1) || (openIndex > closeIndex)) {@b@        sb.append(source.substring(startIndex));@b@        break;@b@      }@b@      sb.append(source.substring(startIndex, openIndex));@b@    }@b@    return sb.toString();@b@  }@b@@b@  public static final String formatHtml(String source, boolean bReplaceNl, boolean bReplaceTag, boolean bReplaceQuote)@b@  {@b@    StringBuilder sb = new StringBuilder();@b@    int len = source.length();@b@    for (int i = 0; i ':@b@        if (bReplaceTag)@b@          sb.append(">");@b@        else@b@          sb.append(c);@b@        break;@b@      case '\n':@b@        if (bReplaceNl)@b@          if (bReplaceTag)@b@            sb.append("<br>");@b@          else@b@            sb.append("
");@b@        else@b@          sb.append(c);@b@@b@        break;@b@      case '\r':@b@        break;@b@      case '&':@b@        sb.append("&");@b@        break;@b@      default:@b@        sb.append(c);@b@      }@b@    }@b@@b@    return sb.toString();@b@  }@b@@b@  public static final String pad(String src, char padChar, boolean rightPad, int totalLength)@b@  {@b@    int srcLength = src.length();@b@    if (srcLength >= totalLength) {@b@      return src;@b@    }@b@@b@    int padLength = totalLength - srcLength;@b@    StringBuilder sb = new StringBuilder(padLength);@b@    for (int i = 0; i > 1;@b@    byte[] buff = new byte[arrLength];@b@    for (int i = 0; i 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值