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

The following are Jave code examples for showing how to use removeStart() 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: Hydrograph   File: ExternalSchemaUpdaterHandler.java   Source Code and License Vote up 6 votes
private boolean closeEditorIfAlreadyOpen(IPath jobFilePath, String fileName) {

		String jobPathRelative = StringUtils.removeStart(jobFilePath.toString(), "..");
		jobPathRelative = StringUtils.removeStart(jobPathRelative, "/");
		String jobPathAbsolute = StringUtils.replace(jobPathRelative, "/", "\\");
		IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		if (activeWorkbenchWindow != null) {
			IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
			for (IEditorReference editorRefrence : activePage.getEditorReferences()) {
				if (StringUtils.equals(editorRefrence.getTitleToolTip(), jobPathRelative)
						|| StringUtils.equals(editorRefrence.getTitleToolTip(), jobPathAbsolute)
						|| fileName.equals(editorRefrence.getTitleToolTip())) {
					IEditorPart editor = editorRefrence.getEditor(true);
					if (!activePage.closeEditor(editor, true)) {
						LOGGER.debug("Editor not closed");
					}
					LOGGER.debug("Editor closed");
					return true;
				}
			}
		}
		return false;
	}
 
Example 2
Project: monarch   File: GfshParser.java   Source Code and License Vote up 6 votes
private CommandTarget locateExactMatchingTarget(final String userInput)// exact matching
    throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
  CommandTarget commandTarget = null;

  Map<String, CommandTarget> commandTargetsMap = commandManager.getCommands();
  // Reverse sort the command names because we should start from longer names
  // E.g. Consider commands "A", "A B" & user input as "A B --opt1=val1"
  // In this case, "A B" is the most probable match & should be matched first
  // which can be achieved by reversing natural order of sorting.
  Set<String> commandNamesReverseSorted = new TreeSet<String>(Collections.reverseOrder());
  commandNamesReverseSorted.addAll(commandTargetsMap.keySet());

  // Now we need to locate the CommandTargets from the entries in the map
  for (final String commandName : commandNamesReverseSorted) {
    if (userInput.startsWith(commandName) && commandWordsMatch(userInput, commandName)) {
      // This means that the user has entered the command & name matches exactly
      commandTarget = commandTargetsMap.get(commandName);
      if (commandTarget != null) {
        String remainingBuffer = StringUtils.removeStart(userInput, commandName);
        commandTarget = commandTarget.duplicate(commandName, remainingBuffer);
        break;
      }
    }
  }
  return commandTarget;
}
 
Example 3
Project: configx   File: ProxyUtils.java   Source Code and License Vote up 5 votes
/**
 * 获取bean name的原始名称,如果是代理的bean,返回原始bean name。
 *
 * @param beanName
 * @return
 */
public static String getOriginalBeanName(String beanName) {
    if (beanName.startsWith(TARGET_NAME_PREFIX)) {
        return StringUtils.removeStart(beanName, TARGET_NAME_PREFIX);
    } else {
        return beanName;
    }
}
 
Example 4
Project: IPE-LWM2M   File: ClientServlet.java   Source Code and License Vote up 5 votes
/**
 * {@inheritDoc}
 */
@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String[] path = StringUtils.split(req.getPathInfo(), '/');
    String clientEndpoint = path[0];

    // at least /endpoint/objectId/instanceId
    if (path.length < 3) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid path");
        return;
    }

    try {
        String target = StringUtils.removeStart(req.getPathInfo(), "/" + clientEndpoint);
        Registration registration = server.getRegistrationService().getByEndpoint(clientEndpoint);
        if (registration != null) {
            // get content format
            String contentFormatParam = req.getParameter(FORMAT_PARAM);
            ContentFormat contentFormat = contentFormatParam != null
                    ? ContentFormat.fromName(contentFormatParam.toUpperCase()) : null;

            // create & process request
            LwM2mNode node = extractLwM2mNode(target, req);
            WriteRequest request = new WriteRequest(Mode.REPLACE, contentFormat, target, node);
            WriteResponse cResponse = server.send(registration, request, TIMEOUT);
            processDeviceResponse(req, resp, cResponse);
        } else {
            resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            resp.getWriter().format("No registered client with id '%s'", clientEndpoint).flush();
        }
    } catch (RuntimeException | InterruptedException e) {
        handleException(e, resp);
    }
}
 
Example 5
Project: airsonic   File: FileUtils.java   Source Code and License Vote up 5 votes
public static boolean copyJarResourcesRecursively(
        final File destDir, final JarURLConnection jarConnection
) throws IOException {

    final JarFile jarFile = jarConnection.getJarFile();

    for (final Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements(); ) {
        final JarEntry entry = e.nextElement();
        if (entry.getName().startsWith(jarConnection.getEntryName())) {
            final String filename = StringUtils.removeStart(
                    entry.getName(), //
                    jarConnection.getEntryName());

            final File f = new File(destDir, filename);
            if (!entry.isDirectory()) {
                final InputStream entryInputStream = jarFile.getInputStream(entry);
                if (!FileUtils.copyStream(entryInputStream, f)) {
                    return false;
                }
                entryInputStream.close();
            } else {
                if (!FileUtils.ensureDirectoryExists(f)) {
                    throw new IOException("Could not create directory: " + f.getAbsolutePath());
                }
            }
        }
    }
    return true;
}
 
Example 6
Project: util4j   File: HexStrBytes.java   Source Code and License Vote up 5 votes
/**
 * 根据字节数组拆分若干个字字节数组
 * @param data    待拆分数组
 * @param separator 分割数组
 * @return 
 */
public byte[][] getSonArrays(byte[] data,byte[] separator)
{
	if(data==null||data.length<=0||separator==null||separator.length<=0)
	{
		System.out.println("data||separator数据无效!");
		return null;
	}
	String[] dataHexArray=toHexArray(data);
	String dataHexStr=StringUtils.substringBetween(Arrays.toString(dataHexArray), "[", "]").replaceAll("\\s","");
	//System.out.println("待拆分字符串:"+dataHexStr);
	String[] separatorHexhArray=toHexArray(separator);
	String separatorHexStr=StringUtils.substringBetween(Arrays.toString(separatorHexhArray), "[", "]").replaceAll("\\s","");
	//System.out.println("字符串拆分符:"+separatorHexStr);
	//得到拆分后的数组
	String[] arrays=StringUtils.splitByWholeSeparator(dataHexStr, separatorHexStr);
	//System.out.println("拆分后的数组:"+Arrays.toString(arrays));
	if(arrays==null||arrays.length<=0)
	{
		System.out.println("注意:数组拆分为0");
		return null;
	}
	byte[][] result=new byte[arrays.length][];
	//对子数组进行重组
	for(int i=0;i<arrays.length;i++)
	{
		String arrayStr=arrays[i];
		arrayStr=StringUtils.removeStart(arrayStr, ",");//去掉两端的逗号
		arrayStr=StringUtils.removeEnd(arrayStr, ",");//去掉两端的逗号
		String[] array=arrayStr.split(",");//根据子字符串中间剩余的逗号重组为hex字符串
		result[i]=toBtyeArray(array);
	}
	return result;
}
 
Example 7
Project: util4j   File: DataTools.java   Source Code and License Vote up 5 votes
/**
 * 根据字节数组拆分若干个字字节数组
 * @param data
 * @param separator
 * @return
 */
public byte[][] getsonArrays(byte[] data,byte[] separator)
{
	if(data==null||data.length<=0||separator==null||separator.length<=0)
	{
		System.out.println("data||separator数据无效!");
		return null;
	}
	String[] dataHexArray=byteArrayToHexArray(data);
	String dataHexStr=StringUtils.substringBetween(Arrays.toString(dataHexArray), "[", "]").replaceAll("\\s","");
	//System.out.println("待拆分字符串:"+dataHexStr);
	String[] separatorHexhArray=byteArrayToHexArray(separator);
	String separatorHexStr=StringUtils.substringBetween(Arrays.toString(separatorHexhArray), "[", "]").replaceAll("\\s","");
	//System.out.println("字符串拆分符:"+separatorHexStr);
	//得到拆分后的数组
	String[] arrays=StringUtils.splitByWholeSeparator(dataHexStr, separatorHexStr);
	//System.out.println("拆分后的数组:"+Arrays.toString(arrays));
	if(arrays==null||arrays.length<=0)
	{
		System.out.println("注意:数组拆分为0");
		return null;
	}
	byte[][] result=new byte[arrays.length][];
	//对子数组进行重组
	for(int i=0;i<arrays.length;i++)
	{
		String arrayStr=arrays[i];
		arrayStr=StringUtils.removeStart(arrayStr, ",");//去掉两端的逗号
		arrayStr=StringUtils.removeEnd(arrayStr, ",");//去掉两端的逗号
		String[] array=arrayStr.split(",");//根据子字符串中间剩余的逗号重组为hex字符串
		result[i]=hexArrayToBtyeArray(array);
	}
	return result;
}
 
Example 8
Project: Hydrograph   File: PreStartActivity.java   Source Code and License Vote up 5 votes
private static boolean checkJDKVersion(String jdkVersion,boolean showPopupAndExit) {
	jdkVersion=StringUtils.removeStart(jdkVersion, "jdk");
	jdkVersion =StringUtils.remove(jdkVersion, ".");
	jdkVersion=StringUtils.remove(jdkVersion, "_");
	long version=Long.parseLong(jdkVersion);
	if(version>=REQUIRED_JDK_VERSION){
		return true; 
	}
	if(showPopupAndExit){
		showInvalidJavaHomeDialogAndExit();
	}
	return false;
}
 
Example 9
Project: Hydrograph   File: SubJobOpenAction.java   Source Code and License Vote up 5 votes
private boolean isJobAlreadyOpen(IPath jobFilePath) {
	
	String jobPathRelative = StringUtils.removeStart(jobFilePath.toString(), "..");
	jobPathRelative=StringUtils.removeStart(jobPathRelative, "/");
	String jobPathAbsolute = StringUtils.replace(jobPathRelative, "/", "\\");
	for (IEditorReference editorRefrence : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
			.getEditorReferences()) {
		if (StringUtils.equals(editorRefrence.getTitleToolTip(), jobPathRelative)) {
			return true;
		}else if (StringUtils.equals(editorRefrence.getTitleToolTip(), jobPathAbsolute)) {
			return true;
		}
	}
	return false;
}
 
Example 10
Project: hadoop   File: NativeAzureFileSystem.java   Source Code and License Vote up 4 votes
/**
 * Return the contents of the JSON file to represent the operations
 * to be performed for a folder rename.
 */
public String makeRenamePendingFileContents() {
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
  String time = sdf.format(new Date());

  // Make file list string
  StringBuilder builder = new StringBuilder();
  builder.append("[\n");
  for (int i = 0; i != fileMetadata.length; i++) {
    if (i > 0) {
      builder.append(",\n");
    }
    builder.append("    ");
    String noPrefix = StringUtils.removeStart(fileMetadata[i].getKey(), srcKey + "/");

    // Quote string file names, escaping any possible " characters or other
    // necessary characters in the name.
    builder.append(quote(noPrefix));
    if (builder.length() >=
        MAX_RENAME_PENDING_FILE_SIZE - FORMATTING_BUFFER) {

      // Give up now to avoid using too much memory.
      LOG.error("Internal error: Exceeded maximum rename pending file size of "
          + MAX_RENAME_PENDING_FILE_SIZE + " bytes.");

      // return some bad JSON with an error message to make it human readable
      return "exceeded maximum rename pending file size";
    }
  }
  builder.append("\n  ]");
  String fileList = builder.toString();

  // Make file contents as a string. Again, quote file names, escaping
  // characters as appropriate.
  String contents = "{\n"
      + "  FormatVersion: \"1.0\",\n"
      + "  OperationUTCTime: \"" + time + "\",\n"
      + "  OldFolderName: " + quote(srcKey) + ",\n"
      + "  NewFolderName: " + quote(dstKey) + ",\n"
      + "  FileList: " + fileList + "\n"
      + "}\n";

  return contents;
}