Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3be9eb46 authored by Raph Levien's avatar Raph Levien Committed by Android Git Automerger
Browse files

am 401aa9d8: Merge "Clean up Hyphenator file reading" into mnc-dev

* commit '401aa9d8':
  Clean up Hyphenator file reading
parents d8c2bbcf 401aa9d8
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -21,9 +21,10 @@ import com.android.internal.annotations.GuardedBy;
import android.annotation.Nullable;
import android.util.Log;

import libcore.io.IoUtils;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.HashMap;
import java.util.Locale;

@@ -42,9 +43,9 @@ public class Hyphenator {
    private final static Object sLock = new Object();

    @GuardedBy("sLock")
    static HashMap<Locale, Hyphenator> sMap = new HashMap<Locale, Hyphenator>();
    final static HashMap<Locale, Hyphenator> sMap = new HashMap<Locale, Hyphenator>();

    private long mNativePtr;
    final private long mNativePtr;

    private Hyphenator(long nativePtr) {
        mNativePtr = nativePtr;
@@ -90,18 +91,14 @@ public class Hyphenator {
        String patternFilename = "hyph-"+languageTag.toLowerCase(Locale.US)+".pat.txt";
        File patternFile = new File(getSystemHyphenatorLocation(), patternFilename);
        try {
            RandomAccessFile rf = new RandomAccessFile(patternFile, "r");
            byte[] buf = new byte[(int)rf.length()];
            rf.read(buf);
            rf.close();
            String patternData = new String(buf);
            String patternData = IoUtils.readFileAsString(patternFile.getAbsolutePath());
            long nativePtr = StaticLayout.nLoadHyphenator(patternData);
            return new Hyphenator(nativePtr);
        } catch (IOException e) {
            Log.e(TAG, "error loading hyphenation " + patternFile, e);
        }
            return null;
        }
    }

    private static File getSystemHyphenatorLocation() {
        return new File("/system/usr/hyphen-data");