【发布时间】:2016-03-20 01:17:51
【问题描述】:
我正在使用Voice RSS 为我的 java 应用程序进行文本到语音的翻译。我过去使用过像 RESTY 这样的客户端来处理简单的 json 请求,这些请求很舒服。但在这种情况下,服务器(语音 RSS)将内容类型作为音频返回,我不确定如何将其作为 java 客户端处理和解包。任何帮助将不胜感激
谢谢 卡提克
【问题讨论】:
标签: rest content-type rest-client
我正在使用Voice RSS 为我的 java 应用程序进行文本到语音的翻译。我过去使用过像 RESTY 这样的客户端来处理简单的 json 请求,这些请求很舒服。但在这种情况下,服务器(语音 RSS)将内容类型作为音频返回,我不确定如何将其作为 java 客户端处理和解包。任何帮助将不胜感激
谢谢 卡提克
【问题讨论】:
标签: rest content-type rest-client
我发现您可以使用 Url 和 BufferedInputStream 将来自 Web 服务的响应下载为字节数组或输出流,您可以将其保存为任何内容。
InputStream in = null;
ByteArrayOutputStream outputStream = null;
byte[] byteArray = null;
try {
URL link = new URL("YOUR_URL");
in = new BufferedInputStream(link.openStream());
outputStream = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int n = 0;
while (-1 != (n = in.read(buf))) {
outputStream.write(buf, 0, n);
}
byteArray = outputStream.toByteArray();
}catch (Exception ex){
throw ex;
}finally {
if(in != null) in.close();;
if(outputStream != null) outputStream.close();
}
【讨论】: