Wowza Media Systems home
Wowza Pro is the best alternative to Adobe Flash Media Server. Try it today.
Now Hiring. Join the Wowza team!

Go Back   Wowza Media Server Forums > Wowza Media Server Pro Forums (version 1.7.x) > Help Requests

Reply
 
Thread Tools Display Modes
  #1  
Old 03-03-2009, 01:28 AM
andrew12 andrew12 is offline
Junior Member
 
Join Date: May 2007
Posts: 12
Default Passing strings longer than 64Kb or java.io.UTFDataFormatException

Hello all,
Recently I had some problem to pass long string (>64Kb) from my wowza app to flash client.

Wowza throws exception:
Code:
java.io.UTFDataFormatException: encoded string too long: 66826 bytes
at com.wowza.wms.amf.AMF3Utils.serializeStringNoLength(Unknown Source)
at com.wowza.wms.amf.AMFDataItem.serialize(Unknown Source)
at com.wowza.wms.amf.AMFDataList.serialize(Unknown Source)
at com.wowza.wms.amf.AMFDataList.serialize(Unknown Source)
at com.wowza.wms.response.ResponseFunction.write(Unknown Source)
at com.wowza.wms.response.ResponseFunction.write(Unknown Source)
at com.wowza.wms.response.ResponseFunctions.output(Unknown Source)
at com.wowza.wms.request.RTMPRequestAdapter.service(Unknown Source)
at com.wowza.wms.server.ServerHandler.serviceRequest(Unknown Source)
ERROR server comment - serialize: java.io.UTFDataFormatException: encoded string too long: 66826 bytes
Charlie offered the solution to split the string to 64kb chunks and re-assemble them at client-side app.

wowza java code
Code:
public void send(String xml) {
	
	String[] chunks = FCWzVideochatUser.splitString(xml, 65535);
	AMFDataArray longStrArr = new AMFDataArray();
	for (int i=0; i<chunks.length; i++) {
		longStrArr.add(new AMFDataItem(chunks[i]));
	}
	
	iclient.call("receive", new FCWowzaResult(), longStrArr);
	
}

public static String[] splitString(String str, int maxLength) {
    if (str==null) return null;
    int len = str.length();
    int fullChunks = len / maxLength;
    boolean lastChunkEmpty = fullChunks*maxLength == len;
    
    int size = fullChunks;
    if (!lastChunkEmpty) size++;
    
    int i = 0;
    String[] chunks = new String[size];
    for (i=0; i<fullChunks; i++) {
    	chunks[i] = str.substring(i*maxLength, i*maxLength+maxLength);
    }
    
    if (!lastChunkEmpty) chunks[i] = str.substring(i*maxLength, len);
    
    return chunks;
}
On the client side in Flash then you would need to reassemble the string:
Code:
function clientResult(longStrArr:Array)
{
        var xml:String = "";
        for(var i:Number = 0;i< longStrArr.length;i++)
                xml += longStrArr[i];
}
certainly you should change the code for you own app, this is only the example. Hope this help you when you deal with long strings and got "java.io.UTFDataFormatException: encoded string too long".

Charlie, thanks a lot.
Reply With Quote
  #2  
Old 03-03-2009, 08:43 AM
charlie charlie is offline
Administrator
 
Join Date: Nov 2006
Posts: 9,242
Default

Thanks for posting this code. Quick not is that this is not an issue if you use AMF3 encoding (which is the default for ActionScript 3.0).

Charlie
Reply With Quote
  #3  
Old 03-19-2009, 03:12 PM
FlyingPotatoes FlyingPotatoes is offline
Junior Member
 
Join Date: Mar 2007
Posts: 24
Default

Depending on how your client side functions are designed, you may not need to change them. If your functions are expecting a string and you pass an array of strings, Actionscript will automatically call a .toString() on the array and it'll magically turn into the reassembled string.

Your mileage may vary, but this behavior just saved me a ton of work.

EDIT: Ignore that post, I'm an idiot. The default .toString() throws a comma in at the point where the array members are joined, which will cause some very strange behavior if you use that string for XML. Use the code posted above on the client side, don't rely on the default .toString().

Last edited by FlyingPotatoes; 03-23-2009 at 05:09 PM.
Reply With Quote
  #4  
Old 07-07-2009, 04:50 AM
dpMediaDev dpMediaDev is offline
Member
 
Join Date: Jun 2008
Posts: 63
Default

Quote:
Originally Posted by charlie View Post
Thanks for posting this code. Quick not is that this is not an issue if you use AMF3 encoding (which is the default for ActionScript 3.0).
Wrong, I get the same exception when using AMF3 as defaultObjectEncoding set by the client. It even happens in the AMF3Utils package: com.wowza.wms.amf.AMF3Utils.serializeStringNoLengt h(Unknown Source)

According to the JavaDocs it's a limitation of the Java function writeUTF() so it's recommended to use another method or just doing it by yourself.

Splitting the string up is not an option for my case because I use the big UTF8 string (having xml data) in a shared object slot so I would need to handle multiple slots for just one file, that's too confusing.

So, what else can I do to work around the problem?

Robin
dpMediaDev

Last edited by dpMediaDev; 07-07-2009 at 04:53 AM.
Reply With Quote
  #5  
Old 07-07-2009, 04:59 AM
charlie charlie is offline
Administrator
 
Join Date: Nov 2006
Posts: 9,242
Default

There is a limit of 64K on both AMF0 and AMF3 strings. You can still store the string in a single slot by breaking it up into multiple Strings and store an AMFDataArray of strings in the shared object slot. It should do everything you need. Then you just need to marshall it on either end.

Charlie
Reply With Quote
  #6  
Old 07-07-2009, 08:09 AM
dpMediaDev dpMediaDev is offline
Member
 
Join Date: Jun 2008
Posts: 63
Default

Quote:
Originally Posted by charlie View Post
There is a limit of 64K on both AMF0 and AMF3 strings. You can still store the string in a single slot by breaking it up into multiple Strings and store an AMFDataArray of strings in the shared object slot. It should do everything you need. Then you just need to marshall it on either end.
Charlie
Well, this works... at least in one direction. I can create the AMFDataArray on the server (array of strings), add it as a property to the shared object and rebuild the whole text on the flash client (concat strings).

But in the other direction it doesn't work. So in the client I create an array of strings, put it in the shared object and on the server side I want to get it from the shared object as an AMFDataArray. But the casting fails because now it's a AMFDataMixedArray. What's the reason for that? On the client I just put in an array of strings and not an array of any datatype.

Robin
dpMediaDev
Reply With Quote
  #7  
Old 07-07-2009, 08:13 AM
charlie charlie is offline
Administrator
 
Join Date: Nov 2006
Posts: 9,242
Default

Then I would just switch everything to use AMFDataMixedArray. The Flash player tends to always serialize using this format. Not sure why.

Charlie
Reply With Quote
  #8  
Old 07-07-2009, 08:30 AM
dpMediaDev dpMediaDev is offline
Member
 
Join Date: Jun 2008
Posts: 63
Default

Quote:
Originally Posted by charlie View Post
Then I would just switch everything to use AMFDataMixedArray. The Flash player tends to always serialize using this format. Not sure why.
Charlie
Yeah, I already tried this successfully so I was going to change my last post... but you were just too fast this time. ;-)

So this Mixed Array has all things I need, that's ok.

Sincerely,
Robin
dpMediaDev
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:59 AM.


Copyright © 2006 - 2010, Wowza Media Systems
Wowza Media Systems