Skip to content

Commit 45d4c1d

Browse files
committed
Solve the problem that CJK characters cannot be packaged and installed packages and garbled characters
1 parent 5c5ca22 commit 45d4c1d

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

src/main/java/io/github/fvarrui/javapackager/gradle/PackagePlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import edu.sc.seis.launch4j.tasks.Launch4jLibraryTask;
44
import io.github.fvarrui.javapackager.packagers.Context;
5+
import io.github.fvarrui.javapackager.utils.Logger;
56
import org.gradle.api.Plugin;
67
import org.gradle.api.Project;
78

@@ -18,7 +19,6 @@ public class PackagePlugin implements Plugin<Project> {
1819

1920
@Override
2021
public void apply(Project project) {
21-
2222
Context.setContext(new GradleContext(project));
2323

2424
project.getPluginManager().apply("java");

src/main/java/io/github/fvarrui/javapackager/utils/CommandUtils.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package io.github.fvarrui.javapackager.utils;
22

3-
import java.io.BufferedReader;
4-
import java.io.File;
5-
import java.io.IOException;
6-
import java.io.InputStreamReader;
3+
import java.io.*;
4+
import java.nio.charset.Charset;
75

86
import org.apache.commons.lang3.StringUtils;
97
import org.codehaus.plexus.util.cli.CommandLineException;
@@ -47,7 +45,7 @@ public static ExecutionResult executeWithResult(File workingDirectory, String ex
4745

4846
Process process = command.execute();
4947

50-
BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream()));
48+
BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName("GBK")));
5149
BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
5250
while (process.isAlive() || output.ready() || error.ready()) {
5351
if (output.ready()) {

src/main/java/io/github/fvarrui/javapackager/utils/VelocityUtils.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import static org.apache.commons.io.FileUtils.writeStringToFile;
44

5-
import java.io.File;
6-
import java.io.IOException;
5+
import java.io.*;
76
import java.util.ArrayList;
87
import java.util.UUID;
98

@@ -67,10 +66,22 @@ public static void render(String templatePath, File output, Object info) throws
6766
try {
6867
String data = render(templatePath, info);
6968
data = data.replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n");
70-
writeStringToFile(output, data, "UTF-8");
69+
writeString(output,data);
7170
} catch (IOException e) {
7271
throw new Exception(e.getMessage(), e);
7372
}
7473
}
74+
75+
public static void writeString(File output,String data) throws Exception{
76+
if(!output.exists()){
77+
output.getParentFile().mkdirs();
78+
}
79+
FileOutputStream fileOutputStream = new FileOutputStream(output);
80+
// write utf-8 BOM
81+
byte[] uft8bom={(byte)0xef,(byte)0xbb,(byte)0xbf};
82+
fileOutputStream.write(uft8bom);
83+
fileOutputStream.write(data.getBytes());
84+
fileOutputStream.close();
85+
}
7586

7687
}

0 commit comments

Comments
 (0)