Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the Android version, you should close <code>bos</code> <em>after</em> you close <code>gz</code>.</p> <p>Also, this line in <code>compressString</code> may give you problems:</p> <pre><code>byte b[] = str.getBytes(); </code></pre> <p>That will convert the characters to bytes using the default encoding on the device, which is almost certainly not UTF-8. The .NET version, on the other hand, is using UTF8. In Android, try this instead:</p> <pre><code>byte b[] = str.getBytes("UTF-8"); </code></pre> <p>EDIT: On further looking at your code, I suggest that you rewrite it like this:</p> <pre><code>byte b[] = str.getBytes("UTF-8"); GZIPOutputStream gz = new GZIPOutputStream(bos); gz.write(b, 0, b.length); gz.finish(); gz.close(); bos.close(); </code></pre> <p>The changes are: use UTF-8 to encode characters; use the default internal buffer size for the GZIPOutputStream; call <code>gz.close()</code> before calling <code>bos.close()</code> (the latter probably isn't even needed); and call <code>gz.finish()</code> before calling <code>gz.close()</code>.</p> <p>EDIT 2:</p> <p>Okay, I should have realized before what's going on. The GZIPOutputStream class is, in my opinion, a stupid design. It has no way to define the compression you want and the default compression is set to none. You need to subclass it and override the default compression. The easiest way is to do this:</p> <pre><code>GZIPOutputStream gz = new GZIPOutputStream(bos) { { def.setLevel(Deflater.BEST_COMPRESSION); } }; </code></pre> <p>That will reset the internal deflator that GZIP uses to give the best compression. (By the way, in case you aren't familiar with it, the syntax I'm using here is called an <a href="http://download.oracle.com/javase/tutorial/java/javaOO/initial.html" rel="nofollow">instance initializer block</a>.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload