Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object StringDecoders {
* @param improvedNullDetection if true, return null if all bytes are zero
* @return A string representation of the binary data
*/
def decodeEbcdicString(bytes: Array[Byte], trimmingType: Int, conversionTable: Array[Char], improvedNullDetection: Boolean): String = {
final def decodeEbcdicString(bytes: Array[Byte], trimmingType: Int, conversionTable: Array[Char], improvedNullDetection: Boolean): String = {
if (improvedNullDetection && isArrayNull(bytes))
return null

Expand Down Expand Up @@ -73,7 +73,7 @@ object StringDecoders {
* @param improvedNullDetection if true, return null if all bytes are zero
* @return A string representation of the binary data
*/
def decodeAsciiString(bytes: Array[Byte], trimmingType: Int, improvedNullDetection: Boolean): String = {
final def decodeAsciiString(bytes: Array[Byte], trimmingType: Int, improvedNullDetection: Boolean): String = {
if (improvedNullDetection && isArrayNull(bytes))
return null

Expand Down Expand Up @@ -105,7 +105,7 @@ object StringDecoders {
* @param improvedNullDetection if true, return null if all bytes are zero
* @return A string representation of the binary data
*/
def decodeUtf16String(bytes: Array[Byte], trimmingType: Int, isUtf16BigEndian: Boolean, improvedNullDetection: Boolean): String = {
final def decodeUtf16String(bytes: Array[Byte], trimmingType: Int, isUtf16BigEndian: Boolean, improvedNullDetection: Boolean): String = {
if (improvedNullDetection && isArrayNull(bytes))
return null

Expand All @@ -132,7 +132,7 @@ object StringDecoders {
* @param bytes A byte array that represents the binary data
* @return A HEX string representation of the binary data
*/
def decodeHex(bytes: Array[Byte]): String = {
final def decodeHex(bytes: Array[Byte]): String = {
val hexChars = new Array[Char](bytes.length * 2)
var i = 0
while (i < bytes.length) {
Expand All @@ -150,7 +150,7 @@ object StringDecoders {
* @param bytes A byte array that represents the binary data
* @return A string representation of the bytes
*/
def decodeRaw(bytes: Array[Byte]): Array[Byte] = bytes
final def decodeRaw(bytes: Array[Byte]): Array[Byte] = bytes

/**
* A decoder for any EBCDIC uncompressed numbers supporting
Expand All @@ -165,7 +165,7 @@ object StringDecoders {
* @param improvedNullDetection if true, return null if all bytes are zero
* @return A string representation of the binary data
*/
def decodeEbcdicNumber(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): String = {
final def decodeEbcdicNumber(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): String = {
if (improvedNullDetection && isArrayNull(bytes))
return null

Expand Down Expand Up @@ -236,7 +236,8 @@ object StringDecoders {
* @param improvedNullDetection if true, return null if all bytes are zero
* @return A string representation of the binary data
*/
def decodeAsciiNumber(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): String = {
final def decodeAsciiNumber(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): String = {
val allowedDigitChars = " 0123456789"
if (improvedNullDetection && isArrayNull(bytes))
return null

Expand All @@ -251,7 +252,10 @@ object StringDecoders {
if (char == '.' || char == ',') {
buf.append('.')
} else {
buf.append(char)
if (allowedDigitChars.contains(char))
buf.append(char)
else
return null
}
}
i = i + 1
Expand All @@ -269,7 +273,7 @@ object StringDecoders {
* @param bytes A byte array that represents the binary data
* @return A boxed integer
*/
def decodeEbcdicInt(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): Integer = {
final def decodeEbcdicInt(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): Integer = {
try {
decodeEbcdicNumber(bytes, isUnsigned, improvedNullDetection).toInt
} catch {
Expand All @@ -283,7 +287,7 @@ object StringDecoders {
* @param bytes A byte array that represents the binary data
* @return A boxed integer
*/
def decodeAsciiInt(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): Integer = {
final def decodeAsciiInt(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): Integer = {
try {
decodeAsciiNumber(bytes, isUnsigned, improvedNullDetection).toInt
} catch {
Expand All @@ -297,7 +301,7 @@ object StringDecoders {
* @param bytes A byte array that represents the binary data
* @return A boxed long
*/
def decodeEbcdicLong(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): java.lang.Long = {
final def decodeEbcdicLong(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): java.lang.Long = {
try {
decodeEbcdicNumber(bytes, isUnsigned, improvedNullDetection).toLong
} catch {
Expand All @@ -311,7 +315,7 @@ object StringDecoders {
* @param bytes A byte array that represents the binary data
* @return A boxed long
*/
def decodeAsciiLong(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): java.lang.Long = {
final def decodeAsciiLong(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): java.lang.Long = {
try {
decodeAsciiNumber(bytes, isUnsigned, improvedNullDetection).toLong
} catch {
Expand All @@ -327,7 +331,7 @@ object StringDecoders {
* @param scaleFactor Additional zeros to be added before of after the decimal point
* @return A big decimal containing a big integral number
*/
def decodeEbcdicBigNumber(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean, scale: Int = 0, scaleFactor: Int = 0): BigDecimal = {
final def decodeEbcdicBigNumber(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean, scale: Int = 0, scaleFactor: Int = 0): BigDecimal = {
try {
BigDecimal(BinaryUtils.addDecimalPoint(decodeEbcdicNumber(bytes, isUnsigned, improvedNullDetection), scale, scaleFactor))
} catch {
Expand All @@ -343,7 +347,7 @@ object StringDecoders {
* @param scaleFactor Additional zeros to be added before of after the decimal point
* @return A big decimal containing a big integral number
*/
def decodeAsciiBigNumber(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean, scale: Int = 0, scaleFactor: Int = 0): BigDecimal = {
final def decodeAsciiBigNumber(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean, scale: Int = 0, scaleFactor: Int = 0): BigDecimal = {
try {
BigDecimal(BinaryUtils.addDecimalPoint(decodeAsciiNumber(bytes, isUnsigned, improvedNullDetection), scale, scaleFactor))
} catch {
Expand All @@ -358,7 +362,7 @@ object StringDecoders {
* @param bytes A byte array that represents the binary data
* @return A big decimal containing a big integral number
*/
def decodeEbcdicBigDecimal(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): BigDecimal = {
final def decodeEbcdicBigDecimal(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): BigDecimal = {
try {
BigDecimal(decodeEbcdicNumber(bytes, isUnsigned, improvedNullDetection))
} catch {
Expand All @@ -373,7 +377,7 @@ object StringDecoders {
* @param bytes A byte array that represents the binary data
* @return A big decimal containing a big integral number
*/
def decodeAsciiBigDecimal(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): BigDecimal = {
final def decodeAsciiBigDecimal(bytes: Array[Byte], isUnsigned: Boolean, improvedNullDetection: Boolean): BigDecimal = {
try {
BigDecimal(decodeAsciiNumber(bytes, isUnsigned, improvedNullDetection))
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object StringTools {
* @param s A string
* @return The trimmed string
*/
def trimLeft(s: String): String = {
final def trimLeft(s: String): String = {
val len = s.length
var st = 0
val v = s.toCharArray
Expand All @@ -46,7 +46,7 @@ object StringTools {
* @param s A string
* @return The trimmed string
*/
def trimRight(s: String): String = {
final def trimRight(s: String): String = {
var len = s.length
val st = 0
val v = s.toCharArray
Expand All @@ -60,7 +60,7 @@ object StringTools {
else s
}

def isArrayNull(bytes: Array[Byte]): Boolean = {
final def isArrayNull(bytes: Array[Byte]): Boolean = {
var i = 0
val size = bytes.length
while (i < size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ class StringDecodersSpec extends WordSpec {
assert(decodeAsciiNumber("100,00-".getBytes, isUnsigned = false, improvedNullDetection = false) == "-100.00")
}

"return trimmed string if non-digit characters are encountered" in {
assert(decodeAsciiNumber("AAABBBCCC".getBytes, isUnsigned = false, improvedNullDetection = false) == "AAABBBCCC")
"return null if non-digit characters are encountered" in {
assert(decodeAsciiNumber("AAABBBCCC".getBytes, isUnsigned = false, improvedNullDetection = false) == null)
}
}

Expand Down Expand Up @@ -458,8 +458,8 @@ class StringDecodersSpec extends WordSpec {
assert(decodeAsciiBigDecimal("12345678901234567890123456.12345678901234567890123456".getBytes, isUnsigned = true, improvedNullDetection = false) == BigDecimal("12345678901234567890123456.12345678901234567890123456"))
}

"decode numbers in scientific format" in {
assert(decodeAsciiBigDecimal("200E+10".getBytes, isUnsigned = false, improvedNullDetection = false) == 2.00E+12)
"not decode numbers in scientific format" in {
assert(decodeAsciiBigDecimal("200E+10".getBytes, isUnsigned = false, improvedNullDetection = false) == null)
}

"return null for malformed numbers" in {
Expand Down
Loading