title: Uncompressing Strings to Strings with Snappy in Java
body: <p>I am trying to compress <code>Strings</code>, writing them in files (as <code>Strings</code>) and uncompressing those files.
  For compressing, I have written this function:</p>
  
  <pre><code>public static String compress(String s) throws IOException {
      byte[] by = Snappy.compress(s, StandardCharsets.UTF_8);
      return new String(by, StandardCharsets.UTF_8);
  }
  </code></pre>
  
  <p>and then, for uncompressing,</p>
  
  <pre><code>public static String uncompress(String s) throws IOException {
      byte[] by = s.getBytes(StandardCharsets.UTF_8);
      return Snappy.uncompressString(by, StandardCharsets.UTF_8);
  }
  </code></pre>
  
  <p>But I get <code>FAILED_TO_UNCOMPRESS(5)</code>, and by looking at the data, <code>Snappy.compress(s, StandardCharsets.UTF_8)</code> does not give the same result as applying <code>getBytes(StandardCharsets.UTF_8)</code> to the data compressed with my <code>compress</code> function.
  Do you know why? And how I could compress and uncompress to <code>Strings</code>? Thanks!</p>