-1

I am trying url decoding on input data. Few records are decoded fine, but when i tried this on larger data it is giving error. I tried exception handling to discard error data, but getting same error again and again.

val decodedVal = convertedVal22.map(s => doWork(s))

def doWork(param : String) : String = 
{

   var x9 = ""
   try {
     var y = java.net.URLDecoder.decode(param, "UTF-8")
     x9 = y
    }

    return x9
}

Error:

URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "%2"

1 Answers1

0

Run Time exception is required to in catch block.

def doWork(param : String) : String = {
var x9 = ""
try {
    var y = java.net.URLDecoder.decode(param, "UTF-8")
    x9 = y
    return x9
}
catch {   

            case runtime: RuntimeException => 
            {
                ""
            }
}

and that filter it with nonEmpty.

 val decodedVal = convertedVal22.map(s => doWork(s)).filter(_.nonEmpty)