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

The following examples show how to use org.apache.commons.lang.StringUtils#chomp() . 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
Source Project: azure-devops-intellij   File: CheckinCommand.java    License: MIT License 6 votes vote down vote up
/**
 * Returns the files that were added
 * <p/>
 * Output example for success:
 * /Users/leantk/tfvc-tfs/tfsTest_01/addFold:
 * Checking in edit: testHere.txt
 * <p/>
 * /Users/leantk/tfvc-tfs/tfsTest_01:
 * Checking in edit: test3.txt
 * Checking in edit: TestAdd.txt
 * <p/>
 * Changeset #20 checked in.
 * <p/>
 * Output example for failure:
 * <p/>
 * /Users/leantk/tfvc-tfs/tfsTest_01:
 * Checking in edit: test3.txt
 * Checking in edit: TestAdd.txt
 * Unable to perform operation on $/tfsTest_01/TestAdd.txt. The item $/tfsTest_01/TestAdd.txt is locked in workspace new;Leah Antkiewicz.
 * No files checked in.
 * <p/>
 * No files checked in.
 */
@Override
public String parseOutput(final String stdout, final String stderr) {
    // check for failed checkin
    if (StringUtils.isNotEmpty(stderr)) {
        logger.error("Checkin failed with the following stdout:\n" + stdout);
        final String[] output = getLines(stdout);
        final StringBuilder errorMessage = new StringBuilder();
        for (int i = 0; i < output.length; i++) {
            // finding error message by eliminating all other known output lines since we can't parse for the error line itself (it's unknown to us)
            // TODO: figure out a better way to get the error message instead of parsing
            if (!isOutputLineExpected(output[i], new String[]{CHECKIN_LINE_PREFIX, CHECKIN_FAILED_MSG}, true)) {
                errorMessage.append(output[i]).append("\n");
            }
        }
        if (StringUtils.isNotEmpty(errorMessage.toString())) {
            throw new RuntimeException(StringUtils.chomp(errorMessage.toString()));
        }
        // couldn't figure out error message parsing so returning generic error
        logger.error("Parsing of the stdout failed to get the error message");
        throw new TeamServicesException(TeamServicesException.KEY_ERROR_UNKNOWN);
    }

    return getChangesetNumber(stdout);
}
 
Example 2
Source Project: azure-devops-intellij   File: IdeaHelper.java    License: MIT License 6 votes vote down vote up
/**
 * Finds the full path to a resource whether it's installed by the idea or being run inside the idea
 *
 * @param resourceUrl  the URL for the resource
 * @param resourceName name of the resource
 * @param directory    the directory under the idea.plugin/resource directory to for the resource
 * @return the path to the resource
 * @throws UnsupportedEncodingException
 */
public static String getResourcePath(final URL resourceUrl, final String resourceName, final String directory) throws UnsupportedEncodingException {
    // find location of the resource
    String resourcePath = resourceUrl.getPath();
    resourcePath = URLDecoder.decode(resourcePath, CHARSET_UTF8);
    resourcePath = StringUtils.chomp(resourcePath, "/");

    // When running the plugin inside of the idea for test, the path to the app needs to be
    // manipulated to look in a different location than where the resource resides in production.
    // For prod the url is .../../.IdeaIC15/config/plugins/com.microsoft.alm/lib but for test
    // the url is ../.IdeaIC15/system/plugins-sandbox/plugins/com.microsoft.alm.plugin.idea/classes
    if (resourcePath != null && resourcePath.endsWith(PROD_RESOURCES_SUB_PATH)) {
        return resourcePath + "/" + directory + "/" + resourceName;
    } else {
        return resourcePath + TEST_RESOURCES_SUB_PATH + directory + "/" + resourceName;
    }
}
 
Example 3
/**
 * Strip byte count from the bytebuffer. IRTrans devices include the number of bytes sent
 * in each response it sends back to the connected host. This is a simple error checking
 * mechanism - we do need that information, and so, we strip it
 *
 * @param byteBuffer
 *            the byte buffer
 * @return the string
 */
protected String stripByteCount(ByteBuffer byteBuffer) {
    /** {@link Pattern} which matches a binding configuration part */
    Pattern RESPONSE_PATTERN = Pattern.compile("..(\\d{5}) (.*)");
    String message = null;

    String response = new String(byteBuffer.array(), 0, byteBuffer.limit());
    response = StringUtils.chomp(response);

    Matcher matcher = RESPONSE_PATTERN.matcher(response);
    if (matcher.matches()) {
        String byteCountAsString = matcher.group(1);
        int byteCount = Integer.parseInt(byteCountAsString);
        message = matcher.group(2);
    }

    return message;
}
 
Example 4
public String getAssignedToRolesToDisplay() {
    StringBuffer assignedToRolesText = new StringBuffer();
    for (RoleBo roleImpl: assignedToRoles) {
        assignedToRolesText.append(roleImpl.getNamespaceCode().trim())
                .append(" ")
                .append(roleImpl.getName().trim())
                .append(KimConstants.KimUIConstants.COMMA_SEPARATOR);
    }
    return StringUtils.chomp(assignedToRolesText.toString(), KimConstants.KimUIConstants.COMMA_SEPARATOR);
}
 
Example 5
public String getAssignedToRolesToDisplay() {
    StringBuffer assignedToRolesToDisplay = new StringBuffer();
    for (RoleBo roleImpl : assignedToRoles) {
        assignedToRolesToDisplay.append(getRoleDetailsToDisplay(roleImpl));
    }

    return StringUtils.chomp(assignedToRolesToDisplay.toString(), KimConstants.KimUIConstants.COMMA_SEPARATOR);
}
 
Example 6
public void serialEvent(SerialPortEvent event) {
    switch (event.getEventType()) {
        case SerialPortEvent.BI:
        case SerialPortEvent.OE:
        case SerialPortEvent.FE:
        case SerialPortEvent.PE:
        case SerialPortEvent.CD:
        case SerialPortEvent.CTS:
        case SerialPortEvent.DSR:
        case SerialPortEvent.RI:
        case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
            break;
        case SerialPortEvent.DATA_AVAILABLE:
            try {
                BufferedReader br = new BufferedReader(new InputStreamReader(inputStream), 32 * 1024 * 1024);
                if (br.ready()) {
                    String line = br.readLine();
                    line = StringUtils.chomp(line);
                    line = line.replace(",", ".");
                    response = line.trim();
                }
            } catch (IOException e) {
                logger.debug("Error receiving data on serial port {}: {}",
                        new Object[] { port, e.getMessage() });
            }
            break;
    }
}
 
Example 7
Source Project: uReplicator   File: HelixUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static String getAbsoluteZkPathForHelix(String zkBaseUrl) {
  zkBaseUrl = StringUtils.chomp(zkBaseUrl, "/");
  return zkBaseUrl;
}
 
Example 8
protected void validateUpdatabableReferencesRecursively(Object businessObject, int maxDepth,
        boolean validateRequired, boolean chompLastLetterSFromCollectionName, Set<Object> processedBOs) {
    // if null or already processed, return
    if (KRADUtils.isNull(businessObject) || processedBOs.contains(businessObject)) {
        return;
    }
    processedBOs.add(businessObject);  // add bo to list to prevent excessive looping
    Map<String, Class> references = getLegacyDataAdapter().listReferenceObjectFields(businessObject.getClass());
    for (String referenceName : references.keySet()) {
        if (getLegacyDataAdapter().isReferenceUpdatable(businessObject.getClass(), referenceName)) {
            Object referenceObj = KradDataServiceLocator.getDataObjectService().wrap(businessObject)
                    .getPropertyValueNullSafe(referenceName);

            if (KRADUtils.isNull(referenceObj) || !(referenceObj instanceof PersistableBusinessObject)) {
                continue;
            }

            BusinessObject referenceBusinessObject = (BusinessObject) referenceObj;
            GlobalVariables.getMessageMap().addToErrorPath(referenceName);
            validateBusinessObject(referenceBusinessObject, validateRequired);
            if (maxDepth > 0) {
                validateUpdatabableReferencesRecursively(referenceBusinessObject, maxDepth - 1, validateRequired,
                        chompLastLetterSFromCollectionName, processedBOs);
            }
            GlobalVariables.getMessageMap().removeFromErrorPath(referenceName);
        }
    }
    Map<String, Class> collections = getLegacyDataAdapter().listCollectionObjectTypes(businessObject.getClass());
    for (String collectionName : collections.keySet()) {
        if (getLegacyDataAdapter().isCollectionUpdatable(businessObject.getClass(), collectionName)) {
            Object listObj = KradDataServiceLocator.getDataObjectService().wrap(businessObject)
                    .getPropertyValueNullSafe(collectionName);

            if (KRADUtils.isNull(listObj)) {
                continue;
            }

            if (!(listObj instanceof List)) {
                if (LOG.isInfoEnabled()) {
                    LOG.info("The reference named " + collectionName + " of BO class " +
                            businessObject.getClass().getName() +
                            " should be of type java.util.List to be validated properly.");
                }
                continue;
            }

            List list = (List) listObj;

            //should we materialize the proxied collection or just skip validation here assuming an unmaterialized objects are valid?
            KRADUtils.materializeObjects(list);

            for (int i = 0; i < list.size(); i++) {
                final Object o = list.get(i);
                if (KRADUtils.isNotNull(o) && o instanceof PersistableBusinessObject) {
                    final BusinessObject element = (BusinessObject) o;

                    final String errorPathAddition;
                    if (chompLastLetterSFromCollectionName) {
                        errorPathAddition = StringUtils.chomp(collectionName, "s")
                                + "["
                                + Integer.toString(i)
                                + "]";
                    } else {
                        errorPathAddition = collectionName + "[" + Integer.toString(i) + "]";
                    }

                    GlobalVariables.getMessageMap().addToErrorPath(errorPathAddition);
                    validateBusinessObject(element, validateRequired);
                    if (maxDepth > 0) {
                        validateUpdatabableReferencesRecursively(element, maxDepth - 1, validateRequired,
                                chompLastLetterSFromCollectionName, processedBOs);
                    }
                    GlobalVariables.getMessageMap().removeFromErrorPath(errorPathAddition);
                }
            }
        }
    }
}
 
Example 9
Source Project: incubator-pinot   File: HelixConfig.java    License: Apache License 2.0 4 votes vote down vote up
public static String getAbsoluteZkPathForHelix(String zkBaseUrl) {
  zkBaseUrl = StringUtils.chomp(zkBaseUrl, "/");
  return zkBaseUrl;
}
 
Example 10
private ControllerRequestURLBuilder(String baseUrl) {
  _baseUrl = StringUtils.chomp(baseUrl, "/");
}
 
Example 11
public void serialEvent(SerialPortEvent event) {
    switch (event.getEventType()) {
        case SerialPortEvent.BI:
        case SerialPortEvent.OE:
        case SerialPortEvent.FE:
        case SerialPortEvent.PE:
        case SerialPortEvent.CD:
        case SerialPortEvent.CTS:
        case SerialPortEvent.DSR:
        case SerialPortEvent.RI:
        case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
            break;
        case SerialPortEvent.DATA_AVAILABLE:

            try {

                BufferedReader br = new BufferedReader(new InputStreamReader(inputStream), 32 * 1024 * 1024);
                while (br.ready()) {
                    String line = br.readLine();
                    line = StringUtils.chomp(line);

                    // little hack to overcome Locale limits of the RME Rain Manager
                    // note to the attentive reader : should we add support for system locale's
                    // in the Type classes? ;-)
                    line = line.replace(",", ".");
                    line = line.trim();

                    if (previousLine == null) {
                        previousLine = line;
                    }

                    if (!previousLine.equals(line)) {
                        processData(line);
                        previousLine = line;
                    }
                }

            } catch (IOException e) {
                logger.debug("Error receiving data on serial port {}: {}",
                        new Object[] { port, e.getMessage() });
            }
            break;
    }
}
 
Example 12
Source Project: openhab1-addons   File: Stick.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Parse a buffer into a Message and put it in the appropriate queue for further processing
 *
 * @param readBuffer - the string to parse
 */
private void parseAndQueue(ByteBuffer readBuffer) {
    if (readBuffer != null) {

        String response = new String(readBuffer.array(), 0, readBuffer.limit());
        response = StringUtils.chomp(response);

        Matcher matcher = RESPONSE_PATTERN.matcher(response);

        if (matcher.matches()) {

            String protocolHeader = matcher.group(1);
            String command = matcher.group(2);
            String sequence = matcher.group(3);
            String payload = matcher.group(4);
            String CRC = matcher.group(5);

            if (protocolHeader.equals(PROTOCOL_HEADER)) {
                String calculatedCRC = getCRCFromString(command + sequence + payload);
                if (calculatedCRC.equals(CRC)) {

                    int messageTypeNumber = Integer.parseInt(command, 16);
                    MessageType messageType = MessageType.forValue(messageTypeNumber);
                    int sequenceNumber = Integer.parseInt(sequence, 16);

                    if (messageType == null) {
                        logger.debug("Received unrecognized messageTypeNumber:{} command:{} sequence:{} payload:{}",
                                messageTypeNumber, command, sequenceNumber, payload);
                        return;
                    }

                    logger.debug("Received message: command:{} sequence:{} payload:{}", messageType, sequenceNumber,
                            payload);

                    Message message = createMessage(messageType, command, sequenceNumber, payload);

                    try {
                        if (message instanceof AcknowledgeMessage && !((AcknowledgeMessage) message).isExtended()) {
                            logger.debug("Adding to acknowledgedQueue: {}", message);
                            acknowledgedQueue.put((AcknowledgeMessage) message);
                        } else {
                            logger.debug("Adding to receivedQueue: {}", message);
                            receivedQueue.put(message);
                        }
                    } catch (InterruptedException e) {
                        Thread.interrupted();
                    }
                } else {
                    logger.error("Plugwise protocol CRC error: {} does not match {} in message", calculatedCRC,
                            CRC);
                }
            } else {
                logger.debug("Plugwise protocol header error: {} in message {}", protocolHeader, response);
            }
        } else {
            if (!response.contains("APSRequestNodeInfo")) {
                logger.error("Plugwise protocol message error: {}", response);
            }
        }
    }
}