When I try to decompress my .gz file and overwrite the db file I get the Unknown format (magic number 5153). Here is my code for the decompression and overwrite.
InputStream fIn = c.getAssets().open("MyContacts");
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
FileOutputStream myOutput = new FileOutputStream(outFileName);
GZIPInputStream gz = new GZIPInputStream(fIn);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[10246];
int length;
while ((length = gz.read(buffer, 0,buffer.length)) != -1){
myOutput.write(buffer, 0, length);
}
//Close the streams
gz.close();
myOutput.flush();
myOutput.close();
fIn.close();
It is very likely that the asset is being decompressed on the fly before it gets to your code. The aapt has its own strong ideas about how to handle compressed asset files. The behavior depends in part (in ways that are undocumented as far as I can tell) on the asset file names. You are much better off placing uncompressed files in the assets directory and letting aapt compress them for you. It generally does an excellent job and relieves you of having to worry about this kind of thing.
See the blog post that zapl’s comment points to.