private static List<String> trim(String[] strings) { List<String> result = new ArrayList<>(); for (String s : strings) { result.add(StringUtils.trim(s)); } return result; }
/** * @see org.sonar.api.server.ws.WebService.NewAction#setResponseExample(java.net.URL) */ @CheckForNull public String responseExampleAsString() { try { if (responseExample != null) { return StringUtils.trim(IOUtils.toString(responseExample, StandardCharsets.UTF_8)); } return null; } catch (IOException e) { throw new IllegalStateException("Fail to load " + responseExample, e); } }
Key loadSecretFileFromFile(@Nullable String path) throws IOException { if (StringUtils.isBlank(path)) { throw new IllegalStateException("Secret key not found. Please set the property " + CoreProperties.ENCRYPTION_SECRET_KEY_PATH); } File file = new File(path); if (!file.exists() || !file.isFile()) { throw new IllegalStateException("The property " + CoreProperties.ENCRYPTION_SECRET_KEY_PATH + " does not link to a valid file: " + path); } String s = FileUtils.readFileToString(file, UTF_8); if (StringUtils.isBlank(s)) { throw new IllegalStateException("No secret key in the file: " + path); } return new SecretKeySpec(Base64.decodeBase64(StringUtils.trim(s)), CRYPTO_KEY); }
Key loadSecretFileFromFile(String path) throws IOException { if (StringUtils.isBlank(path)) { throw new IllegalStateException("Secret key not found. Please set the property " + ENCRYPTION_SECRET_KEY_PATH); } File file = new File(path); if (!file.exists() || !file.isFile()) { throw new IllegalStateException("The property " + ENCRYPTION_SECRET_KEY_PATH + " does not link to a valid file: " + path); } String s = FileUtils.readFileToString(file, UTF_8); if (StringUtils.isBlank(s)) { throw new IllegalStateException("No secret key in the file: " + path); } return new SecretKeySpec(Base64.decodeBase64(StringUtils.trim(s)), CRYPTO_KEY); }
private static Charset initEncoding(ProjectDefinition module) { String encodingStr = module.properties().get(CoreProperties.ENCODING_PROPERTY); Charset result; if (StringUtils.isNotEmpty(encodingStr)) { result = Charset.forName(StringUtils.trim(encodingStr)); } else { result = Charset.defaultCharset(); } return result; }
protected static Map<String, String> unmodifiableMapWithTrimmedValues(PropertyDefinitions definitions, Map<String, String> props) { Map<String, String> map = new HashMap<>(props.size()); props.forEach((k, v) -> { String validKey = definitions.validKey(k); map.put(validKey, trim(v)); }); return Collections.unmodifiableMap(map); }
@Override public String decrypt(String encryptedText) { try { javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY); cipher.init(javax.crypto.Cipher.DECRYPT_MODE, loadSecretFile()); byte[] cipherData = cipher.doFinal(Base64.decodeBase64(StringUtils.trim(encryptedText))); return new String(cipherData, UTF_8); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalStateException(e); } }
@Override public String decrypt(String encryptedText) { try { javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY); cipher.init(javax.crypto.Cipher.DECRYPT_MODE, loadSecretFile()); byte[] cipherData = cipher.doFinal(Base64.decodeBase64(StringUtils.trim(encryptedText))); return new String(cipherData, StandardCharsets.UTF_8); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalStateException(e); } }
public DefaultIssue setMessage(@Nullable String s) { this.message = StringUtils.abbreviate(StringUtils.trim(s), MESSAGE_MAX_SIZE); return this; }
private static String nodeValue(SMInputCursor cursor) throws XMLStreamException { return trim(cursor.collectDescendantText(false)); }
static String formatNumeric(long value) { if (value == 0) { return ZERO; } NumberFormat numericFormatter = DecimalFormat.getInstance(Locale.ENGLISH); numericFormatter.setMaximumFractionDigits(1); int power = (int) StrictMath.log10(value); double valueToFormat = value / (Math.pow(10, Math.floorDiv(power, 3) * 3d)); String formattedNumber = numericFormatter.format(valueToFormat); formattedNumber = formattedNumber + NUMERIC_SUFFIX_LIST.charAt(power / 3); return formattedNumber.length() > 4 ? trim(formattedNumber.replaceAll(NUMERIC_REGEXP, "")) : trim(formattedNumber); }
public Settings appendProperty(String key, @Nullable String value) { Optional<String> existingValue = getRawString(definitions.validKey(key)); String newValue; if (!existingValue.isPresent()) { newValue = trim(value); } else { newValue = existingValue.get() + "," + trim(value); } return setProperty(key, newValue); }
@Override public DefaultIssueLocation message(String message) { requireNonNull(message, "Message can't be null"); if (message.contains("\u0000")) { throw new IllegalArgumentException(unsupportedCharacterError(message, component)); } this.message = abbreviate(trim(message), MESSAGE_MAX_SIZE); return this; }
Issue(@Nullable Integer line, String lineHash, RuleKey ruleKey, String message, String status, Date creationDate) { this.line = line; this.lineHash = lineHash; this.ruleKey = ruleKey; this.status = status; this.creationDate = creationDate; this.message = trim(message); }
@Override public String getMessage() { return dto.hasMsg() ? trim(dto.getMsg()) : ""; }
@Override public String[] getStringArray(String key) { String value = getString(key); if (value != null) { String[] strings = StringUtils.splitByWholeSeparator(value, ","); String[] result = new String[strings.length]; for (int index = 0; index < strings.length; index++) { result[index] = StringUtils.trim(strings[index]); } return result; } return ArrayUtils.EMPTY_STRING_ARRAY; } }
protected static Properties toProperties(File propertyFile) { Properties propsFromFile = new Properties(); try (FileInputStream fileInputStream = new FileInputStream(propertyFile)) { propsFromFile.load(fileInputStream); } catch (IOException e) { throw new IllegalStateException("Impossible to read the property file: " + propertyFile.getAbsolutePath(), e); } // Trim properties for (String propKey : propsFromFile.stringPropertyNames()) { propsFromFile.setProperty(propKey, StringUtils.trim(propsFromFile.getProperty(propKey))); } return propsFromFile; }
public static PathPattern create(String s) { String trimmed = StringUtils.trim(s); if (StringUtils.startsWithIgnoreCase(trimmed, ABSOLUTE_PATH_PATTERN_PREFIX)) { LOG.warn("Using absolute path pattern is deprecated. Please use relative path instead of '" + trimmed + "'"); return new AbsolutePathPattern(StringUtils.substring(trimmed, ABSOLUTE_PATH_PATTERN_PREFIX.length())); } return new RelativePathPattern(trimmed); }
@Test public void response_example() { MetricWs metricWs = new MetricWs(); metricWs.define(context); WebService.Action action = context.controller("api/metric").action("create"); assertThat(action.responseExampleFormat()).isEqualTo("txt"); assertThat(action.responseExample()).isNotNull(); assertThat(StringUtils.trim(action.responseExampleAsString())).isEqualTo("example of WS response"); }