[Fix] StringHelper.replacePropertiesIn() allow empty string (non-null)
This commit is contained in:
parent
3e116b6b34
commit
332724439d
|
@ -52,9 +52,22 @@ public class StringHelper {
|
||||||
/**
|
/**
|
||||||
* Hex char table for fast calculating of hex values
|
* 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',
|
private static final byte[] HEX_CHAR_TABLE = { (byte) '0',
|
||||||
(byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd',
|
(byte) '1',
|
||||||
(byte) 'e', (byte) 'f' };
|
(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) {
|
public static String toHexString(byte data) {
|
||||||
return String.format("%02x", data);
|
return String.format("%02x", data);
|
||||||
|
@ -80,7 +93,8 @@ public class StringHelper {
|
||||||
return new String(hex, "ASCII"); //$NON-NLS-1$
|
return new String(hex, "ASCII"); //$NON-NLS-1$
|
||||||
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
} 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);
|
throw new RuntimeException(msg, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +152,8 @@ public class StringHelper {
|
||||||
return new String(hex, "ASCII"); //$NON-NLS-1$
|
return new String(hex, "ASCII"); //$NON-NLS-1$
|
||||||
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
} 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);
|
throw new RuntimeException(msg, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -375,6 +390,7 @@ public class StringHelper {
|
||||||
* add at beginning of value
|
* add at beginning of value
|
||||||
* @param c
|
* @param c
|
||||||
* char to append when appending
|
* char to append when appending
|
||||||
|
*
|
||||||
* @return the new string
|
* @return the new string
|
||||||
*/
|
*/
|
||||||
public static String normalizeLength(String value, int length, boolean beginning, char c) {
|
public static String normalizeLength(String value, int length, boolean beginning, char c) {
|
||||||
|
@ -395,6 +411,7 @@ public class StringHelper {
|
||||||
* allow shortening of value
|
* allow shortening of value
|
||||||
* @param c
|
* @param c
|
||||||
* char to append when appending
|
* char to append when appending
|
||||||
|
*
|
||||||
* @return the new string
|
* @return the new string
|
||||||
*/
|
*/
|
||||||
public static String normalizeLength(String value, int length, boolean beginning, boolean shorten, char c) {
|
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 no stop found, then break as another sequence should be able to start
|
||||||
if (stop == -1) {
|
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;
|
tmpValue = value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -505,10 +523,10 @@ public class StringHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
// sequence is good, so see if we have a property for it
|
// 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 no property exists, then log and continue
|
||||||
if (property.isEmpty()) {
|
if (property == null) {
|
||||||
pos = stop;
|
pos = stop;
|
||||||
// logger.warn("No system property found for sequence " + sequence);
|
// logger.warn("No system property found for sequence " + sequence);
|
||||||
continue;
|
continue;
|
||||||
|
@ -709,7 +727,8 @@ public class StringHelper {
|
||||||
*/
|
*/
|
||||||
public static boolean parseBoolean(String value) throws RuntimeException {
|
public static boolean parseBoolean(String value) throws RuntimeException {
|
||||||
if (isEmpty(value))
|
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();
|
String tmp = value.toLowerCase();
|
||||||
if (tmp.equals(Boolean.TRUE.toString())) {
|
if (tmp.equals(Boolean.TRUE.toString())) {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue