Java Code Examples for org.apache.commons.lang.StringUtils.substringAfter()

The following are Jave code examples for showing how to use substringAfter() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: util4j   File: DataTools.java   Source Code and License Vote up 7 votes
public byte[] subByteArrays(byte[] data,byte[] startArray)
	{
		if(data==null||data.length<=0)
		{
			System.out.println("data参数错误!");
			return null;
		}
		String[] dataHex=byteArrayToHexArray(data);//转换为hex字符数组
		String dataHexStr=Arrays.toString(dataHex);//转换为hex字符串
		dataHexStr=StringUtils.substringBetween(dataHexStr, "[", "]").replaceAll("\\s", "");//去括号空格
		
		String[] startHex=byteArrayToHexArray(startArray);//转换为hex字符数组
		String startHexStr=Arrays.toString(startHex);//转换为hex字符串
		startHexStr=StringUtils.substringBetween(startHexStr, "[", "]").replaceAll("\\s", "");//去括号空格
		String resultHex=StringUtils.substringAfter(dataHexStr, startHexStr);//截取并转换为hex字符串
		if(resultHex==null)
		{
			//System.out.println("注意:截取内容为空,无数据!");
			return null;
		}
		String[] result=StringUtils.split(resultHex, ',');//重组为hexstr数组
//		System.out.println(Arrays.toString(result));
		return hexArrayToBtyeArray(result);
	}
 
Example 2
Project: DBus   File: Support.java   Source Code and License Vote up 6 votes
public static int[] getColumnLengthAndPrecision(Column column){
	int[] ret = new int[2];
	String data = StringUtils.substringBetween(column.getMysqlType(), "(",")");
	String length = StringUtils.substringBefore(data, ",");
	String precision = StringUtils.substringAfter(data, ",");
	String type = getColumnType(column).toUpperCase();
	if("SET".equals(type) || "ENUM".equals(type)){
		ret[0] = 0;
		ret[1] = 0;
	}else{
		if(StringUtils.isEmpty(length)){
			ret[0] = 0;
		}else{
			ret[0] = Integer.parseInt(length);
		}
		if(StringUtils.isEmpty(precision)){
			ret[1] = 0;
		}else{
			ret[1] = Integer.parseInt(precision);
		}
	}
	return ret;
}
 
Example 3
Project: IPE-LWM2M   File: SecurityServlet.java   Source Code and License Vote up 6 votes
/**
 * {@inheritDoc}
 */
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String endpoint = StringUtils.substringAfter(req.getPathInfo(), "/clients/");
    if (StringUtils.isEmpty(endpoint)) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }

    LOG.debug("Removing security info for end-point {}", endpoint);
    if (this.store.remove(endpoint) != null) {
        resp.sendError(HttpServletResponse.SC_OK);
    } else {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}
 
Example 4
Project: util4j   File: HexStrBytes.java   Source Code and License Vote up 6 votes
/**
	 * 截取目标字节数组中startArray后面的字节数组
	 * @param byteArray
	 * @param startArray
	 * @return
	 */
	public byte[] subByteArray(byte[] byteArray,byte[] startArray)
	{
		if(byteArray==null||byteArray.length<=0)
		{
			System.out.println("data参数错误!");
			return null;
		}
		String[] dataHex=toHexArray(byteArray);//转换为hex字符数组
		String dataHexStr=Arrays.toString(dataHex);//转换为hex字符串
		dataHexStr=StringUtils.substringBetween(dataHexStr, "[", "]").replaceAll("\\s", "");//去括号空格
		
		String[] startHex=toHexArray(startArray);//转换为hex字符数组
		String startHexStr=Arrays.toString(startHex);//转换为hex字符串
		startHexStr=StringUtils.substringBetween(startHexStr, "[", "]").replaceAll("\\s", "");//去括号空格
		
		String resultHex=StringUtils.substringAfter(dataHexStr, startHexStr);//截取并转换为hex字符串
		if(resultHex==null)
		{
			//System.out.println("注意:截取内容为空,无数据!");
			return null;
		}
		String[] result=StringUtils.split(resultHex, ',');//重组为hexstr数组
//		System.out.println(Arrays.toString(result));
		return toBtyeArray(result);
	}
 
Example 5
Project: util4j   File: DataTools.java   Source Code and License Vote up 6 votes
/**
 * 截取以什么开头的数据
 * @param data
 * @param startHexStr
 * @return
 * @throws UnsupportedEncodingException
 */
public String[] SubHexArraysByStr(byte[] data,String startStr) throws UnsupportedEncodingException
{
	if(data==null||data.length<=0)
	{
		System.out.println("data数据无效!");
		return null;
	}
	String[] result=null;
	//转换原数据
	String[] hexarray=byteArrayToHexArray(data);
	String hexstr=Arrays.toString(hexarray);
	hexstr=StringUtils.substringBetween(hexstr, "[", "]").replaceAll("\\s", "");//原数据字符串去括号空格
	////转换匹配参数数据
	byte[] startArray=startStr.getBytes("utf-8");//转换为字节
	String[] startHex=byteArrayToHexArray(startArray);//转换为hex字符数组
	String startHexStr=Arrays.toString(startHex);//转换为hex字符串
	startHexStr=StringUtils.substringBetween(startHexStr, "[", "]").replaceAll("\\s", "");//去括号空格
	String resultHex=StringUtils.substringAfter(hexstr, startHexStr);
	if(resultHex==null)
	{
		//System.out.println("注意:截取内容为空,无数据!");
		return null;
	}
	result=StringUtils.split(resultHex, ',');//重组为hexstr数组
	return result;
}
 
Example 6
Project: Hydrograph   File: TrackingDisplayUtils.java   Source Code and License Vote up 6 votes
/**
 * This function will be return process ID which running on defined port.
 * 
 * @return the service port pid
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public String getServicePortPID(Properties properties) throws IOException {
	int portNumber = Integer.parseInt(properties.getProperty(EXECUTION_TRACKING_PORT));
	if (OSValidator.isWindows()) {
		ProcessBuilder builder = new ProcessBuilder(new String[] { "cmd",
				"/c", "netstat -a -o -n |findstr :" + portNumber });
		Process process = builder.start();
		InputStream inputStream = process.getInputStream();
		BufferedReader bufferedReader = new BufferedReader(
				new InputStreamReader(inputStream));
		String str = bufferedReader.readLine();
		str = StringUtils.substringAfter(str, "LISTENING");
		str = StringUtils.trim(str);
		return str;
	}
	return "";
}
 
Example 7
Project: Hydrograph   File: ExportXSDWidget.java   Source Code and License Vote up 6 votes
private String getRootElementName(String rowTag) {

		String rootElementName = null;

		if (StringUtils.isBlank(rowTag) || !rowTag.startsWith("/")) {
			return null;
		}

		// TODO: Ask for requirement how row tag will be come
		if (rowTag.startsWith("/")) {
			rootElementName = StringUtils.substringBetween(rowTag, "/", "/");
		}
		if (StringUtils.isBlank(rootElementName)) {
			rootElementName = StringUtils.substringAfter(rowTag, "/");
		}

		return rootElementName;
	}
 
Example 8
Project: TakeoutService   File: CommonUtil.java   Source Code and License Vote up 5 votes
/**
 * 直接输出内容的简便函数.

 * eg.
 * render("text/plain", "hello", "encoding:GBK");
 * render("text/plain", "hello", "no-cache:false");
 * render("text/plain", "hello", "encoding:GBK", "no-cache:false");
 * 
 * @param headers 可变的header数组,目前接受的值为"encoding:"或"no-cache:",默认值分别为UTF-8和true.
 */
public static void render(final HttpServletResponse response,final String contentType, final String content, final String... headers) {
	try {
		//分析headers参数
		String encoding = ENCODING_DEFAULT;
		boolean noCache = NOCACHE_DEFAULT;
		for (String header : headers) {
			String headerName = StringUtils.substringBefore(header, ":");
			String headerValue = StringUtils.substringAfter(header, ":");

			if (StringUtils.equalsIgnoreCase(headerName, ENCODING_PREFIX)) {
				encoding = headerValue;
			} else if (StringUtils.equalsIgnoreCase(headerName, NOCACHE_PREFIX)) {
				noCache = Boolean.parseBoolean(headerValue);
			} else
				throw new IllegalArgumentException(headerName + "不是一个合法的header类型");
		}

		//设置headers参数
		String fullContentType = contentType + ";charset=" + encoding;
		response.setContentType(fullContentType);
		if (noCache) {
			response.setHeader("Pragma", "No-cache");
			response.setHeader("Cache-Control", "no-cache");
			response.setDateHeader("Expires", 0);
		}

		PrintWriter writer = response.getWriter();
		writer.write(content);
		writer.flush();
		writer.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 9
Project: buenojo   File: StaticResourcesProductionFilter.java   Source Code and License Vote up 5 votes
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String contextPath = ((HttpServletRequest) request).getContextPath();
    String requestURI = httpRequest.getRequestURI();
    requestURI = StringUtils.substringAfter(requestURI, contextPath);
    if (StringUtils.equals("/", requestURI)) {
        requestURI = "/index.html";
    }
    String newURI = "/dist" + requestURI;
    request.getRequestDispatcher(newURI).forward(request, response);
}
 
Example 10
Project: DBus   File: TableMatchContainer.java   Source Code and License Vote up 5 votes
public void addTableRegex(String tableRegex){
	String[] tableRegexs = StringUtils.split(tableRegex, ",");
	for(String regex : tableRegexs){
		String localTbl = StringUtils.substringBefore(regex.trim(), ".");
		String partitionTblRegex = StringUtils.substringAfter(regex.trim(), ".");
		map.put(localTbl, partitionTblRegex);
	}
	
}
 
Example 11
Project: sling-org-apache-sling-query   File: ResourceMock.java   Source Code and License Vote up 5 votes
@Override
public Resource getChild(String relPath) {
	if (StringUtils.contains(relPath, '/')) {
		String firstPart = StringUtils.substringBefore(relPath, "/");
		String rest = StringUtils.substringAfter(relPath, "/");
		if (children.containsKey(firstPart)) {
			return children.get(firstPart).getChild(rest);
		}
	} else if (children.containsKey(relPath)) {
		return children.get(relPath);
	}

	return null;
}
 
Example 12
Project: Hydrograph   File: ApplicationWorkbenchWindowAdvisor.java   Source Code and License Vote up 5 votes
/**
 * This function will be return process ID which running on defined port
 *
 */
public String getServicePortPID(String portNumber) throws IOException{
	if(OSValidator.isWindows()){
		ProcessBuilder builder = new ProcessBuilder(new String[]{"cmd", "/c" ,"netstat -a -o -n |findstr :"+portNumber});
		Process process =builder.start();
		InputStream inputStream = process.getInputStream();
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
		String str = bufferedReader.readLine();
		str=StringUtils.substringAfter(str, "LISTENING");
		str=StringUtils.trim(str);
		return str;
	}
	return "";
}
 
Example 13
Project: canal-elasticsearch   File: TotoroLauncher.java   Source Code and License Vote up 5 votes
private static Properties getProperties(String conf) throws IOException {
    Properties properties = new Properties();

    if (conf.startsWith(CLASSPATH_URL_PREFIX)) {
        conf = StringUtils.substringAfter(conf, CLASSPATH_URL_PREFIX);
        properties.load(TotoroLauncher.class.getClassLoader().getResourceAsStream(conf));
    } else {
        properties.load(new FileInputStream(conf));
    }
    return properties;
}
 
Example 14
Project: util4j   File: HexStrBytes.java   Source Code and License Vote up 5 votes
/**
 * 截取以文本开头的字节数据并以hexStringArray数组返回
 * @param data 目标字节数组
 * @param startHexStr  普通文本,默认以utf8形式
 * @return
 * @throws UnsupportedEncodingException
 */
public String[] subHexArray(byte[] data,String startStr) throws UnsupportedEncodingException
{
	if(data==null||data.length<=0)
	{
		System.out.println("data数据无效!");
		return null;
	}
	String[] result=null;
	//转换原数据
	String[] hexarray=toHexArray(data);
	String hexstr=Arrays.toString(hexarray);
	hexstr=StringUtils.substringBetween(hexstr, "[", "]").replaceAll("\\s", "");//原数据字符串去括号空格
	////转换匹配参数数据
	byte[] startArray=startStr.getBytes("utf-8");//转换为字节
	String[] startHex=toHexArray(startArray);//转换为hex字符数组
	String startHexStr=Arrays.toString(startHex);//转换为hex字符串
	startHexStr=StringUtils.substringBetween(startHexStr, "[", "]").replaceAll("\\s", "");//去括号空格
	String resultHex=StringUtils.substringAfter(hexstr, startHexStr);
	if(resultHex==null)
	{
		//System.out.println("注意:截取内容为空,无数据!");
		return null;
	}
	result=StringUtils.split(resultHex, ',');//重组为hexstr数组
	return result;
}
 
Example 15
Project: Ins_fb_pictureSpider_WEB   File: BaseUtils.java   Source Code and License Vote up 5 votes
/**
 * 分析并设置contentType与headers.
 */
private static HttpServletResponse initResponseHeader(final String contentType, final String... headers) {
    //分析headers参数
    String encoding = DEFAULT_ENCODING;
    boolean noCache = DEFAULT_NOCACHE;
    for (String header : headers) {
        String headerName = StringUtils.substringBefore(header, ":");
        String headerValue = StringUtils.substringAfter(header, ":");

        if (StringUtils.equalsIgnoreCase(headerName, HEADER_ENCODING)) {
            encoding = headerValue;
        } else if (StringUtils.equalsIgnoreCase(headerName, HEADER_NOCACHE)) {
            noCache = Boolean.parseBoolean(headerValue);
        } else {
            throw new IllegalArgumentException(headerName + "不是一个合法的header类型");
        }
    }

    HttpServletResponse response = ServletActionContext.getResponse();

    //设置headers参数
    String fullContentType = contentType + ";charset=" + encoding;
    response.setContentType(fullContentType);
    if (noCache) {
        ServletUtils.setDisableCacheHeader(response);
    }

    return response;
}
 
Example 16
Project: ymate-payment-v2   File: WxPayAccountMeta.java   Source Code and License Vote up 5 votes
public void setSandboxPrefix(String sandboxPrefix) {
    sandboxPrefix = StringUtils.defaultIfBlank(sandboxPrefix, "sandboxnew");
    if (StringUtils.startsWith(sandboxPrefix, "/")) {
        sandboxPrefix = StringUtils.substringAfter(sandboxPrefix, "/");
    }
    if (!StringUtils.endsWith(this.sandboxPrefix, "/")) {
        sandboxPrefix = sandboxPrefix + "/";
    }
    this.sandboxPrefix = sandboxPrefix;
}
 
Example 17
Project: DBus   File: Support.java   Source Code and License Vote up 4 votes
public static void main(String[] args){
	String str="int";
	String length = StringUtils.substringBetween(str, "(",")");
	String precision = StringUtils.substringBefore(length, ",");
	String scale = StringUtils.substringAfter(length, ",");
}
 
Example 18
Project: hadoop   File: PrivilegedOperationExecutor.java   Source Code and License Vote up 4 votes
/**
 * Squash operations for cgroups - e.g mount, add pid to cgroup etc .,
 * For now, we only implement squashing for 'add pid to cgroup' since this
 * is the only optimization relevant to launching containers
 *
 * @return single squashed cgroup operation. Null on failure.
 */

public static PrivilegedOperation squashCGroupOperations
(List<PrivilegedOperation> ops) throws PrivilegedOperationException {
  if (ops.size() == 0) {
    return null;
  }

  StringBuffer finalOpArg = new StringBuffer(PrivilegedOperation
      .CGROUP_ARG_PREFIX);
  boolean noTasks = true;

  for (PrivilegedOperation op : ops) {
    if (!op.getOperationType()
        .equals(PrivilegedOperation.OperationType.ADD_PID_TO_CGROUP)) {
      LOG.warn("Unsupported operation type: " + op.getOperationType());
      throw new PrivilegedOperationException("Unsupported operation type:"
          + op.getOperationType());
    }

    List<String> args = op.getArguments();
    if (args.size() != 1) {
      LOG.warn("Invalid number of args: " + args.size());
      throw new PrivilegedOperationException("Invalid number of args: "
          + args.size());
    }

    String arg = args.get(0);
    String tasksFile = StringUtils.substringAfter(arg,
        PrivilegedOperation.CGROUP_ARG_PREFIX);
    if (tasksFile == null || tasksFile.isEmpty()) {
      LOG.warn("Invalid argument: " + arg);
      throw new PrivilegedOperationException("Invalid argument: " + arg);
    }

    if (tasksFile.equals(PrivilegedOperation.CGROUP_ARG_NO_TASKS)) {
      //Don't append to finalOpArg
      continue;
    }

    if (noTasks == false) {
      //We have already appended at least one tasks file.
      finalOpArg.append(PrivilegedOperation.LINUX_FILE_PATH_SEPARATOR);
      finalOpArg.append(tasksFile);
    } else {
      finalOpArg.append(tasksFile);
      noTasks = false;
    }
  }

  if (noTasks) {
    finalOpArg.append(PrivilegedOperation.CGROUP_ARG_NO_TASKS); //there
    // were no tasks file to append
  }

  PrivilegedOperation finalOp = new PrivilegedOperation(
      PrivilegedOperation.OperationType.ADD_PID_TO_CGROUP, finalOpArg
      .toString());

  return finalOp;
}
 
Example 19
Project: Yidu   File: GenerateHtmlFileInterceptor.java   Source Code and License Vote up 4 votes
public static String getVarNameFromMethodName(String methodName) {
    String varName = StringUtils.substringAfter(methodName, "get");
    String firstChar = StringUtils.substring(varName, 0, 1);
    varName = varName.replaceFirst(firstChar, firstChar.toLowerCase());
    return varName;
}
 
Example 20
Project: lams   File: WebUtil.java   Source Code and License Vote up 3 votes
/**
    * <p>
    * This helper method create the struts action forward name using the path. It will chop all path related
    * characters, such as "/" and ".do".
    * </p>
    *
    * <p>
    * For example:
    * <li><code>getStrutsForwardNameFromPath("/DisplayParallelActivity.do")<code>
    * = displayParallelActivity</li>
    * </p>
    *
    * @param path
    * @return
    */
   public static String getStrutsForwardNameFromPath(String path) {
String pathWithoutSlash = StringUtils.substringAfter(path, "/");
String orginalForwardName = StringUtils.substringBeforeLast(pathWithoutSlash, ".do");

return StringUtils.uncapitalize(orginalForwardName);

   }