ActiveMQ example source code file (MarshallingSupport.java)
This example ActiveMQ source code file (MarshallingSupport.java) is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.
Java - ActiveMQ tags/keywords
io, ioexception, ioexception, list, long_type, map, object, object, properties, string, string, sun, todo, todo, utfdataformatexception, util
The ActiveMQ MarshallingSupport.java source code
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.util;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.UTFDataFormatException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* The fixed version of the UTF8 encoding function. Some older JVM's UTF8
* encoding function breaks when handling large strings.
*
*
*/
public final class MarshallingSupport {
public static final byte NULL = 0;
public static final byte BOOLEAN_TYPE = 1;
public static final byte BYTE_TYPE = 2;
public static final byte CHAR_TYPE = 3;
public static final byte SHORT_TYPE = 4;
public static final byte INTEGER_TYPE = 5;
public static final byte LONG_TYPE = 6;
public static final byte DOUBLE_TYPE = 7;
public static final byte FLOAT_TYPE = 8;
public static final byte STRING_TYPE = 9;
public static final byte BYTE_ARRAY_TYPE = 10;
public static final byte MAP_TYPE = 11;
public static final byte LIST_TYPE = 12;
public static final byte BIG_STRING_TYPE = 13;
private MarshallingSupport() {
}
public static void marshalPrimitiveMap(Map map, DataOutputStream out) throws IOException {
if (map == null) {
out.writeInt(-1);
} else {
out.writeInt(map.size());
for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
String name = (String)iter.next();
out.writeUTF(name);
Object value = map.get(name);
marshalPrimitive(out, value);
}
}
}
public static Map<String, Object> unmarshalPrimitiveMap(DataInputStream in) throws IOException {
return unmarshalPrimitiveMap(in, Integer.MAX_VALUE);
}
/**
* @param in
* @return
* @throws IOException
* @throws IOException
*/
public static Map<String, Object> unmarshalPrimitiveMap(DataInputStream in, int maxPropertySize) throws IOException {
int size = in.readInt();
if (size > maxPropertySize) {
throw new IOException("Primitive map is larger than the allowed size: " + size);
}
if (size < 0) {
return null;
} else {
Map<String, Object> rc = new HashMap(size);
for (int i = 0; i < size; i++) {
String name = in.readUTF();
rc.put(name, unmarshalPrimitive(in));
}
return rc;
}
}
public static void marshalPrimitiveList(List list, DataOutputStream out) throws IOException {
out.writeInt(list.size());
for (Iterator iter = list.iterator(); iter.hasNext();) {
Object element = (Object)iter.next();
marshalPrimitive(out, element);
}
}
public static List<Object> unmarshalPrimitiveList(DataInputStream in) throws IOException {
int size = in.readInt();
List<Object> answer = new ArrayList