Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portable String <--> bytes conversion #841

Merged
merged 1 commit into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.base.Strings;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -69,7 +70,9 @@ static Optional<List<GapicBatchingSettings>> parse(String gapicYamlConfigFilePat
String fileContents = null;

try {
fileContents = new String(Files.readAllBytes(Paths.get(gapicYamlConfigFilePath)));
fileContents =
new String(
Files.readAllBytes(Paths.get(gapicYamlConfigFilePath)), StandardCharsets.UTF_8);
} catch (IOException e) {
return Optional.empty();
}
Expand Down Expand Up @@ -104,7 +107,7 @@ private static Optional<List<GapicBatchingSettings>> parseFromMap(Map<String, Ob
batchingOuterYamlConfig.containsKey(YAML_KEY_DESCRIPTOR),
String.format(
"%s key expected but not found for method %s",
YAML_KEY_DESCRIPTOR, (String) methodYamlConfig.get(YAML_KEY_NAME)));
YAML_KEY_DESCRIPTOR, methodYamlConfig.get(YAML_KEY_NAME)));

// Parse the threshold values first.
Map<String, Object> batchingYamlConfig =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.base.Strings;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
Expand Down Expand Up @@ -48,7 +49,9 @@ static Optional<GapicLanguageSettings> parse(String gapicYamlConfigFilePath) {
String fileContents = null;

try {
fileContents = new String(Files.readAllBytes(Paths.get(gapicYamlConfigFilePath)));
fileContents =
new String(
Files.readAllBytes(Paths.get(gapicYamlConfigFilePath)), StandardCharsets.UTF_8);
} catch (IOException e) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.base.Strings;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -56,7 +57,9 @@ static Optional<List<GapicLroRetrySettings>> parse(String gapicYamlConfigFilePat
String fileContents = null;

try {
fileContents = new String(Files.readAllBytes(Paths.get(gapicYamlConfigFilePath)));
fileContents =
new String(
Files.readAllBytes(Paths.get(gapicYamlConfigFilePath)), StandardCharsets.UTF_8);
} catch (IOException e) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.protobuf.util.JsonFormat;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.LinkedHashMap;
Expand All @@ -37,7 +38,8 @@ public static Optional<com.google.api.Service> parse(String serviceYamlFilePath)

String fileContents = null;
try {
fileContents = new String(Files.readAllBytes(Paths.get(serviceYamlFilePath)));
fileContents =
new String(Files.readAllBytes(Paths.get(serviceYamlFilePath)), StandardCharsets.UTF_8);
} catch (IOException e) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse;
import com.google.protobuf.util.JsonFormat;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
Expand Down Expand Up @@ -61,7 +62,7 @@ public static CodeGeneratorResponse write(
JarEntry jarEntry = new JarEntry(String.format("%s/%s.java", path, className));
try {
jos.putNextEntry(jarEntry);
jos.write(code.getBytes());
jos.write(code.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new GapicWriterException(
String.format(
Expand All @@ -80,7 +81,7 @@ public static CodeGeneratorResponse write(
JarEntry jarEntry = new JarEntry(String.format("%s/package-info.java", path));
try {
jos.putNextEntry(jarEntry);
jos.write(code.getBytes());
jos.write(code.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new GapicWriterException("Could not write code for package-info.java");
}
Expand All @@ -90,7 +91,8 @@ public static CodeGeneratorResponse write(
jarEntry = new JarEntry(String.format("%s/gapic_metadata.json", path));
try {
jos.putNextEntry(jarEntry);
jos.write(JsonFormat.printer().print(context.gapicMetadata()).getBytes());
jos.write(
JsonFormat.printer().print(context.gapicMetadata()).getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new GapicWriterException("Could not write gapic_metadata.json");
}
Expand Down