List of usage examples for org.apache.commons.lang3 StringUtils substring
public static String substring(final String str, int start)
Gets a substring from the specified String avoiding exceptions.
A negative start position can be used to start n characters from the end of the String.
A null String will return null .
From source file:com.bellman.bible.android.view.activity.page.MainBibleActivity.java
private BibleRef getAllRefFromUri(String uri) { String usefulPath = StringUtils.substring(uri.toString(), 17); String[] spStr = StringUtils.split(usefulPath, "/"); int bookNo = getBibleBookNo(spStr[0]); BibleRef ref = new BibleRef(bookNo, Integer.parseInt(spStr[1]), Integer.parseInt(spStr[2])); Log.d(TAG, ref.toString());/*ww w .j ava 2 s . c o m*/ return ref; }
From source file:de.knightsoftnet.validators.shared.impl.PhoneNumberValueRestValidator.java
private String urlEncode(final String pphoneNumber) { if (StringUtils.startsWith(pphoneNumber, "+")) { return "%2B" + URL.encode(StringUtils.substring(pphoneNumber, 1)); } else {//from w w w. j av a2 s . c o m return URL.encode(pphoneNumber); } }
From source file:de.micromata.genome.db.jpa.logging.BaseJpaLoggingImpl.java
/** * Split cols string.//from w w w . j a va2 s . c om * * @param content the content * @param cols the cols * @return the string */ public static String splitColsString(String content, List<String> cols) { if (content == null) { return null; } for (int i = 0; i < COLNUM && content.length() > 0; ++i) { String t = Converter.trimUtf8(content, COLSIZE); content = StringUtils.substring(content, t.length()); cols.add(t); // alt aber gehend // int byteL = COLSIZE; // String t = StringUtils.substring(content, 0, byteL); // // byte[] contentBytes = Converter.bytesFromString(t); // if (contentBytes.length > COLSIZE) { // int dif = (contentBytes.length - COLSIZE); // byteL = t.length() - dif; // t = StringUtils.substring(content, 0, byteL); // } // cols.add(t); } return content; }
From source file:com.adobe.cq.wcm.core.components.internal.servlets.SearchResultServlet.java
private Resource getSearchContentResource(SlingHttpServletRequest request, Page currentPage) { Resource searchContentResource = null; RequestPathInfo requestPathInfo = request.getRequestPathInfo(); Resource resource = request.getResource(); String relativeContentResource = requestPathInfo.getSuffix(); if (StringUtils.startsWith(relativeContentResource, "/")) { relativeContentResource = StringUtils.substring(relativeContentResource, 1); }//from ww w . j av a 2s . c om if (StringUtils.isNotEmpty(relativeContentResource)) { searchContentResource = resource.getChild(relativeContentResource); if (searchContentResource == null) { PageManager pageManager = resource.getResourceResolver().adaptTo(PageManager.class); if (pageManager != null) { Template template = currentPage.getTemplate(); if (template != null) { Resource templateResource = request.getResourceResolver().getResource(template.getPath()); if (templateResource != null) { searchContentResource = templateResource .getChild(NN_STRUCTURE + "/" + relativeContentResource); } } } } } return searchContentResource; }
From source file:com.ottogroup.bi.streaming.operator.json.decode.Base64ContentDecoder.java
/** * Decodes the provided {@link Base64} encoded string. Prior decoding a possibly existing prefix is removed from the encoded string. * The result which is received from {@link Decoder#decode(byte[])} as array of bytes is converted into a string representation which * follows the given encoding //from w ww. j a v a 2 s.c o m * @param base64EncodedString * The {@link Base64} encoded string * @param noValuePrefix * An optional prefix attached to string after encoding (eg to mark it as base64 value) which must be removed prior decoding * @param encoding * The encoding applied on converting the resulting byte array into a string representation * @return */ protected String decodeBase64(final String base64EncodedString, final String noValuePrefix, final String encoding) throws UnsupportedEncodingException { // if the base64 encoded string is either empty or holds only the prefix that must be removed before decoding, the method returns an empty string if (StringUtils.isBlank(base64EncodedString) || StringUtils.equalsIgnoreCase(base64EncodedString, noValuePrefix)) return ""; // remove optional prefix and decode - if the prefix does not exist, simply decode the input byte[] result = null; if (StringUtils.startsWith(base64EncodedString, noValuePrefix)) result = Base64.getDecoder().decode(StringUtils.substring(base64EncodedString, noValuePrefix.length())); else result = Base64.getDecoder().decode(base64EncodedString); // if the result array is either null or empty the method returns an empty string if (result == null || result.length < 1) return ""; // otherwise: the method tries to convert the array into a proper string representation following the given encoding return new String(result, (StringUtils.isNotBlank(encoding) ? encoding : "UTF-8")); }
From source file:ke.co.tawi.babblesms.server.servlet.sms.callback.Callback.java
/** * @param request //www . j a v a2s. c o m * @param response * @throws ServletException, IOException */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DateTimeFormatter timeFormatter = ISODateTimeFormat.dateTimeNoMillis(); String callbackType = request.getParameter("callbackType"); String messageId; LocalDateTime datetime; switch (callbackType) { case "status": // A notification of an SMS Status change messageId = request.getParameter("messageId"); datetime = timeFormatter.parseLocalDateTime(request.getParameter("datetime")); String status = request.getParameter("status"); OutgoingLog log = outgoingLogDAO.get(messageId); log.setLogTime(datetime.toDate()); log.setMessagestatusuuid(dlrstatusMap.get(status)); outgoingLogDAO.put(log); break; case "incomingSms": String network = request.getParameter("network").toLowerCase(); datetime = timeFormatter.parseLocalDateTime(request.getParameter("datetime")); IncomingLog incomingLog = new IncomingLog(); incomingLog.setDestination(request.getParameter("destination")); incomingLog.setUuid(request.getParameter("messageId")); incomingLog.setMessage(request.getParameter("message")); incomingLog.setLogTime(datetime.toDate()); incomingLog.setNetworkUuid(networkMap.get(network)); // The source saved in the address book may begin with "07" // but the one received for Kenya would begin with "254" // We have to reconcile the two String source = request.getParameter("source"); String phoneNum = ""; if (StringUtils.startsWith(source, "254")) { phoneNum = "07" + StringUtils.substring(source, 4); } if (phoneDAO.getPhones(phoneNum).size() > 0) { incomingLog.setOrigin(phoneNum); } else { incomingLog.setOrigin(source); } // Determine the account that it is destined for // This assumes that the same shortcode number cannot // be owned by multiple accounts for (Shortcode shortcode : shortcodeList) { if (shortcode.getCodenumber().equals(incomingLog.getDestination())) { incomingLog.setRecipientUuid(shortcode.getAccountuuid()); break; } } incomingLogDAO.putIncomingLog(incomingLog); break; } }
From source file:com.joyent.manta.client.MantaClientRangeIT.java
public final void canGetWithEndRangeBeyondObjectSize() throws IOException { final String name = UUID.randomUUID().toString(); final String path = testPathPrefix + name; final String expected = StringUtils.substring(TEST_DATA, 50); mantaClient.put(path, TEST_DATA);//from ww w . j av a 2 s.c o m final MantaHttpHeaders headers = new MantaHttpHeaders(); // Range is inclusive, inclusive headers.setRange("bytes=50-" + Integer.MAX_VALUE); try (final InputStream min = mantaClient.getAsInputStream(path, headers)) { String actual = IOUtils.toString(min, Charset.defaultCharset()); Assert.assertEquals(actual, expected, "Didn't receive correct range value"); } }
From source file:jp.mathes.databaseWiki.dav.TableResource.java
@Override @SuppressWarnings("unchecked") public Resource createNew(String newName, InputStream inputStream, Long length, String contentType) throws IOException, ConflictException, NotAuthorizedException, BadRequestException { try {/*from ww w .j a v a2 s .com*/ Document doc = DbwConfiguration.getInstance().getBackend().getDocument(this.user, this.password, this.dbName, this.name, name, true); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String line = reader.readLine(); while (line != null) { if (StringUtils.isEmpty(line) || StringUtils.isWhitespace(line)) { // everything after this line is field content StringBuffer content = new StringBuffer(); while ((line = reader.readLine()) != null) { if (content.length() > 0) { content.append("\n"); } content.append(line); } if (doc.getAllFields().containsKey("content")) { doc.getAllFields().get("content").setValue(content.toString()); } else { DbwConfiguration.getInstance().davLog("Parse error, could not set field 'content'."); throw new BadRequestException(this, "Parse error, could not set field 'content'."); } } else if (line.startsWith("\t")) { // if the line starts with a tab it has to be the continuation of // another line (which is handled in the else path) or is a mistake DbwConfiguration.getInstance() .davLog("Line starts with tab although it is not a continuation."); throw new BadRequestException(this, "Line starts with tab although it is not a continuation."); } else { // this is a regular field, potentially with continuation String[] split = StringUtils.split(line, ":", 2); String fieldName = split[0].trim(); StringBuffer fieldValue = new StringBuffer(split[1].trim()); String nextLine = reader.readLine(); while (nextLine != null && nextLine.startsWith("\t")) { fieldValue.append("\n").append(StringUtils.substring(nextLine, 1)); } line = nextLine; if (doc.getAllFields().containsKey(fieldName)) { doc.getAllFields().get(fieldName).setValue(fieldValue.toString()); } else { DbwConfiguration.getInstance() .davLog(String.format("Parse error, could not set field '%s'.", fieldName)); throw new BadRequestException(this, String.format("Parse error, could not set field '%s'.", fieldName)); } } } DbwConfiguration.getInstance().getBackend().saveDocument(this.user, this.password, this.dbName, this.name, name, doc); } catch (DocumentNotFoundException e) { DbwConfiguration.getInstance().davLog("Impossible DocumentNotFoundException in createNew()", e); throw new BadRequestException(this, "This cannot happen with allowEmpty=true (getDocument)."); } catch (BackendException e) { DbwConfiguration.getInstance().davLog("BackendException in createNew()", e); throw new BadRequestException(this, e.getMessage()); } return null; }
From source file:jenkins.plugins.asqatasun.AsqatasunRunner.java
private String getNbStatus(PrintStream ps, boolean isFirstNb, String line) { ps.println(line);/*from ww w. ja va2 s . c o m*/ if (isFirstNb) { return StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim(); } return null; }
From source file:com.thoughtworks.go.domain.AccessToken.java
public boolean isValidToken(String actualToken) { String originalToken = StringUtils.substring(actualToken, 8); String saltValue = getSaltValue(); String digestOfUserProvidedToken = digestToken(originalToken, saltValue); return getValue().equals(digestOfUserProvidedToken); }