mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
Refactor: Always use UTF-8
This commit is contained in:
1 parent
e9efd5a702
commit
edbe867fd8
26 files changed
+187
-138
No files matched your search
@@ -7,6 +7,7 @@ import io.ebean.ddlrunner.DdlRunner;
|
||||
import io.ebean.ddlrunner.ScriptTransform;
|
||||
import io.ebean.plugin.Plugin;
|
||||
import io.ebean.plugin.SpiServer;
|
||||
import io.ebean.util.IOUtils;
|
||||
import io.ebean.util.JdbcClose;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.dbmigration.model.CurrentModel;
|
||||
@@ -18,13 +19,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;
|
||||
|
||||
@@ -266,7 +265,7 @@ public class DdlPlugin implements Plugin {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -335,7 +334,7 @@ public class DdlPlugin implements Plugin {
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -346,7 +345,9 @@ public class DdlPlugin implements Plugin {
|
||||
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 {
|
||||
|
||||
+15
-33
@@ -1,31 +1,27 @@
|
||||
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.PersistenceContextScope;
|
||||
import io.ebean.annotation.MutationDetection;
|
||||
import io.ebean.annotation.PersistBatch;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.cache.ServerCachePlugin;
|
||||
import io.ebean.config.AutoTuneConfig;
|
||||
import io.ebean.config.ClassLoadConfig;
|
||||
import io.ebean.config.CurrentTenantProvider;
|
||||
import io.ebean.config.CurrentUserProvider;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.DbConstraintNaming;
|
||||
import io.ebean.config.DocStoreConfig;
|
||||
import io.ebean.config.EncryptDeployManager;
|
||||
import io.ebean.config.EncryptKeyManager;
|
||||
import io.ebean.config.Encryptor;
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebean.config.PlatformConfig;
|
||||
import io.ebean.config.PropertiesWrapper;
|
||||
import io.ebean.config.TenantCatalogProvider;
|
||||
import io.ebean.config.TenantMode;
|
||||
import io.ebean.config.TenantSchemaProvider;
|
||||
import io.ebean.config.DatabaseConfig.UuidVersion;
|
||||
import io.ebean.config.dbplatform.DatabasePlatform;
|
||||
import io.ebean.config.dbplatform.DbEncrypt;
|
||||
import io.ebean.config.dbplatform.clickhouse.ClickHousePlatform;
|
||||
import io.ebean.config.dbplatform.cockroach.CockroachPlatform;
|
||||
import io.ebean.config.dbplatform.db2.DB2Platform;
|
||||
@@ -44,8 +40,8 @@ import io.ebean.config.dbplatform.sqlanywhere.SqlAnywherePlatform;
|
||||
import io.ebean.config.dbplatform.sqlite.SQLitePlatform;
|
||||
import io.ebean.config.dbplatform.sqlserver.SqlServer16Platform;
|
||||
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
|
||||
import io.ebean.datasource.DataSourceConfig;
|
||||
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;
|
||||
@@ -62,20 +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 java.util.StringJoiner;
|
||||
|
||||
import javax.persistence.EnumType;
|
||||
|
||||
import static io.ebeaninternal.api.PlatformMatch.matchPlatform;
|
||||
|
||||
/**
|
||||
* Generates DB Migration xml and sql scripts.
|
||||
@@ -518,7 +500,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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-3
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.dbmigration.ddlgeneration;
|
||||
|
||||
import io.ebean.util.IOUtils;
|
||||
import io.ebeaninternal.dbmigration.migration.AddColumn;
|
||||
import io.ebeaninternal.dbmigration.migration.ChangeSet;
|
||||
import io.ebeaninternal.dbmigration.migration.CreateTable;
|
||||
@@ -9,8 +10,8 @@ import io.ebeaninternal.dbmigration.migrationreader.MigrationXmlReader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Reader;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -89,8 +90,7 @@ public class Helper {
|
||||
|
||||
public static String asText(InputStream in) throws IOException {
|
||||
|
||||
try {
|
||||
InputStreamReader reader = new InputStreamReader(in);
|
||||
try (Reader reader = IOUtils.newReader(in)) {
|
||||
|
||||
LineNumberReader lineNumberReader = new LineNumberReader(reader);
|
||||
|
||||
|
||||
Reference in new issue
Block a user