use of org.apache.commons.io.filefilter.WildcardFileFilter in project OpenRefine by OpenRefine.
the class GetLanguagesCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String modname = request.getParameter("module");
if (modname == null) {
modname = "core";
}
ButterflyModule module = this.servlet.getModule(modname);
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
JSONWriter writer = new JSONWriter(response.getWriter());
writer.object();
writer.key("languages");
writer.array();
// we always have English and it's always first
writeLangData(writer, "en", "English");
FileFilter fileFilter = new WildcardFileFilter("translation-*.json");
for (File file : new File(module.getPath() + File.separator + "langs").listFiles(fileFilter)) {
String lang = file.getName().split("-")[1].split("\\.")[0];
if (!"en".equals(lang) && !"default".equals(lang)) {
JSONObject json = LoadLanguageCommand.loadLanguage(this.servlet, "core", lang);
if (json != null) {
String label = json.getString("name");
writeLangData(writer, lang, label);
}
}
}
writer.endArray();
writer.endObject();
} catch (JSONException e) {
respondException(response, e);
}
}
use of org.apache.commons.io.filefilter.WildcardFileFilter in project storymaker by StoryMaker.
the class StorymakerDownloadManager method handleFile.
private boolean handleFile(File tempFile) {
File appendedFile = null;
File actualFile = new File(tempFile.getPath().substring(0, tempFile.getPath().lastIndexOf(".")));
Timber.d("ACTUAL FILE: " + actualFile.getAbsolutePath());
long fileSize = 0;
if (tempFile.getName().contains(scal.io.liger.Constants.MAIN)) {
fileSize = indexItem.getExpansionFileSize();
} else if (tempFile.getName().contains(scal.io.liger.Constants.PATCH)) {
fileSize = indexItem.getPatchFileSize();
} else {
Timber.e("CAN'T DETERMINE FILE SIZE FOR " + tempFile.getName() + " (NOT A MAIN OR PATCH FILE)");
return false;
}
// additional error checking
if (tempFile.exists()) {
if (tempFile.length() == 0) {
Timber.e("FINISHED DOWNLOAD OF " + tempFile.getPath() + " BUT IT IS A ZERO BYTE FILE");
return false;
} else if (tempFile.length() < fileSize) {
Timber.e("FINISHED DOWNLOAD OF " + tempFile.getPath() + " BUT IT IS TOO SMALL: " + Long.toString(tempFile.length()) + "/" + Long.toString(fileSize));
// if file is too small, managePartialFile
appendedFile = managePartialFile(tempFile);
// if appended file is still too small, fail (leave .part file for next download
if (appendedFile == null) {
Timber.e("ERROR WHILE APPENDING TO PARTIAL FILE FOR " + tempFile.getPath());
return false;
} else if (appendedFile.length() < fileSize) {
Timber.e("APPENDED FILE " + appendedFile.getPath() + " IS STILL TOO SMALL: " + Long.toString(appendedFile.length()) + "/" + Long.toString(fileSize));
return false;
} else {
Timber.d("APPENDED FILE " + appendedFile.getPath() + " IS COMPLETE!");
// show notification
Utils.toastOnUiThread((Activity) context, context.getString(R.string.finished_downloading) + " " + indexItem.getTitle() + ".", false);
sendDownloadCompleteMessage(indexItem.getExpansionId());
}
} else {
Timber.d("FINISHED DOWNLOAD OF " + tempFile.getPath() + " AND FILE LOOKS OK");
// show notification
Utils.toastOnUiThread((Activity) context, context.getString(R.string.finished_downloading) + " " + indexItem.getTitle() + ".", false);
sendDownloadCompleteMessage(indexItem.getExpansionId());
}
} else {
Timber.e("FINISHED DOWNLOAD OF " + tempFile.getPath() + " BUT IT DOES NOT EXIST");
return false;
}
try {
// clean up old obbs before renaming new file
File directory = new File(actualFile.getParent());
String nameFilter = "";
if (actualFile.getName().contains(indexItem.getExpansionFileVersion())) {
nameFilter = actualFile.getName().replace(indexItem.getExpansionFileVersion(), "*");
} else {
nameFilter = actualFile.getName();
}
Timber.d("CLEANUP: DELETING " + nameFilter + " FROM " + directory.getPath());
WildcardFileFilter oldFileFilter = new WildcardFileFilter(nameFilter);
for (File oldFile : FileUtils.listFiles(directory, oldFileFilter, null)) {
Timber.d("CLEANUP: FOUND " + oldFile.getPath() + ", DELETING");
FileUtils.deleteQuietly(oldFile);
}
if ((appendedFile != null) && appendedFile.exists()) {
// moved to commons-io from using exec and mv because we were getting 0kb obb files on some devices
FileUtils.moveFile(appendedFile, actualFile);
// for some reason I was getting an 0kb .tmp file lingereing
FileUtils.deleteQuietly(appendedFile);
// for some reason I was getting an 0kb .tmp file lingereing
FileUtils.deleteQuietly(tempFile);
Timber.d("MOVED PART FILE " + appendedFile.getPath() + " TO " + actualFile.getPath());
} else if (tempFile.exists()) {
// moved to commons-io from using exec and mv because we were getting 0kb obb files on some devices
FileUtils.moveFile(tempFile, actualFile);
// for some reason I was getting an 0kb .tmp file lingereing
FileUtils.deleteQuietly(tempFile);
Timber.d("MOVED TEMP FILE " + tempFile.getPath() + " TO " + actualFile.getPath());
} else {
// not sure how we get here but this is a failure state
Timber.e(".TMP AND .PART FILES DO NOT EXIST FOR " + tempFile.getPath());
return false;
}
} catch (IOException ioe) {
Timber.e("ERROR DURING CLEANUP/MOVING TEMP FILE: " + ioe.getMessage());
return false;
}
// download finished, must clear ZipHelper cache
ZipHelper.clearCache();
return true;
}
use of org.apache.commons.io.filefilter.WildcardFileFilter in project storymaker by StoryMaker.
the class BaseTest method cleanup.
public void cleanup(String directory) {
Timber.d("BEGIN CLEANUP");
WildcardFileFilter oldFileFilter = new WildcardFileFilter("*instance*");
for (File oldFile : FileUtils.listFiles(new File(directory), oldFileFilter, null)) {
Timber.d("FOUND " + oldFile.getPath() + ", DELETING");
FileUtils.deleteQuietly(oldFile);
}
Timber.d("CLEANUP COMPLETE");
}
use of org.apache.commons.io.filefilter.WildcardFileFilter in project storymaker by StoryMaker.
the class MinimumTest method cleanup.
/*
private void swipe(int swipes) {
for (int i = 0; i < swipes; i++) {
onView(withId(R.id.recyclerView)).perform(Util.swipeUpLess());
}
}
private void swipeMore(int swipes) {
for (int i = 0; i < swipes; i++) {
onView(withId(R.id.recyclerView)).perform(Util.swipeUp());
}
}
private void settingsSwipe(int currentItem) {
onView(withChild(withChild(withText(mHomeActivity.getApplicationContext().getString(currentItem))))).perform(Util.swipeUp());
}
*/
private void cleanup(String directory) {
WildcardFileFilter oldFileFilter = new WildcardFileFilter("*instance*");
for (File oldFile : FileUtils.listFiles(new File(directory), oldFileFilter, null)) {
Timber.d("CLEANUP: FOUND " + oldFile.getPath() + ", DELETING");
FileUtils.deleteQuietly(oldFile);
}
}
use of org.apache.commons.io.filefilter.WildcardFileFilter in project symmetric-ds by JumpMind.
the class FileTrigger method createIOFileFilter.
public IOFileFilter createIOFileFilter() {
String[] includes = StringUtils.isNotBlank(includesFiles) ? includesFiles.split(",") : new String[] { "*" };
String[] excludes = StringUtils.isNotBlank(excludesFiles) ? excludesFiles.split(",") : null;
IOFileFilter filter = new WildcardFileFilter(includes);
if (excludes != null && excludes.length > 0) {
List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
fileFilters.add(filter);
fileFilters.add(new NotFileFilter(new WildcardFileFilter(excludes)));
filter = new AndFileFilter(fileFilters);
}
if (!recurse) {
List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
fileFilters.add(filter);
fileFilters.add(new NotFileFilter(FileFilterUtils.directoryFileFilter()));
filter = new AndFileFilter(fileFilters);
} else {
List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
fileFilters.add(filter);
fileFilters.add(FileFilterUtils.directoryFileFilter());
filter = new OrFileFilter(fileFilters);
}
return filter;
}
Aggregations