【发布时间】:2012-02-23 07:08:27
【问题描述】:
我有一个基于 Java 的服务器端和一个使用 Spring BlazeDS 集成的 flex 客户端。它工作正常,但我最近想从服务器端获取声音。
我关注了BlazeDS mapping doc,它说当 Java 返回一个 Byte[] 时,它将被转换为我想要的 ByteArray。于是我通过 ByteArrayOutputStream 处理 MP3 文件,将其转换为 Byte[] 并返回给前端,但是 Actionscript 得到的值变成了 null 值。
public Byte[] sayHello() {
Byte[] ba = null;
try {
FileInputStream fis = new FileInputStream(
"D:/e/Ryan Adams - I Wish You Were Here.mp3");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = fis.read(buffer)) > 0) {
baos.write(buffer, 0, bytesRead);
}
byte[] byteArray = baos.toByteArray();
ba = new Byte[byteArray.length];
for (int i = 0; i < byteArray.length; i++) {
ba[i] = Byte.valueOf(byteArray[i]);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return ba;
}
ActionScript 代码:
<s:RemoteObject id="ro" destination="helloWorldService" fault="handleFault(event)">
<s:channelSet>
<s:ChannelSet>
<s:AMFChannel uri="/flexspring/messagebroker/amf"/>
</s:ChannelSet>
</s:channelSet>
</s:RemoteObject>
...
private function loaded():void {
var bArr:ByteArray = ro.sayHello() as ByteArray;
l.text = "" + (bArr == null);
}
...
<s:Label id="l" text=""/>
它说“真的”。有谁知道问题出在哪里。
【问题讨论】:
标签: java web-services apache-flex blazeds