|
25 | 25 |
|
26 | 26 | import java.io.File; |
27 | 27 | import java.io.FileOutputStream; |
| 28 | +import java.io.IOException; |
28 | 29 | import java.io.OutputStream; |
29 | 30 | import java.lang.ref.WeakReference; |
30 | 31 | import java.text.SimpleDateFormat; |
@@ -85,36 +86,51 @@ public void changePassword(char[] password) throws SQLiteException { |
85 | 86 | } |
86 | 87 |
|
87 | 88 | private static void loadICUData(Context context, File workingDir) { |
88 | | - |
| 89 | + OutputStream out = null; |
| 90 | + ZipInputStream in = null; |
| 91 | + File icuDir = new File(workingDir, "icu"); |
| 92 | + File icuDataFile = new File(icuDir, "icudt46l.dat"); |
| 93 | + try { |
| 94 | + if(!icuDir.exists()) icuDir.mkdirs(); |
| 95 | + if(!icuDataFile.exists()) { |
| 96 | + in = new ZipInputStream(context.getAssets().open("icudt46l.zip")); |
| 97 | + in.getNextEntry(); |
| 98 | + out = new FileOutputStream(icuDataFile); |
| 99 | + byte[] buf = new byte[1024]; |
| 100 | + int len; |
| 101 | + while ((len = in.read(buf)) > 0) { |
| 102 | + out.write(buf, 0, len); |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + catch (Exception ex) { |
| 107 | + Log.e(TAG, "Error copying icu dat file", ex); |
| 108 | + if(icuDataFile.exists()){ |
| 109 | + icuDataFile.delete(); |
| 110 | + } |
| 111 | + throw new RuntimeException(ex); |
| 112 | + } |
| 113 | + finally { |
89 | 114 | try { |
90 | | - File icuDir = new File(workingDir, "icu"); |
91 | | - if(!icuDir.exists()) icuDir.mkdirs(); |
92 | | - File icuDataFile = new File(icuDir, "icudt46l.dat"); |
93 | | - if(!icuDataFile.exists()) { |
94 | | - ZipInputStream in = new ZipInputStream(context.getAssets().open("icudt46l.zip")); |
95 | | - in.getNextEntry(); |
96 | | - OutputStream out = new FileOutputStream(icuDataFile); |
97 | | - byte[] buf = new byte[1024]; |
98 | | - int len; |
99 | | - while ((len = in.read(buf)) > 0) { |
100 | | - out.write(buf, 0, len); |
101 | | - } |
102 | | - in.close(); |
103 | | - out.flush(); |
104 | | - out.close(); |
105 | | - } |
106 | | - } |
107 | | - catch (Exception e) { |
108 | | - Log.e(TAG, "Error copying icu data file", e); |
| 115 | + if(in != null){ |
| 116 | + in.close(); |
| 117 | + } |
| 118 | + if(out != null){ |
| 119 | + out.flush(); |
| 120 | + out.close(); |
| 121 | + } |
| 122 | + } catch (IOException ioe){ |
| 123 | + Log.e(TAG, "Error in closing streams IO streams after expanding ICU dat file", ioe); |
| 124 | + throw new RuntimeException(ioe); |
109 | 125 | } |
| 126 | + } |
110 | 127 | } |
111 | 128 |
|
112 | | - public static void loadLibs (Context context) { |
| 129 | + public static synchronized void loadLibs (Context context) { |
113 | 130 | loadLibs(context, context.getFilesDir()); |
114 | 131 | } |
115 | 132 |
|
116 | | - public static void loadLibs (Context context, File workingDir) |
117 | | - { |
| 133 | + public static synchronized void loadLibs (Context context, File workingDir) { |
118 | 134 | System.loadLibrary("stlport_shared"); |
119 | 135 | System.loadLibrary("sqlcipher_android"); |
120 | 136 | System.loadLibrary("database_sqlcipher"); |
|
0 commit comments