use of org.springframework.beans.factory.BeanInitializationException in project openolat by klemens.
the class WebappHelper method testUtf8FileSystem.
/**
* Test if filesystem is capable to store UTF-8 characters
* Try to read/write a file with UTF-8 chars in the filename in a temporary directory.
*/
private void testUtf8FileSystem() {
File tmpDir = new File(new File(WebappHelper.getUserDataRoot()), "tmp");
if (!tmpDir.exists())
tmpDir.mkdir();
File writeFile = new File(tmpDir, "UTF-8 test läsÖiç-首页|新");
if (writeFile.exists()) {
// remove exising files first
writeFile.delete();
}
try {
writeFile.createNewFile();
} catch (IOException e) {
log.warn("No UTF-8 capable filesystem found! Error while writing testfile to filesystem", e);
}
// try to lookup file: get files from filesystem and search for file we created above
File[] tmpFiles = tmpDir.listFiles();
boolean foundUtf8File = false;
if (tmpFiles != null) {
for (int i = 0; i < tmpFiles.length; i++) {
File tmpFile = tmpFiles[i];
if (tmpFile.getName().equals("UTF-8 test läsÖiç-首页|新")) {
foundUtf8File = true;
break;
}
}
}
if (foundUtf8File) {
// test ok
log.info("UTF-8 capable filesystem detected");
} else {
// test failed
log.warn("No UTF-8 capable filesystem found! Could not read / write UTF-8 characters from / to filesystem! " + "You probably misconfigured your system, try setting your LANG variable to a correct value.");
log.warn("Your current file encoding configuration: java.nio.charset.Charset.defaultCharset().name()::" + java.nio.charset.Charset.defaultCharset().name() + " (the one used) and your system property file.encoding::" + System.getProperty("file.encoding") + " (the one configured)");
}
// try to delete file anyway
writeFile.delete();
if (!foundUtf8File && WebappHelper.enforceUtf8Filesystem) {
throw new BeanInitializationException("System startup aborted to to file system missconfiguration. See previous warnings in logfile and fix your " + "Java environment. This check can be disabled by setting enforce.utf8.filesystem=false, but be aware that the " + "decision to use a certain encoding on the filesystem is a one-time decision. You can not cange to UTF-8 later!");
}
}
Aggregations