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/>.
*
*/
package org.kiwix.kiwixmobile.core.main;
package org.kiwix.kiwixmobile.core.main
import android.content.Context;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import android.content.Context
import java.io.BufferedReader
import java.io.IOException
public class FileReader {
public String readFile(String filePath, Context context) {
try {
StringBuilder buf = new StringBuilder();
InputStream json = context.getAssets().open(filePath);
BufferedReader in =
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 "";
}
class FileReader {
fun readFile(filePath: String?, context: Context): String = try {
context.assets.open(filePath)
.bufferedReader()
.use(BufferedReader::readText)
} catch (e: IOException) {
"".also { e.printStackTrace() }
}
}