下面列出了org.apache.commons.lang3.StringUtils#removeStart ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
}
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;
}
}
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());
}
}
/**
* 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();
}
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());
}
}
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;
}
@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);
}
/**
* 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;
}
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);
}
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;
}
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())));
}
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;
}
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));
}
}
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;
}
}
@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;
}
private String removeWrappingQuotes(String s) {
return StringUtils.removeStart(StringUtils.removeEnd(s.trim(), "\""), "\"");
}
MetricFetcher(String name) {
this.name = StringUtils.removeStart(StringUtils.removeEnd(name, "/"), "/");
this.accpetMetrics = Collections.singletonList(name);
}
private String getRelativePath(final String fullUrl, final String remote) {
return StringUtils.removeStart(fullUrl, remote);
}
public static String trim(String text, final String character)
{
text = StringUtils.removeStart(text, character);
text = StringUtils.removeEnd(text, character);
return text;
}
/**
* {@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);
}