protected def reduce()

in daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/XSHexBinary.scala [28:52]


  protected def reduce(numeric: Any): Array[Byte] = {
    val res: Array[Byte] = numeric match {
      case b: Byte => HexBinaryConversions.toByteArray(b)
      //
      // Note -128 to 255 are converted to bytes. This means signed or unsigned bytes
      // will stay at size 1 byte. This prevents bytes like 0xD0 from turning
      // into 00D0 and occupying 4 characters instead of two.
      //
      case s: Short if (s <= 255 && s >= Byte.MinValue) => reduce(s.toByte)
      case s: Short => HexBinaryConversions.toByteArray(s)
      case i: Int if (i <= Short.MaxValue && i >= Short.MinValue) => reduce(i.toShort)
      case i: Int => HexBinaryConversions.toByteArray(i)
      case l: Long if (l <= Int.MaxValue && l >= Int.MinValue) => reduce(l.toInt)
      case l: Long => HexBinaryConversions.toByteArray(l)
      case bi: JBigInt if (bi.bitLength <= 63) => reduce(bi.longValue())
      case bi: JBigInt => bi.toByteArray()
      case bd: JBigDecimal if (try { bd.toBigIntegerExact(); true }
          catch { case e: ArithmeticException => false }) =>
        reduce(bd.toBigIntegerExact())
      case str: String => Misc.hex2Bytes(str)
      case _ =>
        throw new NumberFormatException("%s could not fit into a long".format(numeric.toString))
    }
    res
  }