views:

54

answers:

0

Hi,

I am trying to send a byteArray from my .fla to my running tomcat server integrated in Eclipse. From flash I am using the following code:

var loader:URLLoader = new URLLoader();

var header:URLRequestHeader = new URLRequestHeader("audio/wav", "application/octet-stream");
var request:URLRequest = new URLRequest("http://localhost:8080/pdp/Server?wav=" + tableID);
request.requestHeaders.push(header); 
request.method = URLRequestMethod.POST;
request.data = wav; //the variable containing a raw bytearray from a mic recording
loader.load(request);

And my java servlet looks as follows:

try{

   int readBytes = -1; 
   int lengthOfBuffer = request.getContentLength(); 
   InputStream input = request.getInputStream(); 
   byte[] buffer  = new byte[lengthOfBuffer]; 
   ByteArrayOutputStream output = new ByteArrayOutputStream(lengthOfBuffer); 
   while((readBytes = input.read(buffer, 0, lengthOfBuffer)) != -1) { 
    output.write(buffer, 0, readBytes); 
   } 
   byte[] finalOutput = output.toByteArray();  
   input.close();
   FileOutputStream fos = new FileOutputStream(getServletContext().getRealPath(""+"/temp/"+wav+".wav"));
   fos.write(finalOutput);
   fos.close(); 

When i run the flash .swf file and send the bytearray to the server, I receive following in the server's console window:: (loads of loads of Chinese symbols) May 20, 2010 7:04:57 PM org.apache.tomcat.util.http.Parameters processParameters WARNING: Parameters: Character decoding failed. Parameter '? (loads of loads of Chinese symbols) and then looping this for a long time. It is like I recieve the bytes but not encoding/decoding them correctly. What can I do?