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:
- Public Static void Compress (InputStream is, OutputStream OS)
- throws Exception {
- Gzipoutputstream Gos = new gzipoutputstream (OS);
- < span class= "keyword" style= "Color:rgb (127,0,85); Font-weight:bold ">int count;
- < span class= "keyword" style= "Color:rgb (127,0,85); Font-weight:bold ">byte data[] = new byte [buffer];
- < span class= "keyword" style= "Color:rgb (127,0,85); Font-weight:bold ">while ((Count = is.read (Data, 0 , buffer)" != -1 ) {
- Gos.write (data, 0, Count);
- }
- gos.finish ();
- Gos.flush ();
- Gos.close ();
- }
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.
- public Static byte [] Compress (byte [] data] < span class= "keyword" style= "Color:rgb (127,0,85); Font-weight:bold ">throws exception {
- Bytearrayinputstream Bais = new bytearrayinputstream (data);
- Bytearrayoutputstream BAOs = new bytearrayoutputstream ();
- //Compression
- compress (Bais, BAOs);
- byte [] output = Baos.tobytearray ();
- Baos.flush ();
- Baos.close ();
- Bais.close ();
- return output;
- }
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