Android:ZIP从base 64编码的字符串解压缩

时间:2017-08-24 10:55:32

标签: c# android soap unzip ksoap2

我从C#SOAP Web服务接收.zip文件时遇到问题。服务器上的文件是正确的(我可以解压缩)。我正在将它作为基础64字符串打磨,但当我在Android应用程序中将其转换回来并尝试解压缩时,我正在

  

java.util.zip.ZipException:无效的条目压缩大小(预期4294967295,但得到74274字节);

public static string FileToBase64String(string filename, string GUID) { string output; try { byte[] AsBytes = File.ReadAllBytes(filename); output = Convert.ToBase64String(AsBytes); } catch (Exception e) { ExceptionHandling.HandleError(e, "Zapis pliku " + filename + ". Metoda: [FileToBase64String]", GUID); //output = e.ToString(); throw; } return output; } 中只有一个文件,并且代码在具有android<的手机上正常运行7.0。

关于问题可能是什么的任何想法?

这是我要转换为base 64字符串的C#代码:

            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            String result = response.toString();

            byte[] resultDecodedBase64Bytes = android.util.Base64.decode(result, android.util.Base64.DEFAULT);

            byte[] newDBFileBytes = unZipDBFromBytes(resultDecodedBase64Bytes);


public byte[] unZipDBFromBytes(byte[] bytes) {

    ByteArrayInputStream bis = null;
    ZipInputStream zis = null;
    ZipEntry ze = null;
    ByteArrayOutputStream output = null;
    try {
        bis = new ByteArrayInputStream(bytes);
        zis = new ZipInputStream(bis);
        ze = zis.getNextEntry();

        boolean isDbFile = false;
        while (ze != null) {
            String fileName = ze.getName();
            if (fileName.equalsIgnoreCase(Engine.DATABASE_FILENAME)) {
                output = new ByteArrayOutputStream();
                int data = 0;
                while ((data = zis.read()) != -1) {
                    output.write(data);
                }
                isDbFile = true;

            }
            if (isDbFile) {
                ze = null;

            }

        }

        if (output != null) {
            return output.toByteArray();
        } else {
            return null;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    } finally {

        try {
            if (zis != null) {
                zis.closeEntry();
                zis.close();
            }

            if (output != null)
                output.close();
            if (bis != null)
                bis.close();
        } catch (IOException e) {
        }
    }

}

这是我的Android代码:

function Get-Greeting
    {
    $Hour = (Get-Date).TimeOfDay.Hours
    if($Hour –ge 0 –and $Hour –lt 12)

    {
        $greet = “Good Morning give me a coffee !!”
    }
    elseif($Hour –ge 12 –and $Hour –lt 16)
    {
        $greet = “Good Afternoon How is the weather today?”
    }
    else
    {
        $greet = “Good Evening sir, want to sip a tea?”
    }

    $Username = $env:USERNAME

    return $(“$greet , You have logged in as User, $Username” )
    }
        enter code here

0 个答案:

没有答案