我有一个Android应用程序,我正在尝试将图片发送到服务器.我使用Base64编码做到了这一点并且效果很好,但是在发送之前对图片进行编码需要太多的内存(和时间).
我试图将Android应用程序剥离到它只是简单地发送字节数组并且不会使用任何类型的编码方案,因此它将尽可能多地节省内存和CPU周期.
这就是我想要Android代码的样子:
public String sendPicture(byte[] picture, String address) {
try {
Socket clientSocket = new Socket(address, 8000);
OutputStream out = clientSocket.getOutputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
out.write(picture);
return in.readLine();
}
catch(IOException ioe) {
Log.v("test", ioe.getMessage());
}
return " ";
}
Run Code Online (Sandbox Code Playgroud)
服务器是用Java编写的.如何编写服务器代码以便正确检索完全相同的字节数组?我的目标是尽可能多地在Android上保存CPU周期.
到目前为止,我尝试过的所有方法都会导致数据损坏或抛出异常.
任何帮助将不胜感激.
我试图弄清楚如何将 XML 传递到 XSLT 文档中并像在任何节点上一样解析它。
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:param name="xmlparam"></xsl:param>
<xsl:template match="/">
<xsl:value-of select="node()"></xsl:value-of>
<xsl:value-of select="$xmlparam/coll"></xsl:value-of>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
xml参数:
<?xml version="1.0" encoding="UTF-8"?>
<coll>
<title>Test</title>
<text>Some text</text>
</coll>
Run Code Online (Sandbox Code Playgroud)
输入:
<?xml version="1.0" encoding="UTF-8"?>
<coll>
Root doc
</coll>
Run Code Online (Sandbox Code Playgroud)
输出:
<?xml version="1.0" encoding="UTF-8"?>
Root doc
XPTY0019: Required item type of first operand of '/' is node(); supplied value has item type xs:untypedAtomic
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解析作为参数传入 XSLT 的 XML?由于某些限制,我无法读取文件,它需要是一个参数。