gzipinputstream

PHP's gzuncompress function in Java?

我的未来我决定 提交于 2019-12-11 10:47:18
问题 I'm compressing a string using PHP's gzcompress() function: http://us2.php.net/manual/en/function.gzcompress.php I'd like to take the output from the PHP compression function and decompress the string in Java. Can anyone send me down the right path? Thanks so much! 回答1: have a look to GZIPInputStream: GZIPInputStream gzipInputStream = new GZIPInputStream(new FileInputStream(inFilename)); byte[] buf = new byte[1024]; int len; while ((len = gzipInputStream.read(buf)) > 0) { // buf contains

truncated output from GZIPInputStream on Android

妖精的绣舞 提交于 2019-12-11 01:54:23
问题 I must be doing something really wrong. Running following code on Android it produces truncated file (_items_) without any exceptions or problems in the log. Running the same code with OpenJDK 7 it decompresses the file correctly. try { final InputStream fis = new GZIPInputStream(new FileInputStream("/storage/sdcard/_items")); try { final FileOutputStream fos = new FileOutputStream("/storage/sdcard/_items_"); try { final byte[] buffer = new byte[1024]; int n; while ((n = fis.read(buffer)) !=

Is this a bug in the Java GZipInputStream class?

a 夏天 提交于 2019-12-08 16:51:26
问题 I noticed that some of my gzip decoding code seemed to be failing to detect corrupted data. I think that I have traced the problem to the Java GZipInputStream class. In particular, it seems that when you read the entire stream with a single 'read' call, corrupted data doesn't trigger an IOException. If you read the stream in 2 or more calls on the same corrupted data, then it does trigger an exception. I wanted to see what the community here thought before I consider filing a bug report. EDIT

How do I get the InputStream of decompressed data from an InputStream of GZIPed data?

风流意气都作罢 提交于 2019-12-08 16:09:07
问题 I call a service which returns a gzipped file. I have the data as an InputStream (courtesy of javax.activation.DataHandler.getInputStream(); ) from the response. What I would like to do is, without writing anything to disk, get an InputStream of the decompressed data in the file that is in the archive. The compressed file in this case is an xml document that I am trying to unmarshal using javax.xml.bind.Unmarshaller which takes an InputStream. I'm currently trying to write the InputStream to

GZIPInputStream is prematurely closed when reading from s3

删除回忆录丶 提交于 2019-12-08 08:10:42
问题 new BufferedReader(new InputStreamReader( new GZIPInputStream(s3Service.getObject(bucket, objectKey).getDataInputStream()))) creates Reader that returns null from readLine() after ~100 lines if file is greater then several MB. Not reproducible on gzip files less then 1 MB. Does anybody knows how to handle this? 回答1: From the documentation of BufferedReader#readLine() : Returns: A String containing the contents of the line, not including any line-termination characters, or null if the end of

How to read compressed HTML page with Content-Encoding : gzip

前提是你 提交于 2019-12-07 05:32:17
问题 I request a web page that sends a Content-Encoding: gzip header, but got stuck how to read it.. My code: try { URLConnection connection = new URL("http://jquery.org").openConnection(); String html = ""; BufferedReader in = null; connection.setReadTimeout(10000); in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null){ html+=inputLine+"\n"; } in.close(); System.out.println(html); System.exit(0); } catch

C# to Java: Base64String, MemoryStream, GZipStream

十年热恋 提交于 2019-12-06 03:06:53
问题 I have a Base64 string that's been gzipped in .NET and I would like to convert it back into a string in Java. I'm looking for some Java equivalents to the C# syntax, particularly: Convert.FromBase64String MemoryStream GZipStream Here's the method I'd like to convert: public static string Decompress(string zipText) { byte[] gzipBuff = Convert.FromBase64String(zipText); using (MemoryStream memstream = new MemoryStream()) { int msgLength = BitConverter.ToInt32(gzipBuff, 0); memstream.Write

C# to Java: Base64String, MemoryStream, GZipStream

不羁岁月 提交于 2019-12-04 07:14:15
I have a Base64 string that's been gzipped in .NET and I would like to convert it back into a string in Java. I'm looking for some Java equivalents to the C# syntax, particularly: Convert.FromBase64String MemoryStream GZipStream Here's the method I'd like to convert: public static string Decompress(string zipText) { byte[] gzipBuff = Convert.FromBase64String(zipText); using (MemoryStream memstream = new MemoryStream()) { int msgLength = BitConverter.ToInt32(gzipBuff, 0); memstream.Write(gzipBuff, 4, gzipBuff.Length - 4); byte[] buffer = new byte[msgLength]; memstream.Position = 0; using

GZIPInputStream closes prematurely when decompressing HTTPInputStream

狂风中的少年 提交于 2019-12-03 16:59:31
Question See updated question in edit section below I'm trying to decompress large (~300M) GZIPed files from Amazon S3 on the fly using GZIPInputStream but it only outputs a portion of the file; however, if I download to the filesystem before decompression then GZIPInputStream will decompress the entire file. How can I get GZIPInputStream to decompress the entire HTTPInputStream and not just the first part of it? What I've Tried see update in the edit section below I suspected a HTTP problem except that no exceptions are ever thrown, GZIPInputStream returns a fairly consistent chunk of the

Wrapping BodySubscriber<InputStream> in GZIPInputStream leads to hang

二次信任 提交于 2019-12-01 06:27:04
I'm using the new java.net.http classes to handle asynchronous HTTP request+response exchanges, and I'm trying to find a way to have the BodySubscriber handle different encoding types such as gzip. However, mapping a BodySubsriber<InputStream> so that the underlying stream is wrapped by a GZIPInputStream (when "Content-Encoding: gzip" is found in the response header) leads to a hang. No exceptions, just a total cessation of activity. The code which maps the BodySubscriber looks like this: private HttpResponse.BodySubscriber<InputStream> gzippedBodySubscriber( HttpResponse.ResponseInfo