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

The following examples show how to use org.apache.commons.lang3.StringUtils#removeStart() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClasspathResourceServlet.java    From chassis with Apache License 2.0 6 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	// figure out the real path
	String pathInfo = StringUtils.trimToEmpty(req.getPathInfo());
	
	while (pathInfo.endsWith("/")) {
		pathInfo = StringUtils.removeEnd(pathInfo, "/");
	}
	
	while (pathInfo.startsWith("/")) {
		pathInfo = StringUtils.removeStart(pathInfo, "/");
	}

	if (StringUtils.isBlank(pathInfo)) {
		resp.sendRedirect(rootContextPath + "/" + welcomePage);
	} else {
		Resource resource = resourceLoader.getResource("classpath:" + classPathDirectory + req.getPathInfo());
		
		if (resource.exists()) {
			StreamUtils.copy(resource.getInputStream(), resp.getOutputStream());
			resp.setStatus(HttpServletResponse.SC_OK);
		} else {
			resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
		}
	}
}
 
Example 2
Source File: RepositoryFactoryBase.java    From symbol-sdk-java with Apache License 2.0 5 votes vote down vote up
protected ObservableSource<NetworkCurrency> getNetworkCurrency(String mosaicIdHex) {
    MosaicId mosaicId = new MosaicId(
        StringUtils.removeStart(mosaicIdHex.replace("'", "").substring(2), "0x"));
    return createMosaicRepository().getMosaic(mosaicId)
        .map(mosaicInfo -> new NetworkCurrencyBuilder(mosaicInfo.getMosaicId(),
            mosaicInfo.getDivisibility()).withTransferable(mosaicInfo.isTransferable())
            .withSupplyMutable(mosaicInfo.isSupplyMutable()))
        .flatMap(builder -> createNamespaceRepository()
            .getMosaicsNames(Collections.singletonList(mosaicId)).map(
                names -> names.stream().filter(n -> n.getMosaicId().equals(mosaicId))
                    .findFirst()
                    .map(name -> builder.withNamespaceId(getNamespaceId(names)).build())
                    .orElse(builder.build())));
}
 
Example 3
Source File: PartitionTree.java    From sqlg with MIT License 5 votes vote down vote up
private String fromExpression() {
    if (this.fromToIn != null && this.parentPartitionTree.partitionType.isRange()) {
        String tmp = this.fromToIn.substring("FOR VALUES FROM (".length());
        String fromTo[] = tmp.split(" TO ");
        String from = fromTo[0].trim();
        from = StringUtils.removeStart(from, "(");
        from = StringUtils.removeEnd(from, ")");
        return from;
    } else {
        return null;
    }
}
 
Example 4
Source File: S3S3Copier.java    From circus-train with Apache License 2.0 5 votes vote down vote up
private void initialiseCopyJobsFromListing(
    AmazonS3URI sourceS3Uri,
    final AmazonS3URI targetS3Uri,
    ListObjectsRequest request,
    ObjectListing listing) {
  LOG
      .debug("Found objects to copy {}, for request {}/{}", listing.getObjectSummaries(), request.getBucketName(),
          request.getPrefix());
  List<S3ObjectSummary> objectSummaries = listing.getObjectSummaries();
  for (final S3ObjectSummary s3ObjectSummary : objectSummaries) {
    totalBytesToReplicate += s3ObjectSummary.getSize();
    String fileName = StringUtils.removeStart(s3ObjectSummary.getKey(), sourceS3Uri.getKey());
    final String targetKey = Strings.nullToEmpty(targetS3Uri.getKey()) + fileName;
    CopyObjectRequest copyObjectRequest = new CopyObjectRequest(s3ObjectSummary.getBucketName(),
        s3ObjectSummary.getKey(), targetS3Uri.getBucket(), targetKey);

    if (s3s3CopierOptions.getCannedAcl() != null) {
      copyObjectRequest.withCannedAccessControlList(s3s3CopierOptions.getCannedAcl());
    }

    applyObjectMetadata(copyObjectRequest);

    TransferStateChangeListener stateChangeListener = new BytesTransferStateChangeListener(s3ObjectSummary,
        targetS3Uri, targetKey);
    copyJobRequests.add(new CopyJobRequest(copyObjectRequest, stateChangeListener));
  }
}
 
Example 5
Source File: QueryDescriptor.java    From bird-java with MIT License 5 votes vote down vote up
public static String getDbFieldName(Field field) {
    TableField tableField = field.getAnnotation(TableField.class);
    String dbFieldName = tableField == null ? field.getName() : tableField.value();

    if (StringUtils.startsWith(dbFieldName, "{") && StringUtils.endsWith(dbFieldName, "}")) {
        dbFieldName = StringUtils.removeStart(dbFieldName, "{");
        dbFieldName = StringUtils.removeEnd(dbFieldName, "}");
    } else {
        dbFieldName = StringUtils.wrapIfMissing(dbFieldName, '`');
    }
    return dbFieldName;
}
 
Example 6
Source File: RemoteRepository.java    From archiva with Apache License 2.0 5 votes vote down vote up
public void setCheckPath(String checkPath) {
    if (checkPath==null) {
        this.checkPath="";
    } else if (checkPath.startsWith("/")) {
        this.checkPath = StringUtils.removeStart(checkPath, "/");
        while(this.checkPath.startsWith("/")) {
            this.checkPath = StringUtils.removeStart(checkPath, "/");
        }
    } else {
        this.checkPath = checkPath;
    }
}
 
Example 7
Source File: XValue.java    From JsoupXpath with Apache License 2.0 5 votes vote down vote up
public XValue exprStr(){
    this.isExprStr = true;
    String str = StringUtils.removeStart(String.valueOf(this.value),"'");
    str = StringUtils.removeStart(str,"\"");
    str = StringUtils.removeEnd(str,"'");
    this.value = StringUtils.removeEnd(str,"\"");
    return this;
}
 
Example 8
Source File: ConfigService.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Tuple<String, String> createHostProperty(Entry<String, String> propertyEntry) {
	String hostFunction = StringUtils.removeStart(propertyEntry.getKey(), "hostname-");
	String hostName = propertyEntry.getValue();
	String propertyName = String.format("host.%s.%s.ping", hostFunction, hostName);
	String reachable = "ERROR";
	try {
		InetAddress address = InetAddress.getByName(hostName);
		reachable = address.isReachable(1000) ? "OK" : "ERROR";
	} catch (IOException e) {
		logger.error("Cannot reach to host " + hostName, e);
	}
	return new Tuple<>(propertyName, reachable);
}
 
Example 9
Source File: FrontUtils.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
/**
 * remove fist string.
 */
public static String removeFirstStr(String constant, String target) {
    if (StringUtils.isBlank(constant) || StringUtils.isBlank(target)) {
        return constant;
    }
    if (constant.startsWith(target)) {
        constant = StringUtils.removeStart(constant, target);
    }
    return constant;
}
 
Example 10
Source File: TestHdfsSnapshotHRegion.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  Configuration c = TEST_UTIL.getConfiguration();
  c.setBoolean("dfs.support.append", true);
  TEST_UTIL.startMiniCluster(1);
  table = TEST_UTIL.createMultiRegionTable(TABLE_NAME, FAMILY);
  TEST_UTIL.loadTable(table, FAMILY);

  // setup the hdfssnapshots
  client = new DFSClient(TEST_UTIL.getDFSCluster().getURI(), TEST_UTIL.getConfiguration());
  String fullUrIPath = TEST_UTIL.getDefaultRootDirPath().toString();
  String uriString = TEST_UTIL.getTestFileSystem().getUri().toString();
  baseDir = StringUtils.removeStart(fullUrIPath, uriString);
  client.allowSnapshot(baseDir);
}
 
Example 11
Source File: ScooldUtils.java    From scoold with Apache License 2.0 5 votes vote down vote up
private ParaObject checkApiAuth(HttpServletRequest req) {
	if (req.getRequestURI().equals(CONTEXT_PATH + "/api")) {
		return null;
	}
	String apiKeyJWT = StringUtils.removeStart(req.getHeader(HttpHeaders.AUTHORIZATION), "Bearer ");
	if (req.getRequestURI().equals(CONTEXT_PATH + "/api/stats") && isValidJWToken(apiKeyJWT)) {
		return API_USER;
	} else if (!isApiEnabled() || StringUtils.isBlank(apiKeyJWT) || !isValidJWToken(apiKeyJWT)) {
		throw new WebApplicationException(401);
	}
	return API_USER;
}
 
Example 12
Source File: CamelSinkTask.java    From camel-kafka-connector with Apache License 2.0 5 votes vote down vote up
private void addHeader(Map<String, Object> map, Header singleHeader) {
    String camelHeaderKey = StringUtils.removeStart(singleHeader.key(), HEADER_CAMEL_PREFIX);
    Schema schema = singleHeader.schema();
    if (schema.type().getName().equals(Schema.STRING_SCHEMA.type().getName())) {
        map.put(camelHeaderKey, (String)singleHeader.value());
    } else if (schema.type().getName().equalsIgnoreCase(Schema.BOOLEAN_SCHEMA.type().getName())) {
        map.put(camelHeaderKey, (Boolean)singleHeader.value());
    } else if (schema.type().getName().equalsIgnoreCase(Schema.INT32_SCHEMA.type().getName())) {
        map.put(camelHeaderKey, singleHeader.value());
    } else if (schema.type().getName().equalsIgnoreCase(Schema.BYTES_SCHEMA.type().getName())) {
        map.put(camelHeaderKey, (byte[])singleHeader.value());
    } else if (schema.type().getName().equalsIgnoreCase(Schema.FLOAT32_SCHEMA.type().getName())) {
        map.put(camelHeaderKey, (float)singleHeader.value());
    } else if (schema.type().getName().equalsIgnoreCase(Schema.FLOAT64_SCHEMA.type().getName())) {
        map.put(camelHeaderKey, (double)singleHeader.value());
    } else if (schema.type().getName().equalsIgnoreCase(Schema.INT16_SCHEMA.type().getName())) {
        map.put(camelHeaderKey, (short)singleHeader.value());
    } else if (schema.type().getName().equalsIgnoreCase(Schema.INT64_SCHEMA.type().getName())) {
        map.put(camelHeaderKey, (long)singleHeader.value());
    } else if (schema.type().getName().equalsIgnoreCase(Schema.INT8_SCHEMA.type().getName())) {
        map.put(camelHeaderKey, (byte)singleHeader.value());
    } else if (schema.type().getName().equalsIgnoreCase(SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.STRING_SCHEMA).type().getName())) {
        map.put(camelHeaderKey, (Map<?, ?>)singleHeader.value());
    } else if (schema.type().getName().equalsIgnoreCase(SchemaBuilder.array(Schema.STRING_SCHEMA).type().getName())) {
        map.put(camelHeaderKey, (List<?>)singleHeader.value());
    }
}
 
Example 13
Source File: PANTHERTree.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create an instance for the given path
 *
 * @param pFile path
 * @throws IOException
 */
public PANTHERTree (File pFile) throws IOException {

	if( pFile == null ){ throw new Error("No file was specified..."); }

	//
	String fileAsStr = FileUtils.readFileToString(pFile);
	String[] lines = StringUtils.split(fileAsStr, "\n");

	// The first line is the tree in Newick-ish form, the rest is the annotation info
	// that needs to be parsed later on.
	if( lines.length < 3 ){
		throw new Error("Does not look like a usable PANTHER tree file: " + pFile.getName());
	}else{

		// The human tree name.
		//treeLabel = StringUtils.lowerCase(StringUtils.removeStart(lines[0], "NAME="));
		treeLabel = StringUtils.removeStart(lines[0], "NAME=");

		// The raw tree.
		treeStr = lines[1];

		// The raw annotations associated with the tree.
		treeAnns = Arrays.copyOfRange(lines, 2, lines.length);

		if( treeAnns == null || treeStr == null || treeLabel == null || treeStr.equals("") || treeLabel.equals("") || treeAnns.length < 1 ){
			throw new Error("It looks like a bad PANTHER tree file.");
		}else{
			String filename = pFile.getName();
			treeID = StringUtils.substringBefore(filename, ".");
		}
	}

	//LOG.info("Processing: " + getTreeName() + " with " + lines.length + " lines.");
	annotationSet = new HashSet<String>();
	generateGraph(); // this must come before annotation processing
	readyAnnotationDataCache();
	matchAnnotationsIntoGraph();
}
 
Example 14
Source File: TerminalHelpFormatter.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
protected StringBuffer renderWrappedText(final StringBuffer sb, final int width, int nextLineTabStop, String text) {
    int pos = findWrapPos(text, width, 0);
    if(pos == -1) {
        sb.append(rtrim(text));

        return sb;
    }
    sb.append(rtrim(text.substring(0, pos))).append(getNewLine());
    if(nextLineTabStop >= width) {
        // stops infinite loop happening
        nextLineTabStop = 1;
    }
    // all following lines must be padded with nextLineTabStop space characters
    final String padding = createPadding(nextLineTabStop);
    while(true) {
        text = padding + StringUtils.removeStart(text.substring(pos), StringUtils.SPACE);
        pos = findWrapPos(text, width, 0);
        if(pos == -1) {
            sb.append(text);
            return sb;
        }
        if((text.length() > width) && (pos == nextLineTabStop - 1)) {
            pos = width;
        }
        sb.append(rtrim(text.substring(0, pos))).append(getNewLine());
    }
}
 
Example 15
Source File: NameBean.java    From jackdaw with Apache License 2.0 4 votes vote down vote up
@Override
public final String apply(final String input) {
    final String name = StringUtils.removeStart(StringUtils.removeEnd(input, MODEL), ABSTRACT);
    return StringUtils.equals(name, input) ? input + BEAN : name;
}
 
Example 16
Source File: YarnLockParser.java    From synopsys-detect with Apache License 2.0 4 votes vote down vote up
private String removeWrappingQuotes(String s) {
    return StringUtils.removeStart(StringUtils.removeEnd(s.trim(), "\""), "\"");
}
 
Example 17
Source File: EmitMetricsAnalyzer.java    From DCMonitor with MIT License 4 votes vote down vote up
MetricFetcher(String name) {
  this.name = StringUtils.removeStart(StringUtils.removeEnd(name, "/"), "/");
  this.accpetMetrics = Collections.singletonList(name);
}
 
Example 18
Source File: P2BrowseNodeGenerator.java    From nexus-repository-p2 with Eclipse Public License 1.0 4 votes vote down vote up
private String getRelativePath(final String fullUrl, final String remote) {
  return StringUtils.removeStart(fullUrl, remote);
}
 
Example 19
Source File: Helper.java    From cloudsync with GNU General Public License v2.0 4 votes vote down vote up
public static String trim(String text, final String character)
{
	text = StringUtils.removeStart(text, character);
	text = StringUtils.removeEnd(text, character);
	return text;
}
 
Example 20
Source File: SlaEventSubmitter.java    From incubator-gobblin with Apache License 2.0 2 votes vote down vote up
/**
 * {@link SlaEventKeys} have a prefix of {@link SlaEventKeys#EVENT_GOBBLIN_STATE_PREFIX} to keep properties organized
 * in state. This method removes the prefix before submitting an Sla event.
 */
private String withoutPropertiesPrefix(String key) {
  return StringUtils.removeStart(key, SlaEventKeys.EVENT_GOBBLIN_STATE_PREFIX);
}