mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
Always use UTF-8
This commit is contained in:
1 parent
0cf9f0bf58
commit
01847e44de
26 files changed
+189
-117
No files matched your search
@@ -5,6 +5,7 @@ import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.dbplatform.DatabasePlatform;
|
||||
import io.ebean.ddlrunner.DdlRunner;
|
||||
import io.ebean.ddlrunner.ScriptTransform;
|
||||
import io.ebean.util.IOUtils;
|
||||
import io.ebean.util.JdbcClose;
|
||||
import io.ebeaninternal.api.SpiDdlGenerator;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
@@ -17,13 +18,11 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@@ -268,7 +267,7 @@ public class DdlGenerator implements SpiDdlGenerator {
|
||||
if (is == null) {
|
||||
log.warn("sql script {} was not found as a resource", sqlScript);
|
||||
} else {
|
||||
String content = readContent(new InputStreamReader(is));
|
||||
String content = readContent(IOUtils.newReader(is)); // 'is' is closed
|
||||
runScript(connection, false, content, sqlScript);
|
||||
}
|
||||
}
|
||||
@@ -337,7 +336,7 @@ public class DdlGenerator implements SpiDdlGenerator {
|
||||
|
||||
protected void writeFile(String fileName, String fileContent) throws IOException {
|
||||
File f = new File(baseDir, fileName);
|
||||
try (FileWriter fw = new FileWriter(f)) {
|
||||
try (Writer fw = IOUtils.newWriter(f)) {
|
||||
fw.write(fileContent);
|
||||
fw.flush();
|
||||
}
|
||||
@@ -348,7 +347,9 @@ public class DdlGenerator implements SpiDdlGenerator {
|
||||
if (!f.exists()) {
|
||||
return null;
|
||||
}
|
||||
return readContent(new FileReader(f));
|
||||
try (Reader reader = IOUtils.newReader(f)) {
|
||||
return readContent(reader);
|
||||
}
|
||||
}
|
||||
|
||||
protected String readContent(Reader reader) throws IOException {
|
||||
|
||||
+17
-12
@@ -1,8 +1,22 @@
|
||||
package io.ebeaninternal.dbmigration;
|
||||
|
||||
import static io.ebeaninternal.api.PlatformMatch.matchPlatform;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.config.ClassLoadConfig;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.DbConstraintNaming;
|
||||
import io.ebean.config.PlatformConfig;
|
||||
@@ -27,6 +41,8 @@ import io.ebean.config.dbplatform.sqlite.SQLitePlatform;
|
||||
import io.ebean.config.dbplatform.sqlserver.SqlServer16Platform;
|
||||
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
|
||||
import io.ebean.dbmigration.DbMigration;
|
||||
import io.ebean.util.IOUtils;
|
||||
import io.ebean.util.StringHelper;
|
||||
import io.ebeaninternal.api.DbOffline;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlOptions;
|
||||
@@ -42,17 +58,6 @@ import io.ebeaninternal.dbmigration.model.PlatformDdlWriter;
|
||||
import io.ebeaninternal.extraddl.model.DdlScript;
|
||||
import io.ebeaninternal.extraddl.model.ExtraDdl;
|
||||
import io.ebeaninternal.extraddl.model.ExtraDdlXmlReader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import static io.ebeaninternal.api.PlatformMatch.matchPlatform;
|
||||
|
||||
/**
|
||||
* Generates DB Migration xml and sql scripts.
|
||||
@@ -417,7 +422,7 @@ public class DefaultDbMigration implements DbMigration {
|
||||
String fullName = repeatableMigrationName(script.isInit(), script.getName());
|
||||
logger.debug("writing repeatable script {}", fullName);
|
||||
File file = new File(migrationDir, fullName);
|
||||
try (FileWriter writer = new FileWriter(file)) {
|
||||
try (Writer writer = IOUtils.newWriter(file)) {
|
||||
writer.write(script.getValue());
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ package io.ebeaninternal.dbmigration;
|
||||
|
||||
import io.ebean.config.dbplatform.DatabasePlatform;
|
||||
import io.ebean.migration.MigrationVersion;
|
||||
import io.ebean.util.IOUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -50,17 +51,17 @@ class IndexMigration {
|
||||
|
||||
private void generateIndex() throws IOException {
|
||||
Collections.sort(all);
|
||||
FileWriter writer = new FileWriter(indexFile);
|
||||
for (Entry entry : all) {
|
||||
writeChecksumPadded(writer, entry.checksum);
|
||||
writer.write(entry.fileName);
|
||||
try (Writer writer = IOUtils.newWriter(indexFile)) {
|
||||
for (Entry entry : all) {
|
||||
writeChecksumPadded(writer, entry.checksum);
|
||||
writer.write(entry.fileName);
|
||||
writer.write(eol);
|
||||
}
|
||||
writer.write(eol);
|
||||
}
|
||||
writer.write(eol);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
private void writeChecksumPadded(FileWriter writer, int checksum) throws IOException {
|
||||
private void writeChecksumPadded(Writer writer, int checksum) throws IOException {
|
||||
final String asStr = String.valueOf(checksum);
|
||||
writer.write(asStr);
|
||||
writer.write(',');
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package io.ebeaninternal.dbmigration;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
import io.ebean.util.IOUtils;
|
||||
|
||||
/**
|
||||
* Calculates the checksum for the given file content.
|
||||
*/
|
||||
@@ -14,7 +15,7 @@ class MChecksum {
|
||||
* Returns the checksum of the file. Agnostic of encoding and new line character.
|
||||
*/
|
||||
static int calculate(File file) {
|
||||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")))) {
|
||||
try (BufferedReader bufferedReader = IOUtils.newReader(file)) {
|
||||
final CRC32 crc32 = new CRC32();
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
|
||||
+3
-2
@@ -1,14 +1,15 @@
|
||||
package io.ebeaninternal.dbmigration.migrationreader;
|
||||
|
||||
|
||||
import io.ebean.util.IOUtils;
|
||||
import io.ebeaninternal.dbmigration.migration.Migration;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Simple writer for output of the Migration/ChangeSet as an XML document.
|
||||
@@ -26,7 +27,7 @@ public class MigrationXmlWriter {
|
||||
*/
|
||||
public void write(Migration migration, File file) {
|
||||
|
||||
try (FileWriter writer = new FileWriter(file)) {
|
||||
try (Writer writer = IOUtils.newWriter(file)) {
|
||||
|
||||
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
|
||||
if (comment != null) {
|
||||
|
||||
+4
-4
@@ -2,6 +2,7 @@ package io.ebeaninternal.dbmigration.model;
|
||||
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.dbplatform.DatabasePlatform;
|
||||
import io.ebean.util.IOUtils;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlHandler;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
|
||||
@@ -14,7 +15,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.List;
|
||||
@@ -70,16 +70,16 @@ public class PlatformDdlWriter {
|
||||
*/
|
||||
protected void writePlatformDdl(DdlWrite write, File resourcePath, String fullVersion) throws IOException {
|
||||
if (!write.isApplyEmpty()) {
|
||||
try (FileWriter applyWriter = createWriter(resourcePath, fullVersion, ".sql")) {
|
||||
try (Writer applyWriter = createWriter(resourcePath, fullVersion, ".sql")) {
|
||||
writeApplyDdl(applyWriter, write);
|
||||
applyWriter.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected FileWriter createWriter(File path, String fullVersion, String suffix) throws IOException {
|
||||
protected Writer createWriter(File path, String fullVersion, String suffix) throws IOException {
|
||||
File applyFile = new File(path, fullVersion + suffix);
|
||||
return new FileWriter(applyFile);
|
||||
return IOUtils.newWriter(applyFile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user