use of java.io.FilenameFilter in project SeaStar by 13120241790.
the class AppCrashHandler method sendCrashReport.
/**
* 发送错误日志报告,并删除本地文件
*/
public void sendCrashReport() {
File filesDir = mContext.getFilesDir();
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
return filename.endsWith(SUFFIX);
}
};
String[] list = filesDir.list(filter);
if (list != null && list.length > 0) {
for (String fileName : list) {
File file = new File(path, fileName);
if (file.exists()) {
if (onCrashListener != null) {
onCrashListener.onCrashPost(String.valueOf(crashReport), file);
}
}
}
}
}
use of java.io.FilenameFilter in project opennms by OpenNMS.
the class ConfigTesterTest method zz002testCheckAllDaemonXmlConfigFilesTested.
@Test
public void zz002testCheckAllDaemonXmlConfigFilesTested() {
File someConfigFile = ConfigurationTestUtils.getFileForConfigFile("discovery-configuration.xml");
File configDir = someConfigFile.getParentFile();
assertTrue("daemon configuration directory exists at " + configDir.getAbsolutePath(), configDir.exists());
assertTrue("daemon configuration directory is a directory at " + configDir.getAbsolutePath(), configDir.isDirectory());
String[] configFiles = configDir.list(new FilenameFilter() {
@Override
public boolean accept(File file, String name) {
return name.endsWith(".xml");
}
});
Set<String> allXml = new HashSet<String>(Arrays.asList(configFiles));
allXml.removeAll(m_filesTested);
allXml.removeAll(m_filesIgnored);
if (allXml.size() > 0) {
List<String> files = new ArrayList<String>(allXml);
Collections.sort(files);
fail("These files in " + configDir.getAbsolutePath() + " were not tested: \n\t" + StringUtils.collectionToDelimitedString(files, "\n\t"));
}
}
use of java.io.FilenameFilter in project mobile-center-sdk-android by Microsoft.
the class StorageHelperAndroidTest method internalStorage.
@Test
public void internalStorage() throws IOException, InterruptedException {
Log.i(TAG, "Testing Internal Storage file read/write");
final String prefix = Long.toString(System.currentTimeMillis());
/* Create a mock data. */
String filename1 = prefix + "-" + UUIDUtils.randomUUID().toString() + INTERNAL_STORAGE_TEST_FILE_EXTENSION;
String contents1 = "java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.isEmpty()' on a null object reference\n" + "at com.microsoft.azure.mobile.utils.StorageHelperAndroidTest.internalStorage(StorageHelperAndroidTest.java:124)\n" + "at java.lang.reflect.Method.invoke(Native Method)\n" + "at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)";
String filename2 = prefix + "-" + UUIDUtils.randomUUID().toString() + INTERNAL_STORAGE_TEST_FILE_EXTENSION;
//noinspection SpellCheckingInspection
String contents2 = "java.io.FileNotFoundException: 6c1b1c58-1c2f-47d9-8f04-52639c3a804d: open failed: EROFS (Read-only file system)\n" + "at libcore.io.IoBridge.open(IoBridge.java:452)\n" + "at java.io.FileOutputStream.<init>(FileOutputStream.java:87)\n" + "at java.io.FileOutputStream.<init>(FileOutputStream.java:72)\n" + "at java.io.FileWriter.<init>(FileWriter.java:42)";
String filename3 = prefix + "-" + UUIDUtils.randomUUID().toString() + INTERNAL_STORAGE_TEST_FILE_EXTENSION;
String filename4 = prefix + "-" + UUIDUtils.randomUUID().toString() + INTERNAL_STORAGE_TEST_FILE_EXTENSION;
/* FilenameFilter to look up files that are created in current test. */
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
return filename.startsWith(prefix) && filename.endsWith(INTERNAL_STORAGE_TEST_FILE_EXTENSION);
}
};
/* Write contents to test files after 2 sec delay. */
Log.i(TAG, "Writing " + filename1);
InternalStorage.write(sAndroidFilesPath + filename1, contents1);
TimeUnit.SECONDS.sleep(2);
Log.i(TAG, "Writing " + filename2);
InternalStorage.write(sAndroidFilesPath + filename2, contents2);
/* Also write empty content to a test file. */
InternalStorage.write(sAndroidFilesPath + filename3, "");
InternalStorage.write(sAndroidFilesPath + filename4, " ");
/* Get file names in the root path. */
String[] filenames = InternalStorage.getFilenames(sAndroidFilesPath, filter);
/* Verify the files are created. */
assertNotNull(filenames);
assertEquals(2, filenames.length);
List<String> list = Arrays.asList(filenames);
assertTrue(list.contains(filename1));
assertTrue(list.contains(filename2));
assertFalse(list.contains(filename3));
assertFalse(list.contains(filename4));
/* Get the most recent file. */
File lastModifiedFile = InternalStorage.lastModifiedFile(sAndroidFilesPath, filter);
/* Verify the most recent file. */
assertNotNull(lastModifiedFile);
assertEquals(filename2, lastModifiedFile.getName());
/* Read the most recent file. */
String actual = InternalStorage.read(lastModifiedFile);
/* Verify the contents of the most recent file. */
assertNotNull(actual);
assertEquals(contents2, actual.trim());
/* Delete the files to clean up. */
for (String filename : filenames) {
Log.i(TAG, "Deleting " + filename);
assertTrue(InternalStorage.delete(sAndroidFilesPath + filename));
}
/* Verify all the files are properly deleted. */
assertEquals(0, InternalStorage.getFilenames(sAndroidFilesPath, filter).length);
/* Verify invalid accesses. */
assertNull(InternalStorage.read("not-exist-filename"));
assertArrayEquals(new String[0], InternalStorage.getFilenames("not-exist-path", null));
assertNull(InternalStorage.lastModifiedFile("not-exist-path", null));
}
use of java.io.FilenameFilter in project mobile-center-sdk-android by Microsoft.
the class StorageHelperAndroidTest method tearDownClass.
@AfterClass
public static void tearDownClass() {
/* Clean up shared preferences. */
try {
for (SharedPreferencesTestData data : generateSharedPreferenceData()) {
String key = data.value.getClass().getCanonicalName();
PreferencesStorage.remove(key);
}
} catch (NoSuchMethodException ignored) {
/* Ignore exception. */
}
/* Clean up internal storage. */
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
return filename.endsWith(INTERNAL_STORAGE_TEST_FILE_EXTENSION);
}
};
String[] filenames = InternalStorage.getFilenames(sAndroidFilesPath, filter);
/* Delete the files to clean up. */
for (String filename : filenames) {
InternalStorage.delete(sAndroidFilesPath + filename);
}
InternalStorage.delete(sAndroidFilesPath);
/* Delete database. */
sContext.deleteDatabase("test-databaseStorage");
sContext.deleteDatabase("test-databaseStorageUpgrade");
sContext.deleteDatabase("test-putTooManyLogs");
sContext.deleteDatabase("test-databaseStorageScannerRemove");
sContext.deleteDatabase("test-databaseStorageScannerNext");
sContext.deleteDatabase("test-databaseStorageInMemoryDB");
}
use of java.io.FilenameFilter in project XobotOS by xamarin.
the class CacheManager method trimCacheIfNeeded.
static void trimCacheIfNeeded() {
assert !JniUtil.useChromiumHttpStack();
if (mDataBase.getCacheTotalSize() > CACHE_THRESHOLD) {
List<String> pathList = mDataBase.trimCache(CACHE_TRIM_AMOUNT);
int size = pathList.size();
for (int i = 0; i < size; i++) {
File f = new File(mBaseDir, pathList.get(i));
if (!f.delete()) {
Log.e(LOGTAG, f.getPath() + " delete failed.");
}
}
// remove the unreferenced files in the cache directory
final List<String> fileList = mDataBase.getAllCacheFileNames();
if (fileList == null)
return;
String[] toDelete = mBaseDir.list(new FilenameFilter() {
public boolean accept(File dir, String filename) {
if (fileList.contains(filename)) {
return false;
} else {
return true;
}
}
});
if (toDelete == null)
return;
size = toDelete.length;
for (int i = 0; i < size; i++) {
File f = new File(mBaseDir, toDelete[i]);
if (!f.delete()) {
Log.e(LOGTAG, f.getPath() + " delete failed.");
}
}
}
}
Aggregations