minor refactor to create marshalString helper method

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@452752 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-10-04 06:13:12 +00:00
parent afcb55e547
commit 00282727b8
1 changed files with 13 additions and 11 deletions

View File

@ -145,17 +145,7 @@ public class MarshallingSupport {
out.writeInt(((byte[])value).length); out.writeInt(((byte[])value).length);
out.write(((byte[])value)); out.write(((byte[])value));
} else if( value.getClass() == String.class ) { } else if( value.getClass() == String.class ) {
String s = (String)value; marshalString(out, (String)value);
// If it's too big, out.writeUTF may not able able to write it out.
if( s.length() < Short.MAX_VALUE/4 ) {
out.writeByte(STRING_TYPE);
out.writeUTF((String)value);
} else {
out.writeByte(BIG_STRING_TYPE);
writeUTF8(out, s);
}
} else if( value instanceof Map) { } else if( value instanceof Map) {
out.writeByte(MAP_TYPE); out.writeByte(MAP_TYPE);
marshalPrimitiveMap((Map) value, out); marshalPrimitiveMap((Map) value, out);
@ -215,6 +205,18 @@ public class MarshallingSupport {
return value; return value;
} }
public static void marshalString(DataOutputStream out, String s) throws IOException {
// If it's too big, out.writeUTF may not able able to write it out.
if( s.length() < Short.MAX_VALUE/4 ) {
out.writeByte(STRING_TYPE);
out.writeUTF(s);
} else {
out.writeByte(BIG_STRING_TYPE);
writeUTF8(out, s);
}
}
static public void writeUTF8(DataOutput dataOut, String text) throws IOException { static public void writeUTF8(DataOutput dataOut, String text) throws IOException {
if (text != null) { if (text != null) {
int strlen = text.length(); int strlen = text.length();