 Issue 29424615:
  Issue 4231 - Fix unstable FilterEngineTest.testSetRemoveFilterChangeCallback  (Closed)
    
  
    Issue 29424615:
  Issue 4231 - Fix unstable FilterEngineTest.testSetRemoveFilterChangeCallback  (Closed) 
  | Index: libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidFileSystem.java | 
| diff --git a/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidFileSystem.java b/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidFileSystem.java | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..ba6141e6ef3bff0d3609ba006dfeb69591ee96fb | 
| --- /dev/null | 
| +++ b/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidFileSystem.java | 
| @@ -0,0 +1,150 @@ | 
| +/* | 
| + * This file is part of Adblock Plus <https://adblockplus.org/>, | 
| + * Copyright (C) 2006-2017 eyeo GmbH | 
| + * | 
| + * Adblock Plus is free software: you can redistribute it and/or modify | 
| + * it under the terms of the GNU General Public License version 3 as | 
| + * published by the Free Software Foundation. | 
| + * | 
| + * Adblock Plus is distributed in the hope that it will be useful, | 
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| + * GNU General Public License for more details. | 
| + * | 
| + * You should have received a copy of the GNU General Public License | 
| + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 
| + */ | 
| + | 
| +package org.adblockplus.libadblockplus.android; | 
| + | 
| +import org.adblockplus.libadblockplus.AdblockPlusException; | 
| +import org.adblockplus.libadblockplus.FileSystem; | 
| +import org.adblockplus.libadblockplus.FileSystemUtils; | 
| + | 
| +import java.io.File; | 
| +import java.io.FileNotFoundException; | 
| +import java.io.IOException; | 
| + | 
| +/** | 
| + * AndroidFileSystem is inefficient for production files routines | 
| + * as C++ streams can't pass JNI layer and be converted into Java streams and vice versa. | 
| + * | 
| + * So in case of any stream routines full stream content is read in either C++ or Java side | 
| + * and it's being passed as string though JNI layer | 
| + * | 
| + * AndroidFileSystem is meant to be used in tests mostly | 
| + */ | 
| +public class AndroidFileSystem extends FileSystem | 
| +{ | 
| + private File basePath; | 
| + | 
| + public File getBasePath() | 
| + { | 
| + return basePath; | 
| + } | 
| + | 
| + public AndroidFileSystem() | 
| + { | 
| + } | 
| + | 
| + /* | 
| + * Sets the base path, all paths are considered relative to it. | 
| + * @param basePath base path | 
| + */ | 
| + public AndroidFileSystem(File basePath) | 
| + { | 
| + this(); | 
| 
diegocarloslima
2017/04/28 13:23:53
Recapping our discussion here from the old code re
 
anton
2017/05/22 13:04:38
AndroidFileSystem can be used without passing `bas
 | 
| + this.basePath = basePath; | 
| + } | 
| + | 
| + private File buildFullPath(String path) | 
| + { | 
| + return basePath != null | 
| + ? new File(basePath, path) | 
| + : new File(path); | 
| + } | 
| + | 
| + @Override | 
| + public String read(String path) | 
| + { | 
| + File file = buildFullPath(path); | 
| + if (!file.exists()) | 
| + { | 
| + return null; | 
| + } | 
| + | 
| + try | 
| + { | 
| + return FileSystemUtils.readFile(file); | 
| + } | 
| + catch (FileNotFoundException e) | 
| + { | 
| + throw new AdblockPlusException(e); | 
| + } | 
| + } | 
| + | 
| + @Override | 
| + public void write(String path, String data) | 
| + { | 
| + File file = buildFullPath(path); | 
| + if (file.exists()) | 
| + { | 
| + file.delete(); | 
| + } | 
| + | 
| + try | 
| + { | 
| + FileSystemUtils.writeFile(file, data); | 
| + } | 
| + catch (IOException e) | 
| + { | 
| + throw new AdblockPlusException(e); | 
| + } | 
| + } | 
| + | 
| + @Override | 
| + public void move(String fromPath, String toPath) | 
| + { | 
| + File fullFromFile = buildFullPath(fromPath); | 
| + try | 
| + { | 
| + String data = FileSystemUtils.readFile(fullFromFile); | 
| + write(toPath, data); | 
| + remove(fromPath); | 
| + } | 
| + catch (FileNotFoundException e) | 
| + { | 
| + throw new AdblockPlusException(e); | 
| + } | 
| + } | 
| + | 
| + @Override | 
| + public void remove(String path) | 
| + { | 
| + File file = buildFullPath(path); | 
| + if (file.exists()) | 
| + { | 
| + file.delete(); | 
| + } | 
| + } | 
| + | 
| + @Override | 
| + public StatResult stat(String path) | 
| + { | 
| + File file = buildFullPath(path); | 
| + return new StatResult( | 
| + file.exists(), | 
| + file.isDirectory(), | 
| + file.isFile(), | 
| + file.lastModified()); | 
| + } | 
| + | 
| + @Override | 
| + public String resolve(String path) | 
| + { | 
| + String fullPath = buildFullPath(path).getAbsolutePath(); | 
| + return basePath != null | 
| + ? fullPath.substring(basePath.getAbsolutePath().length()) | 
| + : fullPath; | 
| + } | 
| 
sergei
2017/05/22 12:09:07
I think it inconsistent with C++ version where the
 
anton
2017/05/22 13:04:38
if it's created with `basePath` argument (see ctor
 
sergei
2017/05/22 13:51:04
I think that `resolve` method had been introduced
 
anton
2017/05/23 05:46:47
You did not get the idea that was introduced by an
 
sergei
2017/05/23 08:08:19
It was clear and I think that it's incorrect.
I th
 
anton
2017/05/23 11:11:18
Can't get your point. All the paths are considered
 
sergei
2017/05/23 13:00:37
In my opinion the aim of FileSystem interface is t
 | 
| +} |