Support UTF-8 BOM - closes #141

This commit is contained in:
ligi 2017-02-26 21:01:56 +01:00
parent 0b7ab6dfe0
commit 76a71dd87c
No known key found for this signature in database
GPG key ID: 8E81894010ABF23D

View file

@ -3,17 +3,14 @@ package org.ligi.passandroid.model;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import com.ibm.icu.text.CharsetDetector;
import com.ibm.icu.text.CharsetMatch;
import org.ligi.passandroid.App;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import org.ligi.passandroid.App;
@VisibleForTesting
public class AppleStylePassTranslation extends HashMap<String, String> {
@ -63,6 +60,12 @@ public class AppleStylePassTranslation extends HashMap<String, String> {
dataInputStream.readFully(fileData);
dataInputStream.close();
if (fileData[0] == (byte) 0xEF && fileData[1] == (byte) 0xBB && fileData[2] == (byte) 0xBF) {
final byte[] crop = new byte[fileData.length - 3];
System.arraycopy(fileData, 3, crop, 0, crop.length);
return new String(crop, "utf-8");
}
final CharsetMatch match = new CharsetDetector().setText(fileData).detect();
if (match != null) try {