Merge pull request #2305 from gouri-panda/filereader_java_file_to_kotlin

Convert FileReader.java file to kotlin #2306
This commit is contained in:
Seán Mac Gillicuddy 2020-08-21 09:37:27 +01:00 committed by GitHub
commit a5f3e74c83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,31 +15,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package org.kiwix.kiwixmobile.core.main; package org.kiwix.kiwixmobile.core.main
import android.content.Context; import android.content.Context
import java.io.BufferedReader; import java.io.BufferedReader
import java.io.InputStream; import java.io.IOException
import java.io.InputStreamReader;
public class FileReader { class FileReader {
fun readFile(filePath: String?, context: Context): String = try {
public String readFile(String filePath, Context context) { context.assets.open(filePath)
try { .bufferedReader()
StringBuilder buf = new StringBuilder(); .use(BufferedReader::readText)
InputStream json = context.getAssets().open(filePath); } catch (e: IOException) {
BufferedReader in = "".also { e.printStackTrace() }
new BufferedReader(new InputStreamReader(json, "UTF-8"));
String str;
while ((str = in.readLine()) != null) {
buf.append(str);
}
in.close();
return buf.toString();
} catch (Exception e) {
return "";
}
} }
} }