@Test public void testIsAsciiPrintable_String() { assertFalse(StringUtils.isAsciiPrintable(null)); assertTrue(StringUtils.isAsciiPrintable("")); assertTrue(StringUtils.isAsciiPrintable(" ")); assertTrue(StringUtils.isAsciiPrintable("a")); assertTrue(StringUtils.isAsciiPrintable("A")); assertTrue(StringUtils.isAsciiPrintable("1")); assertTrue(StringUtils.isAsciiPrintable("Ceki")); assertTrue(StringUtils.isAsciiPrintable("!ab2c~")); assertTrue(StringUtils.isAsciiPrintable("1000")); assertTrue(StringUtils.isAsciiPrintable("10 00")); assertFalse(StringUtils.isAsciiPrintable("10\t00")); assertTrue(StringUtils.isAsciiPrintable("10.00")); assertTrue(StringUtils.isAsciiPrintable("10,00")); assertTrue(StringUtils.isAsciiPrintable("!ab-c~")); assertTrue(StringUtils.isAsciiPrintable("hkHK=Hik6i?UGH_KJgU7.tUJgKJ*GI87GI,kug")); assertTrue(StringUtils.isAsciiPrintable("\u0020")); assertTrue(StringUtils.isAsciiPrintable("\u0021")); assertTrue(StringUtils.isAsciiPrintable("\u007e")); assertFalse(StringUtils.isAsciiPrintable("\u007f")); assertTrue(StringUtils.isAsciiPrintable("G?lc?")); assertTrue(StringUtils.isAsciiPrintable("=?iso-8859-1?Q?G=FClc=FC?=")); assertFalse(StringUtils.isAsciiPrintable("G\u00fclc\u00fc")); }
@Override public void messageArrived(String topic, MqttMessage message) throws Exception { if (logger.isDebugEnabled()) { byte[] payload = message.getPayload(); String text = new String(payload, "UTF-8"); if (StringUtils.isAsciiPrintable(text)) { logger.debug("Message arrived from topic {}. Payload: {}", new Object[] {topic, text}); } else { logger.debug("Message arrived from topic {}. Binary value of size {}", new Object[] {topic, payload.length}); } } if (mqttQueue.size() >= maxQueueSize){ throw new IllegalStateException("The subscriber queue is full, cannot receive another message until the processor is scheduled to run."); } else { mqttQueue.add(new MQTTQueueMessage(topic, message)); } }
@Override protected boolean handle(CharSequence str) { return StringUtils.isAsciiPrintable(str); }
public static boolean isprintable(final CharSequence cs) { return StringUtils.isAsciiPrintable(cs); }
/** * 检查字符串是否只含有ASCII的可打印字符,字符串为null将返回false,""将返回true,引用org.apache.commons.lang.StringUtils.isAsciiPrintable(String str)方法。<br> * 例: <br> * StringUtil.isAsciiPrintable(null) = false <br> * StringUtil.isAsciiPrintable("") = true <br> * StringUtil.isAsciiPrintable(" ") = true <br> * StringUtil.isAsciiPrintable("Ceki") = true <br> * StringUtil.isAsciiPrintable("ab2c") = true <br> * StringUtil.isAsciiPrintable("!ab-c~") = true <br> * StringUtil.isAsciiPrintable("!") = true <br> * StringUtil.isAsciiPrintable("Ceki Gülcü") = false <br> * @param str 要检查的字符串 - 可能为null * @return boolean 如果字符串每个字符都在ASCII范围之内返回true,否则返回false。 */ public static boolean isAsciiPrintable(String str){ return StringUtils.isAsciiPrintable(str); }
return StringUtils.isAsciiPrintable(str);
/** Returns true if the password is valid. */ public static boolean isPasswordValid(String value) { return value != null && value.length() >= 8 && value.length() <= 20 && StringUtils.isAsciiPrintable(value); }
private void checkTags(Set<String> tags) { if (tags.size() > YarnConfiguration.APPLICATION_MAX_TAGS) { throw new IllegalArgumentException("Too many applicationTags, a maximum of only " + YarnConfiguration.APPLICATION_MAX_TAGS + " are allowed!"); } for (String tag : tags) { if (tag.length() > YarnConfiguration.APPLICATION_MAX_TAG_LENGTH) { throw new IllegalArgumentException("Tag " + tag + " is too long, " + "maximum allowed length of a tag is " + YarnConfiguration.APPLICATION_MAX_TAG_LENGTH); } if (!org.apache.commons.lang3.StringUtils.isAsciiPrintable(tag)) { throw new IllegalArgumentException("A tag can only have ASCII " + "characters! Invalid tag - " + tag); } } }
public String getEscaped(String str) { String printableStr; if (str == null) { printableStr = null; } else if (StringUtils.isAsciiPrintable(str)) { printableStr = str; } else { StringBuilder buffer = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c > 126) { buffer.append("(((").append((int) c).append(")))"); } else { buffer.append(c); } } printableStr = buffer.toString(); } return printableStr; }
/** Returns the markdown for a help item with the specified name. */ private String getHelpMarkdown(String helpName) { // Basic validation. if (helpName == null || helpName.isEmpty() || helpName.length() > 50 || !StringUtils.isAsciiPrintable(helpName)) { return null; } if (isInJar) { if (helpMarkdownMap.containsKey(helpName)) { return helpMarkdownMap.get(helpName); } } final String helpMarkeddown = getHelpMarkdownHelper(helpName); if (isInJar) { helpMarkdownMap.put(helpName, helpMarkeddown); } return helpMarkeddown; }
public static boolean isAsciiPrintable(ActionContext actionContext){ Thing self = actionContext.getObject("self"); CharSequence cs = (CharSequence) self.doAction("getCs", actionContext); return StringUtils.isAsciiPrintable(cs); }
protected String preprocessUri(final String uri) { if (StringUtil.isEmpty(uri)) { throw new RobotSystemException("The uri is empty."); } String filePath = uri; if (!filePath.startsWith("file:")) { filePath = "file://" + filePath; } final StringBuilder buf = new StringBuilder(filePath.length() + 100); try { for (final char c : filePath.toCharArray()) { if (c == ' ') { buf.append("%20"); } else { final String str = String.valueOf(c); if (StringUtils.isAsciiPrintable(str)) { buf.append(c); } else { buf.append(URLEncoder.encode(str, charset)); } } } } catch (final UnsupportedEncodingException e) { return filePath; } return buf.toString(); }
private String decryptColumn(String tableName, String colName, byte[] colValue, DbLibService dblibSvc) { String strValue = new String(colValue); if (StringUtils.isAsciiPrintable(strValue)) {
void assertOrder(List<byte[]> bytes, int expectedSize) { String prev = "0"; for (byte[] bytesKey : bytes) { String key = new String(bytesKey); if (StringUtils.isAsciiPrintable(key)) { System.out.println("key = " + key); } else { System.out.println("key = " + Bytes.toHex(bytesKey)); } // System.out.println(prev + ".compareTo(" + key + ") = " + prev.compareTo(key)); assertTrue(prev.compareTo(key) < 0); prev = key; } assertEquals(expectedSize, bytes.size()); }
private StructuralVariation buildSv(String[] split, String reference, String alternate) { if (split.length == SV_SPLIT_LENGTH) { try { Breakend breakend = VariantBuilder.parseBreakend(reference, alternate); return new StructuralVariation( getInt(split, CI_POS_L), getInt(split, CI_POS_R), getInt(split, CI_END_L), getInt(split, CI_END_R), VariantBuilder.getCopyNumberFromAlternate(alternate), null, null, null, breakend); } catch (RuntimeException e) { for (String s : split) { // If any of the splits is non printable, the variantId had 4 colons in the SHA1 if (!StringUtils.isAsciiPrintable(s)) { return null; } } throw new IllegalArgumentException("Unable to build SV from " + String.join(SEPARATOR, split), e); } } else { return null; } }
@Test public void testUploadTokenIsAscii() { // run a few times to rule out the (low) chance it is ascii just by chance; the seed will change regularly for (int i = 0; i < 1000; i++) { String encodedToken = new DataRecordUploadToken(BLOB_ID, UPLOAD_ID).getEncodedToken(SECRET); assertTrue("upload token is not ascii: " + encodedToken, StringUtils.isAsciiPrintable(encodedToken)); // also check token can be parsed and is valid DataRecordUploadToken parsedToken = DataRecordUploadToken.fromEncodedToken(encodedToken, SECRET); assertEquals(BLOB_ID, parsedToken.getBlobId()); assertTrue(parsedToken.getUploadId().isPresent()); assertEquals(UPLOAD_ID, parsedToken.getUploadId().get()); } }