旺阳
2 years ago
committed by
zhuangchong
5 changed files with 142 additions and 34 deletions
@ -0,0 +1,58 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.apache.dolphinscheduler.data.quality.utils; |
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8; |
||||
|
||||
import java.net.URLDecoder; |
||||
import java.net.URLEncoder; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
/** |
||||
* ParserUtil |
||||
*/ |
||||
@Slf4j |
||||
public class ParserUtils { |
||||
|
||||
private ParserUtils() { |
||||
throw new UnsupportedOperationException("Construct ParserUtils"); |
||||
} |
||||
|
||||
public static String encode(String str) { |
||||
String rs = str; |
||||
try { |
||||
rs = URLEncoder.encode(str, UTF_8.toString()); |
||||
} catch (Exception e) { |
||||
log.error("encode str exception!", e); |
||||
} |
||||
|
||||
return rs; |
||||
} |
||||
|
||||
public static String decode(String str) { |
||||
String rs = str; |
||||
try { |
||||
rs = URLDecoder.decode(str, UTF_8.toString()); |
||||
} catch (Exception e) { |
||||
log.error("decode str exception!", e); |
||||
} |
||||
|
||||
return rs; |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.apache.dolphinscheduler.data.quality.utils; |
||||
|
||||
import org.junit.jupiter.api.Assertions; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
public class ParserUtilsTest { |
||||
|
||||
@Test |
||||
public void testParserUtils() { |
||||
String testStr = "aaa$bbb$ccc%ddd^eee#fff"; |
||||
String encode = ParserUtils.encode(testStr); |
||||
String decode = ParserUtils.decode(encode); |
||||
Assertions.assertEquals(testStr, decode); |
||||
|
||||
String blank = ""; |
||||
Assertions.assertEquals(ParserUtils.encode(blank), blank); |
||||
Assertions.assertEquals(ParserUtils.decode(blank), blank); |
||||
|
||||
Assertions.assertNull(ParserUtils.encode(null)); |
||||
Assertions.assertNull(ParserUtils.decode(null)); |
||||
} |
||||
} |
Loading…
Reference in new issue