Fix file encoding bug

pull/146/head
johnniang 2019-05-08 17:38:16 +08:00
parent 4b508af8af
commit 62ad6cda96
2 changed files with 17 additions and 8 deletions

View File

@ -2,9 +2,9 @@ package run.halo.app.model.params;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import run.halo.app.model.support.CreateCheck;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
/** /**
* Install parameters. * Install parameters.
@ -24,7 +24,7 @@ public class InstallParam extends UserParam {
/** /**
* Blog title. * Blog title.
*/ */
@NotBlank(message = "Blog title must not be blank") @NotBlank(message = "Blog title must not be blank", groups = CreateCheck.class)
private String title; private String title;
/** /**

View File

@ -1,8 +1,6 @@
package run.halo.app.service.impl; package run.halo.app.service.impl;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileReader;
import cn.hutool.core.io.file.FileWriter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
@ -37,6 +35,7 @@ import run.halo.app.utils.HaloUtils;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -215,7 +214,12 @@ public class ThemeServiceImpl implements ThemeService {
checkDirectory(absolutePath); checkDirectory(absolutePath);
// Read file // Read file
return new FileReader(absolutePath).readString(); Path path = Paths.get(absolutePath);
try {
return new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new ServiceException("Failed to read file " + absolutePath, e);
}
} }
@Override @Override
@ -224,7 +228,12 @@ public class ThemeServiceImpl implements ThemeService {
checkDirectory(absolutePath); checkDirectory(absolutePath);
// Write file // Write file
new FileWriter(absolutePath).write(content); Path path = Paths.get(absolutePath);
try {
Files.write(path, content.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new ServiceException("Failed to write file " + absolutePath, e);
}
} }
@Override @Override
@ -273,7 +282,7 @@ public class ThemeServiceImpl implements ThemeService {
} }
// Read the yaml file // Read the yaml file
String optionContent = new String(Files.readAllBytes(optionsPath)); String optionContent = new String(Files.readAllBytes(optionsPath), StandardCharsets.UTF_8);
// Resolve it // Resolve it
return themeConfigResolver.resolve(optionContent); return themeConfigResolver.resolve(optionContent);
@ -638,7 +647,7 @@ public class ThemeServiceImpl implements ThemeService {
try { try {
// Get property content // Get property content
String propertyContent = new String(Files.readAllBytes(propertyPath)); String propertyContent = new String(Files.readAllBytes(propertyPath), StandardCharsets.UTF_8);
// Resolve the base properties // Resolve the base properties
ThemeProperty themeProperty = themePropertyResolver.resolve(propertyContent); ThemeProperty themeProperty = themePropertyResolver.resolve(propertyContent);