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

The following examples show how to use org.apache.commons.lang3.StringUtils#isWhitespace() . These examples are extracted from open source projects. 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
private boolean canLoad( final String line ) {
	final boolean comment = line.startsWith( FilterPreserveLine.COMMENT );
	if ( comment ) {
		return true;
	}

	final boolean onlyWhiteSpace = StringUtils.isWhitespace( line );
	if ( onlyWhiteSpace ) {
		return true;
	}

	final boolean leadingWhitespace = Character.isWhitespace( line.charAt( 0 ) );
	if ( leadingWhitespace ) {
		log.warn( "Please remove leading whitespace from the following line:\n{}", line );
		return true;
	}

	return false;
}
 
Example 2
Source Project: jsflight   File: Http2JMeter.java    License: Apache License 2.0 6 votes vote down vote up
public LinkedHashMap<String, Integer> getRequestsByUsers(List<RestoredRequest> requests)
{
    LinkedHashMap<String, Integer> result = new LinkedHashMap<>();

    for (RestoredRequest request : requests)
    {
        String uuid = getUserUuidByRequest(request);
        String sessionId = getUserSessionId(request);
        if (!StringUtils.isWhitespace(uuid))
        {
            Integer filtered = result.get(uuid);
            if (filtered == null)
            {
                filtered = new Integer(0);
                result.put(uuid, filtered);
            }
            else
            {
                result.put(uuid, filtered + 1);
            }

        }
    }

    return result;
}
 
Example 3
Source Project: botbuilder-java   File: TurnContextImpl.java    License: MIT License 5 votes vote down vote up
/**
 * Deletes an existing activity.
 *
 * @param activityId The ID of the activity to delete.
 * @return A task that represents the work queued to execute.
 */
public CompletableFuture<Void> deleteActivity(String activityId) {
    if (StringUtils.isWhitespace(activityId) || StringUtils.isEmpty(activityId)) {
        throw new IllegalArgumentException("activityId");
    }

    ConversationReference cr = activity.getConversationReference();
    cr.setActivityId(activityId);

    Supplier<CompletableFuture<Void>> actuallyDeleteStuff = () -> getAdapter()
        .deleteActivity(this, cr);

    return deleteActivityInternal(cr, onDeleteActivity.iterator(), actuallyDeleteStuff);
}
 
Example 4
private String generateMessagePayload(String verb, String resourceId, String resourceType,
        Map<String, String> headers) {
    String xDate = headers.get(HttpConstants.HttpHeaders.X_DATE);
    String date = headers.get(HttpConstants.HttpHeaders.HTTP_DATE);
    // At-least one of date header should present
    // https://docs.microsoft.com/en-us/rest/api/documentdb/access-control-on-documentdb-resources
    if (StringUtils.isEmpty(xDate) && (StringUtils.isEmpty(date) || StringUtils.isWhitespace(date))) {
        headers.put(HttpConstants.HttpHeaders.X_DATE, Utils.nowAsRFC1123());
        xDate = Utils.nowAsRFC1123();
    }

    // for name based, it is case sensitive, we won't use the lower case
    if (!PathsHelper.isNameBased(resourceId)) {
        resourceId = resourceId.toLowerCase();
    }

    String xDateOrDateOrEmpty = StringUtils.isEmpty(xDate) ? date.toLowerCase() : "";
    int len = verb.length() + resourceType.length() + resourceId.length() + xDate.length() +
            xDateOrDateOrEmpty.length() + 5;

    StringBuilder payload = new StringBuilder(len);
    payload.append(verb.toLowerCase())
            .append('\n')
            .append(resourceType.toLowerCase())
            .append('\n')
            .append(resourceId)
            .append('\n')
            .append(xDate.toLowerCase())
            .append('\n')
            .append(xDateOrDateOrEmpty)
            .append('\n');

    return payload.toString();
}
 
Example 5
static void parseRootless(final StringReader reader, final Host host) throws HostParserException {
    // This is not RFC-compliant.
    // * Rootless-path must not include authentication information.
    final boolean userInfoResult = parseUserInfo(reader, host);

    if(host.getProtocol().isHostnameConfigurable() && StringUtils.isWhitespace(host.getHostname())) {
        // This is not RFC-compliant.
        // We assume for hostconfigurable-empty-hostnames a hostname on first path segment
        parseHostname(reader, host);
    }
    parsePath(reader, host, false);
}
 
Example 6
Source Project: samza   File: SqlFileParser.java    License: Apache License 2.0 5 votes vote down vote up
public static List<String> parseSqlFile(String fileName) {
  Validate.notEmpty(fileName, "fileName cannot be empty.");
  List<String> sqlLines;
  try {
    sqlLines = Files.lines(Paths.get(fileName)).collect(Collectors.toList());
  } catch (IOException e) {
    String msg = String.format("Unable to parse the sql file %s", fileName);
    LOG.error(msg, e);
    throw new SamzaException(msg, e);
  }
  List<String> sqlStmts = new ArrayList<>();
  String lastStatement = "";
  for (String sqlLine : sqlLines) {
    String sql = sqlLine.trim();
    if (sql.toLowerCase().startsWith(INSERT_CMD)) {
      if (StringUtils.isNotEmpty(lastStatement)) {
        sqlStmts.add(lastStatement);
      }

      lastStatement = sql;
    } else if (StringUtils.isNotBlank(sql) && !sql.startsWith(SQL_COMMENT_PREFIX)) {
      lastStatement = String.format("%s %s", lastStatement, sql);
    }
  }

  if (!StringUtils.isWhitespace(lastStatement)) {
    sqlStmts.add(lastStatement);
  }
  return sqlStmts;
}
 
Example 7
Source Project: azure-cosmosdb-java   File: Strings.java    License: MIT License 4 votes vote down vote up
public static boolean isNullOrWhiteSpace(String str) {
    return StringUtils.isEmpty(str) || StringUtils.isWhitespace(str);
}
 
Example 8
Source Project: para   File: CORSFilter.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Determines the request type.
 * @param request req
 * @return CORS request type
 */
public CORSRequestType checkRequestType(final HttpServletRequest request) {
	CORSRequestType requestType = CORSRequestType.INVALID_CORS;
	if (request == null) {
		throw new IllegalArgumentException(
				"HttpServletRequest object is null");
	}
	String originHeader = request.getHeader(REQUEST_HEADER_ORIGIN);
	// Section 6.1.1 and Section 6.2.1
	if (originHeader != null) {
		if (originHeader.isEmpty()) {
			requestType = CORSRequestType.INVALID_CORS;
		} else if (!isValidOrigin(originHeader)) {
			requestType = CORSRequestType.INVALID_CORS;
		} else {
			String method = StringUtils.trimToEmpty(request.getMethod());
			if (HTTP_METHODS.contains(method)) {
				if ("OPTIONS".equals(method)) {
					String accessControlRequestMethodHeader
							= request.getHeader(REQUEST_HEADER_ACCESS_CONTROL_REQUEST_METHOD);
					if (StringUtils.isNotBlank(accessControlRequestMethodHeader)) {
						requestType = CORSRequestType.PRE_FLIGHT;
					} else if (StringUtils.isWhitespace(accessControlRequestMethodHeader)) {
						requestType = CORSRequestType.INVALID_CORS;
					} else {
						requestType = CORSRequestType.ACTUAL;
					}
				} else if ("GET".equals(method) || "HEAD".equals(method)) {
					requestType = CORSRequestType.SIMPLE;
				} else if ("POST".equals(method)) {
					String contentType = request.getContentType();
					if (contentType != null) {
						contentType = contentType.toLowerCase().trim();
						if (SIMPLE_HTTP_REQUEST_CONTENT_TYPE_VALUES
								.contains(contentType)) {
							requestType = CORSRequestType.SIMPLE;
						} else {
							requestType = CORSRequestType.ACTUAL;
						}
					}
				} else if (COMPLEX_HTTP_METHODS.contains(method)) {
					requestType = CORSRequestType.ACTUAL;
				}
			}
		}
	} else {
		requestType = CORSRequestType.NOT_CORS;
	}

	return requestType;
}
 
Example 9
Source Project: baleen   File: RecordStructureManager.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Check if the annotation contains anything
 *
 * @param structure the structure
 * @return true if empty or white space
 */
private boolean isWhitespace(Structure structure) {
  String coveredText = structure.getCoveredText();
  return StringUtils.isEmpty(coveredText) || StringUtils.isWhitespace(coveredText);
}