Skip to content

Commit

Permalink
Merge pull request #42884 from Shadow-Devil/use-standard-charset
Browse files Browse the repository at this point in the history
Replace charset name argument with StandardCharsets.UTF_8
  • Loading branch information
warunalakshitha authored Jun 12, 2024
2 parents 04a642d + ecf86bd commit 4ac37ad
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ private static String readResourceAsString(String uri) throws IOException {
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
return result.toString(StandardCharsets.UTF_8.name());
return result.toString(StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

/**
Expand Down Expand Up @@ -98,12 +97,8 @@ public void logError(LSOperation operation, String message, Throwable error, Tex
String details = getErrorDetails(identifier, error, pos);
if (config.isDebugLogEnabled()) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
PrintStream ps = new PrintStream(baos, true, StandardCharsets.UTF_8.name());
error.printStackTrace(ps);
} catch (UnsupportedEncodingException e1) {
//ignore
}
PrintStream ps = new PrintStream(baos, true, StandardCharsets.UTF_8);
error.printStackTrace(ps);
this.languageClient.logMessage(
new MessageParams(MessageType.Error, message + " " + details + "\n" + baos));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,9 @@ private static Object encode(String key, List<String> specialCharacters) {
String encodedKey = key;
String encodedValue;
for (String character : specialCharacters) {
try {
if (encodedKey.contains(character)) {
encodedValue = URLEncoder.encode(character, StandardCharsets.UTF_8.toString());
encodedKey = encodedKey.replace(character, encodedValue);
}
} catch (UnsupportedEncodingException e) {
return ErrorHelper.getRuntimeException(
ErrorCodes.INCOMPATIBLE_ARGUMENTS, "Error while encoding: " + e.getMessage());
if (encodedKey.contains(character)) {
encodedValue = URLEncoder.encode(character, StandardCharsets.UTF_8);
encodedKey = encodedKey.replace(character, encodedValue);
}
}
return encodedKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;

/**
* Utility class for managing responses.
*/
public class ResponseReader {
private static final Logger LOG = LoggerFactory.getLogger(ResponseReader.class);
public static final String UTF_8 = "UTF-8";

/**
* Get the response value from input stream.
Expand All @@ -46,7 +46,8 @@ public static String getReturnValue(HttpCarbonMessage response) {
final char[] buffer = new char[bufferSize];
final StringBuilder out = new StringBuilder();
try {
reader = new InputStreamReader(new HttpMessageDataStreamer(response).getInputStream(), UTF_8);
reader = new InputStreamReader(
new HttpMessageDataStreamer(response).getInputStream(), StandardCharsets.UTF_8);
while (true) {
int size = reader.read(buffer, 0, buffer.length);
if (size < 0) {
Expand Down

0 comments on commit 4ac37ad

Please sign in to comment.