[#noissue] cleanup charset

This commit is contained in:
emeroad
2017-04-25 13:18:52 +09:00
committed by Woonduk Kang
parent 244969eaa7
commit 36b1d437e0
29 changed files with 109 additions and 48 deletions
@@ -30,6 +30,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -44,7 +45,7 @@ import java.util.concurrent.ThreadFactory;
*/
public class ZookeeperJobWorker implements Runnable {
private static final Charset charset = Charset.forName("UTF-8");
private static final Charset charset = StandardCharsets.UTF_8;
private static final String PINPOINT_CLUSTER_PATH = "/pinpoint-cluster";
private static final String PINPOINT_COLLECTOR_CLUSTER_PATH = PINPOINT_CLUSTER_PATH + "/collector";
@@ -17,6 +17,7 @@ package com.navercorp.pinpoint.common.hbase;
import java.nio.charset.Charset;
import com.navercorp.pinpoint.common.Charsets;
import org.apache.hadoop.conf.Configuration;
import org.springframework.util.StringUtils;
@@ -30,7 +31,7 @@ import org.springframework.util.StringUtils;
public abstract class HbaseAccessor {
private String encoding;
private static final Charset CHARSET = Charset.forName("UTF-8");
private static final Charset CHARSET = Charsets.UTF_8;
private TableFactory tableFactory;
private Configuration configuration;
@@ -16,6 +16,7 @@
package com.navercorp.pinpoint.common.server.bo.codec.stat.strategy;
import com.navercorp.pinpoint.common.Charsets;
import com.navercorp.pinpoint.common.buffer.Buffer;
import com.navercorp.pinpoint.common.server.bo.codec.StringTypedBufferHandler;
import com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy;
@@ -24,7 +25,6 @@ import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.StringRepeatC
import com.navercorp.pinpoint.common.server.bo.codec.strategy.impl.StringValueEncodingStrategy;
import com.navercorp.pinpoint.common.util.BytesUtils;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -90,7 +90,7 @@ public enum StringEncodingStrategy implements EncodingStrategy<String> {
public static class Builder implements StrategyAnalyzerBuilder<String> {
private static final int MAX_BYTES_PER_CHAR_UTF8 = (int) Charset.forName("UTF-8").newEncoder().maxBytesPerChar();
private static final int MAX_BYTES_PER_CHAR_UTF8 = (int) Charsets.UTF_8.newEncoder().maxBytesPerChar();
private final List<String> values = new ArrayList<String>();
@@ -0,0 +1,35 @@
/*
* Copyright 2017 NAVER Corp.
*
* Licensed 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 com.navercorp.pinpoint.common;
import java.nio.charset.Charset;
/**
* @author Woonduk Kang(emeroad)
*/
public final class Charsets {
private Charsets() {
}
public static final Charset US_ASCII = Charset.forName("US-ASCII");
public static final String US_ASCII_NAME = US_ASCII.name();
public static final Charset UTF_8 = Charset.forName("UTF-8");
public static final String UTF_8_NAME = UTF_8.name();
}
@@ -16,6 +16,8 @@
package com.navercorp.pinpoint.common.buffer;
import com.navercorp.pinpoint.common.Charsets;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
@@ -29,9 +31,9 @@ public interface Buffer {
byte[] EMPTY = new byte[0];
String UTF8 = "UTF-8";
String UTF8 = Charsets.UTF_8_NAME;
Charset UTF8_CHARSET = Charset.forName(UTF8);
Charset UTF8_CHARSET = Charsets.UTF_8;
void putPadBytes(byte[] bytes, int totalLength);
@@ -17,6 +17,8 @@
package com.navercorp.pinpoint.common.util;
import com.navercorp.pinpoint.common.Charsets;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
@@ -33,8 +35,9 @@ public final class BytesUtils {
public static final int VINT_MAX_SIZE = 5;
private static final byte[] EMPTY_BYTES = new byte[0];
private static final String UTF8 = "UTF-8";
private static final Charset UTF8_CHARSET = Charset.forName(UTF8);
private static final Charset UTF8_CHARSET = Charsets.UTF_8;
private static final String UTF8 = Charsets.UTF_8_NAME;
private BytesUtils() {
}
@@ -538,9 +541,9 @@ public final class BytesUtils {
return null;
}
try {
return value.getBytes(UTF8);
return value.getBytes(Charsets.UTF_8_NAME);
} catch (UnsupportedEncodingException e) {
return value.getBytes(UTF8_CHARSET);
return value.getBytes(Charsets.UTF_8);
}
}
@@ -16,12 +16,14 @@
package com.navercorp.pinpoint.common.util;
import com.navercorp.pinpoint.common.Charsets;
/**
* @author emeroad
*/
public final class HttpUtils {
private static final String UTF8 = "UTF-8";
private static final String UTF8 = Charsets.UTF_8_NAME;
private static final String CHARSET = "charset=";
@@ -16,6 +16,8 @@
package com.navercorp.pinpoint.common.util;
import com.navercorp.pinpoint.common.Charsets;
import java.io.*;
import java.util.Properties;
@@ -23,7 +25,7 @@ import java.util.Properties;
* @author emeroad
*/
public final class PropertyUtils {
public static final String DEFAULT_ENCODING = "UTF-8";
public static final String DEFAULT_ENCODING = Charsets.UTF_8_NAME;
private static final ClassLoaderUtils.ClassLoaderCallable CLASS_LOADER_CALLABLE = new ClassLoaderUtils.ClassLoaderCallable() {
@Override
@@ -16,6 +16,7 @@
package com.navercorp.pinpoint.common.buffer;
import com.navercorp.pinpoint.common.Charsets;
import com.navercorp.pinpoint.common.util.BytesUtils;
import org.apache.commons.lang3.StringUtils;
@@ -109,9 +110,9 @@ public class AutomaticBufferTest {
Assert.assertEquals("check data", test, trimString);
String padString = new String(result, TOTAL_LENGTH - TEST_SIZE, PAD_SIZE, "UTF-8");
String padString = new String(result, TOTAL_LENGTH - TEST_SIZE, PAD_SIZE, Charsets.UTF_8);
byte[] padBytes = new byte[TOTAL_LENGTH - TEST_SIZE];
org.junit.Assert.assertEquals("check pad", padString, new String(padBytes, Charset.forName("UTF-8")));
org.junit.Assert.assertEquals("check pad", padString, new String(padBytes, Charsets.UTF_8));
}
@@ -17,6 +17,7 @@
package com.navercorp.pinpoint.common.buffer;
import com.google.common.primitives.Ints;
import com.navercorp.pinpoint.common.Charsets;
import com.navercorp.pinpoint.common.util.BytesUtils;
import org.apache.commons.lang3.StringUtils;
@@ -34,7 +35,7 @@ import java.util.Random;
* @author emeroad
*/
public class FixedBufferTest {
public static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
public static final Charset UTF8_CHARSET = Charsets.UTF_8;
private Logger logger = LoggerFactory.getLogger(this.getClass());
private Random random = new Random();
@@ -141,9 +142,9 @@ public class FixedBufferTest {
Assert.assertEquals("check data", test, trimString);
String padString = new String(result, TOTAL_LENGTH - TEST_SIZE, PAD_SIZE, "UTF-8");
String padString = new String(result, TOTAL_LENGTH - TEST_SIZE, PAD_SIZE, UTF8_CHARSET.name());
byte[] padBytes = new byte[TOTAL_LENGTH - TEST_SIZE];
Assert.assertEquals("check pad", padString, new String(padBytes, Charset.forName("UTF-8")));
Assert.assertEquals("check pad", padString, new String(padBytes, UTF8_CHARSET));
}
@@ -16,11 +16,11 @@
package com.navercorp.pinpoint.common.util;
import com.navercorp.pinpoint.common.Charsets;
import org.junit.Assert;
import org.junit.Test;
import com.navercorp.pinpoint.common.util.HttpUtils;
public class HttpUtilsTest {
@Test
@@ -28,7 +28,7 @@ public class HttpUtilsTest {
String test = "text/plain; charset=UTF-8";
String charset = HttpUtils.parseContentTypeCharset(test);
Assert.assertEquals("UTF-8", charset);
Assert.assertEquals(Charsets.UTF_8.name(), charset);
}
@Test
@@ -36,7 +36,7 @@ public class HttpUtilsTest {
String test = "text/plain; charset=UTF-8;";
String charset = HttpUtils.parseContentTypeCharset(test);
Assert.assertEquals("UTF-8", charset);
Assert.assertEquals(Charsets.UTF_8.name(), charset);
}
@Test
@@ -44,7 +44,7 @@ public class HttpUtilsTest {
String test = "text/plain; charset=UTF-8; test=a";
String charset = HttpUtils.parseContentTypeCharset(test);
Assert.assertEquals("UTF-8", charset);
Assert.assertEquals(Charsets.UTF_8.name(), charset);
}
@Test
@@ -52,7 +52,7 @@ public class HttpUtilsTest {
String test = "text/plain; charset= UTF-8 ; test=a";
String charset = HttpUtils.parseContentTypeCharset(test);
Assert.assertEquals("UTF-8", charset);
Assert.assertEquals(Charsets.UTF_8.name(), charset);
}
}
@@ -18,6 +18,7 @@ package com.navercorp.pinpoint.plugin.httpclient4.interceptor;
import java.io.IOException;
import com.navercorp.pinpoint.common.Charsets;
import com.navercorp.pinpoint.common.util.StringUtils;
import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity;
@@ -298,7 +299,7 @@ public class DefaultClientExchangeHandlerImplStartMethodInterceptor implements A
final HttpEntity entity = entityRequest.getEntity();
if (entity != null && entity.isRepeatable() && entity.getContentLength() > 0) {
if (entitySampler.isSampling()) {
final String entityString = entityUtilsToString(entity, "UTF8", 1024);
final String entityString = entityUtilsToString(entity, Charsets.UTF_8_NAME, 1024);
recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, entityString);
}
}
@@ -20,6 +20,7 @@ import java.io.IOException;
import com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScope;
import com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation;
import com.navercorp.pinpoint.common.Charsets;
import com.navercorp.pinpoint.common.util.StringUtils;
import com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext;
import com.navercorp.pinpoint.plugin.httpclient4.HttpCallContextFactory;
@@ -317,7 +318,7 @@ public class HttpRequestExecutorExecuteMethodInterceptor implements AroundInterc
final HttpEntity entity = entityRequest.getEntity();
if (entity != null && entity.isRepeatable() && entity.getContentLength() > 0) {
if (entitySampler.isSampling()) {
final String entityString = entityUtilsToString(entity, "UTF8", 1024);
final String entityString = entityUtilsToString(entity, Charsets.UTF_8_NAME, 1024);
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, entityString);
}
@@ -21,6 +21,7 @@ import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.EnumMap;
import com.navercorp.pinpoint.common.Charsets;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TField;
import org.apache.thrift.protocol.TProtocol;
@@ -214,7 +215,7 @@ public class ThriftRequestProperty {
}
}
private static final Charset HEADER_CHARSET_ENCODING = Charset.forName("UTF-8");
private static final Charset HEADER_CHARSET_ENCODING = Charsets.UTF_8;
private static ByteBuffer stringToByteBuffer(String s) {
return ByteBuffer.wrap(s.getBytes(HEADER_CHARSET_ENCODING));
@@ -24,6 +24,7 @@ import com.navercorp.pinpoint.bootstrap.AgentOption;
import com.navercorp.pinpoint.bootstrap.DefaultAgentOption;
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
import com.navercorp.pinpoint.common.Charsets;
import com.navercorp.pinpoint.common.service.DefaultAnnotationKeyRegistryService;
import com.navercorp.pinpoint.common.service.DefaultServiceTypeRegistryService;
import com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext;
@@ -92,7 +93,7 @@ public class DependencyGraph {
public class Grapher {
public void graph(String filename, Injector demoInjector) throws IOException {
PrintWriter out = new PrintWriter(new File(filename), "UTF-8");
PrintWriter out = new PrintWriter(new File(filename), Charsets.UTF_8.name());
Injector injector = Guice.createInjector(new GraphvizModule());
GraphvizGrapher grapher = injector.getInstance(GraphvizGrapher.class);
@@ -20,6 +20,7 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.grapher.graphviz.GraphvizGrapher;
import com.google.inject.grapher.graphviz.GraphvizModule;
import com.navercorp.pinpoint.common.Charsets;
import java.io.File;
import java.io.IOException;
@@ -31,7 +32,7 @@ import java.io.PrintWriter;
public class Grapher {
public void graph(String filename, Injector demoInjector) throws IOException {
PrintWriter out = new PrintWriter(new File(filename), "UTF-8");
PrintWriter out = new PrintWriter(new File(filename), Charsets.UTF_8_NAME);
Injector injector = Guice.createInjector(new GraphvizModule());
GraphvizGrapher grapher = injector.getInstance(GraphvizGrapher.class);
@@ -16,6 +16,8 @@
package com.navercorp.pinpoint.rpc.control;
import com.navercorp.pinpoint.common.Charsets;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.ArrayList;
@@ -31,7 +33,7 @@ public class ControlMessageDecoder {
private Charset charset;
public ControlMessageDecoder() {
this.charset = Charset.forName("UTF-8");
this.charset = Charsets.UTF_8;
}
public Object decode(byte[] in) throws ProtocolException {
@@ -23,6 +23,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import com.navercorp.pinpoint.common.Charsets;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
@@ -38,7 +39,7 @@ public class ControlMessageEncoder {
private Charset charset;
public ControlMessageEncoder() {
this.charset = Charset.forName("UTF-8");
this.charset = Charsets.UTF_8;
}
public byte[] encode(Map<String, Object> value) throws ProtocolException {
@@ -18,6 +18,7 @@ import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import com.navercorp.pinpoint.common.Charsets;
import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
@@ -30,11 +31,11 @@ import static com.navercorp.pinpoint.test.plugin.PinpointPluginTestConstants.*;
*
*/
public class PinpointPluginTestRunListener extends RunListener {
public static final String UTF_8 = "UTF-8";
public static final String DEFAULT_ENCODING = Charsets.UTF_8_NAME;
private final PrintStream out;
public PinpointPluginTestRunListener(OutputStream out) {
this(out, UTF_8);
this(out, DEFAULT_ENCODING);
}
public PinpointPluginTestRunListener(OutputStream out, String encoding) {
try {
@@ -15,6 +15,8 @@
package com.navercorp.pinpoint.test.plugin;
import static com.navercorp.pinpoint.test.plugin.PinpointPluginTestConstants.CHILD_CLASS_PATH_PREFIX;
import com.navercorp.pinpoint.common.Charsets;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.DependencyResolutionException;
@@ -50,7 +52,7 @@ import java.util.Scanner;
* @author Taejin Koo
*/
public class PinpointPluginTestSuite extends AbstractPinpointPluginTestSuite {
private static final String DEFAULT_ENCODING = "UTF-8";
private static final String DEFAULT_ENCODING = Charsets.UTF_8_NAME;
private final boolean testOnSystemClassLoader;
private final boolean testOnChildClassLoader;
@@ -31,6 +31,7 @@ import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.List;
@@ -40,7 +41,7 @@ import java.util.List;
public class ClusterManager {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Charset charset = Charset.forName("UTF-8");
private final Charset charset = StandardCharsets.UTF_8;
private final WebConfig config;
@@ -17,6 +17,7 @@
package com.navercorp.pinpoint.web.cluster;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -28,7 +29,7 @@ import java.util.Map;
*/
public class CollectorClusterInfoRepository {
private static final Charset charset = Charset.forName("UTF-8");
private static final Charset charset = StandardCharsets.UTF_8;
private static final String PROFILER_SEPARATOR = "\r\n";
@@ -25,7 +25,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
@@ -34,7 +33,6 @@ import java.util.List;
*/
public class ClusterConnectionManager {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Charset charset = Charset.forName("UTF-8");
private final WebConfig config;
@@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.util.AntPathMatcher;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
@@ -33,7 +34,7 @@ import java.util.List;
*/
public class AcceptUrlFilter implements URLPatternFilter {
private static final Charset UTF8 = Charset.forName("UTF-8");
private static final Charset UTF8 = StandardCharsets.UTF_8;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final String urlPattern;
@@ -19,6 +19,7 @@ package com.navercorp.pinpoint.web.filter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@@ -87,7 +88,7 @@ public class DefaultFilterBuilder implements FilterBuilder {
return null;
}
try {
return URLDecoder.decode(value, "UTF-8");
return URLDecoder.decode(value, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("UTF8 decodeFail. value:" + value);
}
@@ -27,6 +27,7 @@ import org.apache.commons.codec.binary.Base64;
import org.springframework.util.AntPathMatcher;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
@@ -35,7 +36,7 @@ import java.util.List;
// TODO development class
public class RpcURLPatternFilter implements URLPatternFilter {
private static final Charset UTF8 = Charset.forName("UTF-8");
private static final Charset UTF8 = StandardCharsets.UTF_8;
private final String urlPattern;
private final AntPathMatcher matcher = new AntPathMatcher();
private final ServiceTypeRegistryService serviceTypeRegistryService;
@@ -29,6 +29,7 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
/**
* FIXME temporary interceptor for admin operations.
@@ -37,7 +38,7 @@ import java.nio.charset.Charset;
*/
public class AdminAuthInterceptor extends HandlerInterceptorAdapter {
private static final Charset UTF_8 = Charset.forName("UTF-8");
private static final Charset UTF_8 = StandardCharsets.UTF_8;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -42,6 +42,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.util.SocketUtils;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.List;
@@ -52,7 +53,7 @@ public class ClusterTest {
private static final Logger LOGGER = LoggerFactory.getLogger(ClusterTest.class);
private static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
private static final Charset UTF_8_CHARSET = StandardCharsets.UTF_8;
// some tests may fail when executed in local environment
// when failures happen, you have to copy pinpoint-web.properties of resource-test to resource-local. Tests will succeed.
@@ -21,14 +21,15 @@ import org.apache.hadoop.hbase.util.Base64;
import org.junit.Assert;
import org.junit.Test;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
/**
* @author emeroad
*/
public class AcceptUrlFilterTest {
private static final String UTF8 = "UTF8";
private static final Charset UTF8 = StandardCharsets.UTF_8;
@Test
public void acceptTest_1() {
@@ -51,11 +52,7 @@ public class AcceptUrlFilterTest {
}
private String encode(String value) {
try {
return Base64.encodeBytes(value.getBytes(UTF8));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
return Base64.encodeBytes(value.getBytes(UTF8));
}
}