public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Введите текст и программа даст инфомрацию о тексте: "); String text = reader.readLine(); if (StringUtils.isAllUpperCase(text)) System.out.println("В тексте только заглавные буквы"); if (StringUtils.isAllLowerCase(text)) System.out.println("В тексте только строчные буквы"); if (StringUtils.isNumeric(text)) System.out.println("Тест состоит из цифр"); String tempReverse = StringUtils.reverse(text); System.out.println("Перевернутый текст: " + tempReverse); int length = StringUtils.length(text); System.out.println("Длина текста: " + length); if (length >= 5) { String tempRight = StringUtils.right(text, 5); System.out.println("Первые 5 символов текста: " + tempRight); } else { System.out.println("Длина текста менее 5 символов"); } reader.close(); }
// 1234567.gpx -> 1234567-wpts.gpx static String getWaypointsFileNameForGpxFileName(String name) { if (StringUtils.endsWithIgnoreCase(name, GPX_FILE_EXTENSION) && (StringUtils.length(name) > GPX_FILE_EXTENSION.length())) { return StringUtils.substringBeforeLast(name, ".") + WAYPOINTS_FILE_SUFFIX_AND_EXTENSION; } else { return null; } }
// 1234567.zip -> 1234567.gpx static String getGpxFileNameForZipFileName(String name) { if (StringUtils.endsWithIgnoreCase(name, ZIP_FILE_EXTENSION) && (StringUtils.length(name) > ZIP_FILE_EXTENSION.length())) { return StringUtils.substringBeforeLast(name, ".") + GPX_FILE_EXTENSION; } else { return null; } }
@Test public void testPath() throws Exception { String packName = "com.mo008.wx.controllers.api"; String appPackPrefix = "com.mo008"; final String path = StringUtils.substring( packName, StringUtils.length(appPackPrefix + "."), StringUtils.indexOf(packName, ".controllers")); System.out.println("path = " + path); }
// 1234567.gpx -> 1234567-wpts.gpx static File getWaypointsFileForGpx(File file) { final String name = file.getName(); if (StringUtils.endsWithIgnoreCase(name, GPX_FILE_EXTENSION) && (StringUtils.length(name) > GPX_FILE_EXTENSION.length())) { final String wptsName = StringUtils.substringBeforeLast(name, ".") + WAYPOINTS_FILE_SUFFIX_AND_EXTENSION; return new File(file.getParentFile(), wptsName); } else { return null; } }
@RequestMapping(value = "/validateName", method = RequestMethod.POST) public @ResponseBody JsonResponse validateName( @RequestParam(value = "name", required = true) String name) { String error = ""; if (StringUtils.isEmpty(name)) { error = messageResource.getMessage("org.hibernate.validator.constraints.NotEmpty.message"); } else if (StringUtils.length(name) > 255) { error = messageResource.getMessage("validation.constraints.Size.message", "1", "255"); } return getResponse(error); }
private static int[] colWidths() { int cols = -1; for (String[] row : rows) cols = Math.max(cols, row.length); int[] widths = new int[cols]; for (String[] row : rows) { for (int colNum = 0; colNum < row.length; colNum++) { widths[colNum] = Math.max(widths[colNum], StringUtils.length(row[colNum])); } } return widths; }
public static boolean isGoogleMapsInstalled() { // Check if API key is available final String mapsKey = CgeoApplication.getInstance().getString(R.string.maps_api_key); if (StringUtils.length(mapsKey) < 30 || StringUtils.contains(mapsKey, "key")) { Log.w("No Google API key available."); return false; } // Check if API is available try { Class.forName("com.google.android.maps.MapActivity"); } catch (final ClassNotFoundException ignored) { return false; } // Assume that Google Maps is available and working return true; }
public HttpRsp _send(String request, String jsonData) { HttpRsp httpRsp = new HttpRsp(); if (null == serverHost || null == client) { httpRsp.status = -1; return httpRsp; } if (StringUtils.isBlank(request)) { return httpRsp; } HttpRequestBase httpRequest; if (StringUtils.isNotBlank(jsonData)) { httpRequest = new HttpPost(request); ((HttpPost) httpRequest).setEntity(new StringEntity(jsonData, Charset.forName("utf-8"))); } else { httpRequest = new HttpGet(request); } try { HttpResponse response = client.execute(serverHost, httpRequest); httpRsp.status = response.getStatusLine().getStatusCode(); if (200 == httpRsp.status) { httpRsp.content = EntityUtils.toString(response.getEntity(), "utf-8"); if (logger.isDebugEnabled()) { logger.debug("Http请求成功 {} {}", request, jsonData); } else { logger.info("Http请求成功 {} {}", request, StringUtils.length(jsonData)); } } EntityUtils.consumeQuietly(response.getEntity()); } catch (Exception e) { logger.error("Http执行异常:" + request, e); httpRsp.status = -1; } finally { httpRequest.releaseConnection(); } return httpRsp; }