Android4.4.4 gzipoutputstream Error: Stream error

Source: Internet
Author: User

Gzip compression is done using the gziputils method provided by the user on the Android 4.4.4 machine, but will always error stream error. Error location:

  1. Public Static void Compress (InputStream is, OutputStream OS)
  2. throws Exception {
  3. Gzipoutputstream Gos = new gzipoutputstream (OS);
  4.         < span class= "keyword" style= "Color:rgb (127,0,85); Font-weight:bold ">int  count;  
  5.         < span class= "keyword" style= "Color:rgb (127,0,85); Font-weight:bold ">byte  data[] = new  byte [buffer];  
  6.         < span class= "keyword" style= "Color:rgb (127,0,85); Font-weight:bold ">while   ((Count = is.read (Data, 0 ,  buffer)"  != -1 )  {  
  7. Gos.write (data, 0, Count);
  8. }
  9. gos.finish ();
  10. Gos.flush ();
  11. Gos.close ();
  12. }

But other Android versions of machine debugging are no problem. Baidu also has no related issues, just said the flow of the opening and closing sequence may conflict.

Because the method I'm actually using is compress (byte[] data), I think Flush (), and close () may be the cause of the problem.

  1. public   Static  byte []  Compress (byte [] data]  < span class= "keyword" style= "Color:rgb (127,0,85); Font-weight:bold ">throws  exception {  
  2. Bytearrayinputstream Bais = new bytearrayinputstream (data);
  3. Bytearrayoutputstream BAOs = new bytearrayoutputstream ();
  4. //Compression
  5. compress (Bais, BAOs);
  6. byte [] output = Baos.tobytearray ();
  7. Baos.flush ();
  8. Baos.close ();
  9. Bais.close ();
  10. return output;
  11. }

The flush () and close () method calls under the Compress (InputStream is, OutputStream OS) function are commented out, then run, ok!

======================

The individual is not a Java master, to here will not continue to study, just look at the Gzipoutputstream documentation, this class only the finish () and write () method,flush () and close () The methods are all parent but not shown in this class, so it is sufficient to invoke the finish () method of the Gzipoutputstream object. (Personal surface Understanding, if there are confusing, please forgive me!) )


Android4.4.4 gzipoutputstream Error: Stream error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.