use of org.dbflute.helper.filesystem.FileTextIO in project dbflute-core by dbflute.
the class DfArrangeQueryDocSetupper method searchArrangeQueryMethodList.
// ===================================================================================
// Analyze Method
// ==============
protected List<DfArrangeQueryMethod> searchArrangeQueryMethodList(String tableDbName, String classFilePath) {
final FileTextIO textIO = prepareSourceFileTextIO();
if (!new File(classFilePath).exists()) {
// e.g. generate-only of table-except
return Collections.emptyList();
}
final String cqText = textIO.read(classFilePath);
final List<String> lineList = Srl.splitList(cqText, "\n");
return analyzeArrangeQueryLineList(tableDbName, lineList);
}
use of org.dbflute.helper.filesystem.FileTextIO in project dbflute-core by dbflute.
the class DfAbsractDataWriter method processLargeTextFile.
// -----------------------------------------------------
// Large Text File
// ---------------
// contributed by awaawa, thanks!
protected boolean processLargeTextFile(String dataDirectory, File dataFile, String tableName, String columnName, String value, PreparedStatement ps, int bindCount, Map<String, DfColumnMeta> columnInfoMap, int rowNumber) throws SQLException {
if (value == null || value.trim().length() == 0) {
// cannot be binary
return false;
}
final DfColumnMeta columnInfo = columnInfoMap.get(columnName);
if (columnInfo == null) {
// unsupported when meta data is not found
return false;
}
final Class<?> columnType = getBindType(tableName, columnInfo);
if (columnType == null) {
// unsupported too
return false;
}
if (!isLargeTextFile(dataDirectory, tableName, columnName)) {
// not target as large text file
return false;
}
// the value should be a path to a text file
// from data file's current directory
final String path;
final String trimmedValue = value.trim();
if (trimmedValue.startsWith("/")) {
// means absolute path
path = trimmedValue;
} else {
final String dataFilePath = Srl.replace(dataFile.getAbsolutePath(), "\\", "/");
final String baseDirPath = Srl.substringLastFront(dataFilePath, "/");
path = baseDirPath + "/" + trimmedValue;
}
final File textFile = new File(path);
if (!textFile.exists()) {
throwLoadDataTextFileReadFailureException(tableName, columnName, path, rowNumber);
}
try {
final String read = new FileTextIO().encodeAsUTF8().removeUTF8Bom().read(path);
ps.setString(bindCount, read);
} catch (RuntimeException e) {
throwLoadDataTextFileReadFailureException(tableName, columnName, path, rowNumber, e);
}
return true;
}
use of org.dbflute.helper.filesystem.FileTextIO in project dbflute-core by dbflute.
the class DfMigrationFromAntTest method test_FileUtils_to_Path.
// ===================================================================================
// FileUtils
// =========
public void test_FileUtils_to_Path() throws IOException {
// ## Arrange ##
String dirPath = getTestCaseBuildDir().getCanonicalPath() + "/fromant";
File testDir = new File(dirPath);
if (testDir.exists()) {
testDir.delete();
}
testDir.mkdir();
File srcFile = new File(dirPath + "/fromant-src.txt");
File destByAntFile = new File(dirPath + "/fromant-desc-by-ant.txt");
File destByNioFile = new File(dirPath + "/fromant-desc-by-nio.txt");
// sea in maihama(as kanji)
String writtenText = "sea in \u821e\u6d5c";
FileTextIO textIO = new FileTextIO().encodeAsUTF8();
textIO.write(new FileOutputStream(srcFile), writtenText);
assertTrue(srcFile.exists());
try {
// ## Act ##
// AlterCheck uses
FileUtils.getFileUtils().copyFile(srcFile, destByAntFile);
Files.copy(srcFile.toPath(), destByNioFile.toPath(), StandardCopyOption.COPY_ATTRIBUTES);
// ## Assert ##
assertTrue(destByAntFile.exists());
assertTrue(destByNioFile.exists());
String byAntText = textIO.read(new FileInputStream(destByAntFile));
String byNioText = textIO.read(new FileInputStream(destByNioFile));
assertEquals(byAntText, byNioText);
} finally {
if (srcFile.exists()) {
srcFile.delete();
}
if (destByAntFile.exists()) {
destByAntFile.delete();
}
if (destByNioFile.exists()) {
destByNioFile.delete();
}
}
}
use of org.dbflute.helper.filesystem.FileTextIO in project dbflute-core by dbflute.
the class DfRefreshMan method detectEclipseProjectName.
protected String detectEclipseProjectName() {
// e.g.
// PROJECT_ROOT
// |-dbflute_maihamadb
// |-mydbflute
// |-...
// |-.project
final File projectFile = new File("../.project");
if (!projectFile.exists()) {
return null;
}
final Set<String> resultSet = new HashSet<String>();
try {
new FileTextIO().encodeAsUTF8().readFilteringLine(new FileInputStream(projectFile), new FileTextLineFilter() {
boolean _found = false;
public String filter(String line) {
if (_found || !line.contains("<name>")) {
return null;
}
ScopeInfo scopeInfo = Srl.extractScopeFirst(line, "<name>", "</name>");
if (scopeInfo == null) {
// basically no way, just in case
return null;
}
final String content = scopeInfo.getContent().trim();
resultSet.add(content);
_found = true;
return null;
}
});
} catch (FileNotFoundException ignored) {
// no way because of already checked, just in case
return null;
}
if (resultSet.isEmpty()) {
_log.info("*The .project file exists but not found project name: " + projectFile);
return null;
}
return resultSet.iterator().next();
}
use of org.dbflute.helper.filesystem.FileTextIO in project dbflute-core by dbflute.
the class DfUpgradeTask method replaceDBFluteClientReference.
// ===================================================================================
// Replace Reference
// =================
protected void replaceDBFluteClientReference(final String upgradeVersion) {
final FileTextIO textIO = new FileTextIO().encodeAsUTF8();
doReplaceProjectBat(upgradeVersion, textIO);
doReplaceProjectSh(upgradeVersion, textIO);
}
Aggregations