title: Why do gzip of Java and Go get different results?
body: <p>Firstly, my Java version:</p>
  
  <pre><code>string str = "helloworld";
  ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(str.length());
  GZIPOutputStream localGZIPOutputStream = new GZIPOutputStream(localByteArrayOutputStream);
  localGZIPOutputStream.write(str.getBytes("UTF-8"));
  localGZIPOutputStream.close();
  localByteArrayOutputStream.close();
  for(int i = 0;i &lt; localByteArrayOutputStream.toByteArray().length;i ++){
      System.out.println(localByteArrayOutputStream.toByteArray()[i]);
  }
  </code></pre>
  
  <p>and output is:</p>
  
  <p>31
  -117
  8
  0
  0
  0
  0
  0
  0
  0
  -53
  72
  -51
  -55
  -55
  47
  -49
  47
  -54
  73
  1
  0
  -83
  32
  -21
  -7
  10
  0
  0
  0</p>
  
  <p>Then the Go version:</p>
  
  <pre><code>var gzBf bytes.Buffer
  gzSizeBf := bufio.NewWriterSize(&amp;gzBf, len(str))
  gz := gzip.NewWriter(gzSizeBf)
  gz.Write([]byte(str))
  gz.Flush()
  gz.Close()
  gzSizeBf.Flush()
  GB := (&amp;gzBf).Bytes()
  for i := 0; i &lt; len(GB); i++ {
      fmt.Println(GB[i])
  }
  </code></pre>
  
  <p>output:</p>
  
  <p>31
  139
  8
  0
  0
  9
  110
  136
  0
  255
  202
  72
  205
  201
  201
  47
  207
  47
  202
  73
  1
  0
  0
  0
  255
  255
  1
  0
  0
  255
  255
  173
  32
  235
  249
  10
  0
  0
  0</p>
  
  <p>Why?</p>
  
  <p>I thought it might be caused by different byte reading methods of those two languages at first. But I noticed that 0 can never convert to 9. And the sizes of <code>[]byte</code> are different.</p>
  
  <p>Have I written wrong code? Is there any way to make my Go program get the same output as the Java program?</p>
  
  <p>Thanks!</p>