I am writing a PHP tunnel to connect to MySQL, as well as a B4A class to create a dataset that will connect to the tunnel and manage (Query, Insert, Delete, Update) the DB. Will post the script and the class once I am near a working copy.
In the PHP script there is a PrintResult function to echo back the data. I am trying to implement a compress function to keep data transmitted to device at a minimum rate. Here it is:
I am using gzencode to encode data, and then base64_encode to ensure characters are transmitable over the net. Lines:
$res = gzencode($res, -1, FORCE_DEFLATE);
$res = base64_encode($res);
In B4A I am using HTTPUtils2 where in JobDone I have the following:
I keep getting an java.IO.IOException in
decompressed = cs.DecompressBytes(compressed, "zlib")
I don't know what to check to find my error.
In the PHP script there is a PrintResult function to echo back the data. I am trying to implement a compress function to keep data transmitted to device at a minimum rate. Here it is:
B4X:
public function PrintResult($compress = 0) {
$res = array();
$res["tunnelversion"] = tunnelversion;
$res["query"] = $this->Query;
$res["errornumber"] = $this->ErrorNumber;
$res["errordescr"] = $this->ErrorDescr;
$res["serverversion"] = $this->ServerInfo;
$res["affectedrows"] = $this->AffecteRows;
$res["lastinsert_id"] = $this->InsertID;
$res["fieldcount"] = $this->FieldCount;
$res["fieldsdescr"] = $this->FieldsDescription;
$res["rows"] = $this->Rows;
utf8_encode_array($res);
$res = json_encode($res, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
if ($compress)
{
$res = gzencode($res, -1, FORCE_DEFLATE);
$res = base64_encode($res);
}
echo $res;
}
I am using gzencode to encode data, and then base64_encode to ensure characters are transmitable over the net. Lines:
$res = gzencode($res, -1, FORCE_DEFLATE);
$res = base64_encode($res);
In B4A I am using HTTPUtils2 where in JobDone I have the following:
B4X:
strResult = Job.GetString
If MySQLConnection.Compress = 1 Then
Dim cs As CompressedStreams
Dim compressed(), decompressed() As Byte
Dim B64 As Base64
Log(strResult.Length)
compressed = B64.DecodeStoB(strResult)
Log(compressed.Length)
decompressed = cs.DecompressBytes(compressed, "zlib")
strResult = BytesToString(decompressed, 0, decompressed.Length, "UTF8")
End If
I keep getting an java.IO.IOException in
decompressed = cs.DecompressBytes(compressed, "zlib")
B4X:
clsdbmysqlutils_jobdone (B4A line: 121)
decompressed = cs.DecompressBytes(compressed, "gzip")
java.io.IOException
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:176)
at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:167)
at java.io.InputStream.read(InputStream.java:163)
at anywheresoftware.b4a.objects.streams.File.Copy2(File.java:336)
at anywheresoftware.b4a.randomaccessfile.CompressedStreams.DecompressBytes(CompressedStreams.java:135)
at anywheresoftware.b4a.samples.mysql.clsdbmysqlutils._jobdone(clsdbmysqlutils.java:674)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.keywords.Common$4.run(Common.java:885)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.util.zip.DataFormatException: data error
at java.util.zip.Inflater.inflateImpl(Native Method)
at java.util.zip.Inflater.inflate(Inflater.java:228)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:157)
... 18 more
java.io.IOException
I don't know what to check to find my error.