Skip to content

net library : transformations #28

@sporniket

Description

@sporniket

Convert the following code into builtins mapper 👍

import static java.nio.charset.StandardCharsets.UTF_8 ;

import java.io.UnsupportedEncodingException ;
import java.net.URLDecoder ;
import java.net.URLEncoder ;
import java.util.Base64 ;

/**
 * @author spornda
 *
 */
public final class BuiltinsNetTransformations {

    public static final Function<String, byte[]> DECODE_BASE64 = t -> Base64.getDecoder().decode(t) ;

    public static final Function<String, String> DECODE_URL = t -> {
        if (null == t || "null".equals(t)) {
            return null ;
        }
        try {
            return URLDecoder.decode(t, UTF_8.name()) ;
        } catch (UnsupportedEncodingException e) {
            // Ça ne doit jamais arriver
            throw new IllegalStateException("The Character Encoding is not supported : " + t) ;
        }
    } ;

    public static final Function<byte[], String> ENCODE_BASE64 = t -> (null != t) ? Base64.getEncoder().encodeToString(t) : "" ;

    public static final Function<String, String> ENCODE_URL = t -> {
        if (t == null) {
            return t ;
        }
        try {
            return URLEncoder.encode(t, UTF_8.name()) ;
        } catch (UnsupportedEncodingException e) {
            // Ça ne doit jamais arriver
            throw new IllegalStateException("The Character Encoding is not supported : " + t) ;
        }

    } ;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions