Android Question HttpJob and gzip

LucaMs

Expert
Licensed User
It is a question in the Italian forum. http://www.basic4ppc.com/android/forum/threads/httpjob-e-gzip.39937/

I have tried to help by creating the app that I am attaching but it does not work.

AsyncUnGzip do not "creates" any files. I guess use File.WriteString is wrong and that the file type is not recognized as Gzip.

Suggestions? Thanks
 

Attachments

  • LM_Demo.zip
    11.9 KB · Views: 203

LucaMs

Expert
Licensed User
Binary data cannot be converted to a string.
B4X:
File.WriteString(File.DirDefaultExternal, "demo.gzip", Job.GetString)

See the code I posted here: Download image or file from a website


Many thanks, Erel.

I tried so:
B4X:
Sub JobDone(job As HttpJob)
  If job.Success Then
    Dim out As OutputStream = File.OpenOutput(File.DirDefaultExternal, "demo.gzip", False)
    File.Copy2(job.GetInputStream, out)
    out.Close '<------ very important
  Else
    Log("Error: " & job.ErrorMessage)
  End If
  job.Release
    Arc.AsyncUnGzip(File.DirDefaultExternal, "demo.gzip", File.DirDefaultExternal, "Unzipped")
End Sub

Sub Unzipped_UnGzipDone(CompletedWithoutError As Boolean)
Log("Unzipped")
    Dim lst As List
    lst = File.ListFiles(File.DirDefaultExternal)
    For i = 0 To lst.Size - 1
        Log(lst.Get(i))
    Next
    If File.Exists(File.DirDefaultExternal, "demo") Then
        Log("filling edittext")
        Label1.Text = File.ReadString(File.DirDefaultExternal, "demo")
    End If
End Sub

The EditText does not show anything, but the log confirms the execution (Log ("filling EditText")).

I tried to open the file with 7zip and according to it the file is corrupted.
 
Upvote 0

LucaMs

Expert
Licensed User
You're right, but it would be the same thing, at that time Success was True, in fact the file was created.
However, to be sure, I try anyway.
 
Upvote 0

LucaMs

Expert
Licensed User
B4X:
Sub JobDone(job As HttpJob)
  If job.Success Then
    Dim out As OutputStream = File.OpenOutput(File.DirDefaultExternal, "demo.gzip", False)
    File.Copy2(job.GetInputStream, out)
    out.Close '<------ very important
        Arc.AsyncUnGzip(File.DirDefaultExternal, "demo.gzip", File.DirDefaultExternal, "Unzipped")
  Else
    Log("Error: " & job.ErrorMessage)
  End If
  job.Release
End Sub

same result as #4
 
Upvote 0

DonManfred

Expert
Licensed User
what says the log output of

B4X:
For i = 0 To lst.Size - 1
    Log(lst.Get(i))
Next
?

Edit: Doesnt matter... The file exists when you filling logmessage is shown...

Can you upload your demo.gz?
 
Upvote 0

LucaMs

Expert
Licensed User
Not, all this is for a member, not for me; but i can ask to him :)

(Probably not, because it is a file that comes from a site and he explained that before did not come zipped)
 
Upvote 0

DonManfred

Expert
Licensed User
Do the member have control over the webside the data came from? Can he disable the compression?
I´ve had a look at the code above...

On webbrowser it is showed correctly (the json).
But the Archiver seems to be incompatible with the file saved in JobDone. Maybe @Informatix can say something about the ability to decompress a GZIP-Compressed-HTML-Response!?
 
Upvote 0

LucaMs

Expert
Licensed User
He does not have access to the file, can just download it.

He is able to download it using VB.Net and pretty much the same instructions, then something is wrong, probably in the library Archiver or, less likely, in the download and save the file.
 
Upvote 0

LucaMs

Expert
Licensed User
I do not know exactly.

That text, once downloaded, is so in the Webview, but I putting it in a label.text, it contains strange characters, instead.

The Italian forum member claims that it is zipped in GZip format.

I used the asynchronous method of library Archiver and the project returns an error (even 7zip says the file is corrupted). Using the synchronous method, the error is EOF Exception, different from the first.

His last post:
Hello Luca, there's a file, you do realize that I had the same result using vb.net; I solved it by adding the highlighted code:
B4X:
Dim srequest As HttpWebRequest = HttpWebRequest.Create(url)
-->srequest.AutomaticDecompression = DecompressionMethods.GZip Or DecompressionMethods.Deflate<--
Dim sresponse As HttpWebResponse = srequest.GetResponse
Dim reader As StreamReader = New StreamReader(sresponse.GetResponseStream)
Dim s As String
s = reader.ReadToEnd

that: "Or DecompressionMethods.Deflate" ?

found: http://msdn.microsoft.com/en-us/library/system.net.decompressionmethods(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

and: http://stackoverflow.com/questions/10214374/which-algorithm-is-using-in-standard-zip
 
Last edited:
Upvote 0

Informatix

Expert
Licensed User
Thanks, but, in that case, his VB.Net code should not work.

I'm thinking that he's not so sure ;)
This file format is not recognized by WinRar and 7z, so I strongly doubt that's an archive. Maybe the file contains an archived content, but it has to be decrypted/decoded before.
 
Upvote 0
Top