[Fix] StringHelper.replacePropertiesIn() allow empty string (non-null)

This commit is contained in:
Robert von Burg 2017-11-21 18:03:25 +01:00
parent 3e116b6b34
commit 332724439d
1 changed files with 139 additions and 120 deletions

View File

@ -52,9 +52,22 @@ public class StringHelper {
/**
* Hex char table for fast calculating of hex values
*/
private static final byte[] HEX_CHAR_TABLE = { (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4',
(byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd',
(byte) 'e', (byte) 'f' };
private static final byte[] HEX_CHAR_TABLE = { (byte) '0',
(byte) '1',
(byte) '2',
(byte) '3',
(byte) '4',
(byte) '5',
(byte) '6',
(byte) '7',
(byte) '8',
(byte) '9',
(byte) 'a',
(byte) 'b',
(byte) 'c',
(byte) 'd',
(byte) 'e',
(byte) 'f' };
public static String toHexString(byte data) {
return String.format("%02x", data);
@ -80,7 +93,8 @@ public class StringHelper {
return new String(hex, "ASCII"); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) {
String msg = MessageFormat.format("Something went wrong while converting to HEX: {0}", e.getMessage()); //$NON-NLS-1$
String msg = MessageFormat
.format("Something went wrong while converting to HEX: {0}", e.getMessage()); //$NON-NLS-1$
throw new RuntimeException(msg, e);
}
}
@ -138,7 +152,8 @@ public class StringHelper {
return new String(hex, "ASCII"); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) {
String msg = MessageFormat.format("Something went wrong while converting to HEX: {0}", e.getMessage()); //$NON-NLS-1$
String msg = MessageFormat
.format("Something went wrong while converting to HEX: {0}", e.getMessage()); //$NON-NLS-1$
throw new RuntimeException(msg, e);
}
}
@ -375,6 +390,7 @@ public class StringHelper {
* add at beginning of value
* @param c
* char to append when appending
*
* @return the new string
*/
public static String normalizeLength(String value, int length, boolean beginning, char c) {
@ -395,6 +411,7 @@ public class StringHelper {
* allow shortening of value
* @param c
* char to append when appending
*
* @return the new string
*/
public static String normalizeLength(String value, int length, boolean beginning, boolean shorten, char c) {
@ -486,7 +503,8 @@ public class StringHelper {
// if no stop found, then break as another sequence should be able to start
if (stop == -1) {
logger.error(MessageFormat.format("Sequence starts at offset {0} but does not end!", pos)); //$NON-NLS-1$
logger.error(
MessageFormat.format("Sequence starts at offset {0} but does not end!", pos)); //$NON-NLS-1$
tmpValue = value;
break;
}
@ -505,10 +523,10 @@ public class StringHelper {
}
// sequence is good, so see if we have a property for it
String property = properties.getProperty(sequence, StringHelper.EMPTY);
String property = properties.getProperty(sequence);
// if no property exists, then log and continue
if (property.isEmpty()) {
if (property == null) {
pos = stop;
// logger.warn("No system property found for sequence " + sequence);
continue;
@ -709,7 +727,8 @@ public class StringHelper {
*/
public static boolean parseBoolean(String value) throws RuntimeException {
if (isEmpty(value))
throw new RuntimeException("Value to parse to boolean is empty! Expected case insensitive true or false"); //$NON-NLS-1$
throw new RuntimeException(
"Value to parse to boolean is empty! Expected case insensitive true or false"); //$NON-NLS-1$
String tmp = value.toLowerCase();
if (tmp.equals(Boolean.TRUE.toString())) {
return true;