Android Question HttpJob and gzip

LucaMs

Expert
Licensed User
Longtime 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
Longtime 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
Longtime 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

DonManfred

Expert
Licensed User
Longtime 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
Longtime 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
Longtime 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
Top