Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.groupon.stomp;
/**
* Copyright (c) 2013, Groupon, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of GROUPON nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
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 unmarshalPrimitiveMap(DataInputStream in) throws IOException {
return unmarshalPrimitiveMap(in, Integer.MAX_VALUE);
}
/**
* @param in
* @return
* @throws IOException
* @throws IOException
*/
public static Map 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 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