• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MapSerializer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.esotericsoftware.kryo.serializers.MapSerializer的典型用法代码示例。如果您正苦于以下问题:Java MapSerializer类的具体用法?Java MapSerializer怎么用?Java MapSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MapSerializer类属于com.esotericsoftware.kryo.serializers包,在下文中一共展示了MapSerializer类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: execute

import com.esotericsoftware.kryo.serializers.MapSerializer; //导入依赖的package包/类
private void execute (Map<Object, Object> map, int inserts) {
	Random random = new Random();
	for (int i = 0; i < inserts; i++)
		map.put(random.nextLong(), random.nextBoolean());

	Kryo kryo = new Kryo();
	kryo.register(HashMap.class, new MapSerializer());
	kryo.register(ConcurrentHashMap.class, new MapSerializer());

	Output output = new Output(2048, -1);
	kryo.writeClassAndObject(output, map);
	output.close();

	Input input = new Input(output.toBytes());
	Object deserialized = kryo.readClassAndObject(input);
	input.close();

	Assert.assertEquals(map, deserialized);
}
 
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:20,代码来源:MapSerializerTest.java


示例2: getIdRecords

import com.esotericsoftware.kryo.serializers.MapSerializer; //导入依赖的package包/类
/**
 * Just to test IdGeneration Recording
 * @param file
 * @return
 * @throws Exception
 */
public List<IdRecordInfo> getIdRecords(String file) throws Exception
{
    List<IdRecordInfo> infos = new ArrayList<>();
    FastInput input = new FastInput(new FileInputStream(file));
    Kryo kryo = new Kryo();
    kryo.register(HashMap.class, new MapSerializer());

    while (input.available() > 0)
    {
        InternalEventRecorder.InternalEventRecord record = kryo.readObject(input,
                InternalEventRecorder.InternalEventRecord.class);
        String tag = new String(record.tag).trim();
        if (tag.equalsIgnoreCase(IdRecordInfo.ID_RECORD_TAG))
        {
            infos.add((IdRecordInfo)record.data);
        }
    }

    return infos;
}
 
开发者ID:d0k1,项目名称:jsflight,代码行数:27,代码来源:Http2JMeter.java


示例3: testMaps

import com.esotericsoftware.kryo.serializers.MapSerializer; //导入依赖的package包/类
public void testMaps () {
	kryo.register(HashMap.class);
	kryo.register(LinkedHashMap.class);
	HashMap map = new HashMap();
	map.put("123", "456");
	map.put("789", "abc");
	roundTrip(18, 21, map);
	roundTrip(2, 5, new LinkedHashMap());
	roundTrip(18, 21, new LinkedHashMap(map));

	MapSerializer serializer = new MapSerializer();
	kryo.register(HashMap.class, serializer);
	kryo.register(LinkedHashMap.class, serializer);
	serializer.setKeyClass(String.class, kryo.getSerializer(String.class));
	serializer.setKeysCanBeNull(false);
	serializer.setValueClass(String.class, kryo.getSerializer(String.class));
	roundTrip(14, 17, map);
	serializer.setValuesCanBeNull(false);
	roundTrip(14, 17, map);
}
 
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:21,代码来源:MapSerializerTest.java


示例4: stringMapSerializer

import com.esotericsoftware.kryo.serializers.MapSerializer; //导入依赖的package包/类
/**
 * Returns a MapSerializer for {@code Map<String, String>} with
 * no null key or value.
 *
 * @return serializer
 */
private static MapSerializer stringMapSerializer() {
    MapSerializer serializer = new MapSerializer();
    serializer.setKeysCanBeNull(false);
    serializer.setKeyClass(String.class, STR_SERIALIZER);
    serializer.setValuesCanBeNull(false);
    serializer.setValueClass(String.class, STR_SERIALIZER);
    return serializer;
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:15,代码来源:AnnotationsSerializer.java


示例5: getRequests

import com.esotericsoftware.kryo.serializers.MapSerializer; //导入依赖的package包/类
public List<RestoredRequest> getRequests(String file, int limit) throws IOException
{
    List<RestoredRequest> requests = new ArrayList<>();
    FastInput input = new FastInput(new FileInputStream(file));

    Kryo kryo = new Kryo();
    kryo.register(HashMap.class, new MapSerializer());
    while (input.available() > 0)
    {
        InternalEventRecorder.InternalEventRecord record = kryo.readObject(input,
                InternalEventRecorder.InternalEventRecord.class);

        String tag = new String(record.tag).trim();

        if (tag.equalsIgnoreCase(HttpRecorderHelper.HTTP_RECORDER_TAG))
        {
            HttpRecordInformation information = (HttpRecordInformation)record.data;
            RestoredRequest request = new RestoredRequest();

            if (information.params != null && information.params.length > 0)
            {
                FastInput paramsInput = new FastInput(new ByteArrayInputStream(information.params));

                request.parameters = kryo.readObject(paramsInput, HashMap.class);
                request.headers = kryo.readObject(paramsInput, HashMap.class);
                request.contentLength = kryo.readObjectOrNull(paramsInput, Integer.class);
                request.contentType = kryo.readObjectOrNull(paramsInput, String.class);
                request.uri = kryo.readObjectOrNull(paramsInput, String.class);
                request.method = kryo.readObjectOrNull(paramsInput, String.class);
                request.contextPath = kryo.readObjectOrNull(paramsInput, String.class);
                request.cookies = kryo.readObject(paramsInput, HashMap.class);
            }
            if (information.payload != null && information.payload.length > 0)
            {
                request.payload = new String(information.payload);
            }

            request.additional = information.additional;
            request.timestampNs = record.timestampNs;

            if (limit > 0 && requests.size() >= limit)
            {
                break;
            }
            requests.add(request);
        }
    }
    return requests;
}
 
开发者ID:d0k1,项目名称:jsflight,代码行数:50,代码来源:Http2JMeter.java


示例6: prepareRequestToRecord

import com.esotericsoftware.kryo.serializers.MapSerializer; //导入依赖的package包/类
public static RecordableHttpServletRequest prepareRequestToRecord(HttpServletRequest original,
        HttpRecordInformation info)
{
    // buffer is 1kb at least
    ByteArrayOutputStream stream = new ByteArrayOutputStream(1024 * 1024);

    FastOutput out = new FastOutput(stream);
    Kryo kryo = threadKryo.get();
    if (kryo == null)
    {
        kryo = new Kryo();
        kryo.register(HashMap.class, new MapSerializer());
        kryo.register(ConcurrentHashMap.class, new MapSerializer());
        threadKryo.set(kryo);
    }
    HashMap<String, String[]> item = new HashMap<>();
    if (original.getParameterMap() != null)
    {
        item.putAll(original.getParameterMap());
    }

    HashMap<String, String> headers = new HashMap<>();
    Enumeration<String> names = original.getHeaderNames();
    while (names.hasMoreElements())
    {
        String header = names.nextElement();
        headers.put(header, original.getHeader(header));
    }
    try
    {
        kryo.writeObject(out, item);

        kryo.writeObject(out, headers);

        kryo.writeObjectOrNull(out, original.getContentLength(), Integer.class);

        kryo.writeObjectOrNull(out, original.getContentType(), String.class);

        kryo.writeObjectOrNull(out, original.getRequestURI(), String.class);

        kryo.writeObjectOrNull(out, original.getMethod(), String.class);
        kryo.writeObjectOrNull(out, original.getServletContext().getContextPath(), String.class);

        HashMap<String, String> cookies = new HashMap<>();
        if (original.getCookies() != null && original.getCookies().length > 0)
        {
            for (Cookie cookie : original.getCookies())
            {
                cookies.put(cookie.getName(), cookie.getValue());
            }
        }

        kryo.writeObject(out, cookies);
        out.flush();
        out.close();

    }
    catch (Exception e)
    {
        e.printStackTrace(System.err);
        throw e;
    }

    info.params = stream.toByteArray();
    return new RecordableHttpServletRequest(original);
}
 
开发者ID:d0k1,项目名称:jsflight,代码行数:67,代码来源:HttpRecorderHelper.java


示例7: Kryo

import com.esotericsoftware.kryo.serializers.MapSerializer; //导入依赖的package包/类
/** @param referenceResolver May be null to disable references. */
public Kryo (ClassResolver classResolver, ReferenceResolver referenceResolver, StreamFactory streamFactory) {
	if (classResolver == null) throw new IllegalArgumentException("classResolver cannot be null.");

	this.classResolver = classResolver;
	classResolver.setKryo(this);

	this.streamFactory = streamFactory;
	streamFactory.setKryo(this);

	this.referenceResolver = referenceResolver;
	if (referenceResolver != null) {
		referenceResolver.setKryo(this);
		references = true;
	}

	addDefaultSerializer(byte[].class, ByteArraySerializer.class);
	addDefaultSerializer(char[].class, CharArraySerializer.class);
	addDefaultSerializer(short[].class, ShortArraySerializer.class);
	addDefaultSerializer(int[].class, IntArraySerializer.class);
	addDefaultSerializer(long[].class, LongArraySerializer.class);
	addDefaultSerializer(float[].class, FloatArraySerializer.class);
	addDefaultSerializer(double[].class, DoubleArraySerializer.class);
	addDefaultSerializer(boolean[].class, BooleanArraySerializer.class);
	addDefaultSerializer(String[].class, StringArraySerializer.class);
	addDefaultSerializer(Object[].class, ObjectArraySerializer.class);
	addDefaultSerializer(KryoSerializable.class, KryoSerializableSerializer.class);
	addDefaultSerializer(BigInteger.class, BigIntegerSerializer.class);
	addDefaultSerializer(BigDecimal.class, BigDecimalSerializer.class);
	addDefaultSerializer(Class.class, ClassSerializer.class);
	addDefaultSerializer(Date.class, DateSerializer.class);
	addDefaultSerializer(Enum.class, EnumSerializer.class);
	addDefaultSerializer(EnumSet.class, EnumSetSerializer.class);
	addDefaultSerializer(Currency.class, CurrencySerializer.class);
	addDefaultSerializer(StringBuffer.class, StringBufferSerializer.class);
	addDefaultSerializer(StringBuilder.class, StringBuilderSerializer.class);
	addDefaultSerializer(Collections.EMPTY_LIST.getClass(), CollectionsEmptyListSerializer.class);
	addDefaultSerializer(Collections.EMPTY_MAP.getClass(), CollectionsEmptyMapSerializer.class);
	addDefaultSerializer(Collections.EMPTY_SET.getClass(), CollectionsEmptySetSerializer.class);
	addDefaultSerializer(Collections.singletonList(null).getClass(), CollectionsSingletonListSerializer.class);
	addDefaultSerializer(Collections.singletonMap(null, null).getClass(), CollectionsSingletonMapSerializer.class);
	addDefaultSerializer(Collections.singleton(null).getClass(), CollectionsSingletonSetSerializer.class);
	addDefaultSerializer(TreeSet.class, TreeSetSerializer.class);
	addDefaultSerializer(Collection.class, CollectionSerializer.class);
	addDefaultSerializer(TreeMap.class, TreeMapSerializer.class);
	addDefaultSerializer(Map.class, MapSerializer.class);
	addDefaultSerializer(TimeZone.class, TimeZoneSerializer.class);
	addDefaultSerializer(Calendar.class, CalendarSerializer.class);
	addDefaultSerializer(Locale.class, LocaleSerializer.class);
	lowPriorityDefaultSerializerCount = defaultSerializers.size();

	// Primitives and string. Primitive wrappers automatically use the same registration as primitives.
	register(int.class, new IntSerializer());
	register(String.class, new StringSerializer());
	register(float.class, new FloatSerializer());
	register(boolean.class, new BooleanSerializer());
	register(byte.class, new ByteSerializer());
	register(char.class, new CharSerializer());
	register(short.class, new ShortSerializer());
	register(long.class, new LongSerializer());
	register(double.class, new DoubleSerializer());
	register(void.class, new VoidSerializer());
	
	// Lambdas support
	// Enable only if JVM supports it
	try {
		String version = System.getProperty("java.version");
		char minor = version.charAt(2);
		if (minor >= '8') {
			register(Class.forName("java.lang.invoke.SerializedLambda"));
			register(Closure.class, (Serializer)Class.forName("com.esotericsoftware.kryo.serializers.ClosureSerializer")
				.newInstance());
		}
	} catch (Exception e) {
		Log.trace("Serialization of Java8 lambdas is not available on this system.");
	}
}
 
开发者ID:HoratiusTang,项目名称:EsperDist,代码行数:78,代码来源:Kryo.java


示例8: Kryo

import com.esotericsoftware.kryo.serializers.MapSerializer; //导入依赖的package包/类
/** @param referenceResolver May be null to disable references. */
public Kryo (ClassResolver classResolver, ReferenceResolver referenceResolver, StreamFactory streamFactory) {
	if (classResolver == null) throw new IllegalArgumentException("classResolver cannot be null.");

	this.classResolver = classResolver;
	classResolver.setKryo(this);

	this.streamFactory = streamFactory;
	streamFactory.setKryo(this);

	this.referenceResolver = referenceResolver;
	if (referenceResolver != null) {
		referenceResolver.setKryo(this);
		references = true;
	}

	addDefaultSerializer(byte[].class, ByteArraySerializer.class);
	addDefaultSerializer(char[].class, CharArraySerializer.class);
	addDefaultSerializer(short[].class, ShortArraySerializer.class);
	addDefaultSerializer(int[].class, IntArraySerializer.class);
	addDefaultSerializer(long[].class, LongArraySerializer.class);
	addDefaultSerializer(float[].class, FloatArraySerializer.class);
	addDefaultSerializer(double[].class, DoubleArraySerializer.class);
	addDefaultSerializer(boolean[].class, BooleanArraySerializer.class);
	addDefaultSerializer(String[].class, StringArraySerializer.class);
	addDefaultSerializer(Object[].class, ObjectArraySerializer.class);
	addDefaultSerializer(KryoSerializable.class, KryoSerializableSerializer.class);
	addDefaultSerializer(BigInteger.class, BigIntegerSerializer.class);
	addDefaultSerializer(BigDecimal.class, BigDecimalSerializer.class);
	addDefaultSerializer(Class.class, ClassSerializer.class);
	addDefaultSerializer(Date.class, DateSerializer.class);
	addDefaultSerializer(Enum.class, EnumSerializer.class);
	addDefaultSerializer(EnumSet.class, EnumSetSerializer.class);
	addDefaultSerializer(Currency.class, CurrencySerializer.class);
	addDefaultSerializer(StringBuffer.class, StringBufferSerializer.class);
	addDefaultSerializer(StringBuilder.class, StringBuilderSerializer.class);
	addDefaultSerializer(Collections.EMPTY_LIST.getClass(), CollectionsEmptyListSerializer.class);
	addDefaultSerializer(Collections.EMPTY_MAP.getClass(), CollectionsEmptyMapSerializer.class);
	addDefaultSerializer(Collections.EMPTY_SET.getClass(), CollectionsEmptySetSerializer.class);
	addDefaultSerializer(Collections.singletonList(null).getClass(), CollectionsSingletonListSerializer.class);
	addDefaultSerializer(Collections.singletonMap(null, null).getClass(), CollectionsSingletonMapSerializer.class);
	addDefaultSerializer(Collections.singleton(null).getClass(), CollectionsSingletonSetSerializer.class);
	addDefaultSerializer(TreeSet.class, TreeSetSerializer.class);
	addDefaultSerializer(Collection.class, CollectionSerializer.class);
	addDefaultSerializer(TreeMap.class, TreeMapSerializer.class);
	addDefaultSerializer(Map.class, MapSerializer.class);
	addDefaultSerializer(TimeZone.class, TimeZoneSerializer.class);
	addDefaultSerializer(Calendar.class, CalendarSerializer.class);
	addDefaultSerializer(Locale.class, LocaleSerializer.class);
	lowPriorityDefaultSerializerCount = defaultSerializers.size();

	// Primitives and string. Primitive wrappers automatically use the same registration as primitives.
	register(int.class, new IntSerializer());
	register(String.class, new StringSerializer());
	register(float.class, new FloatSerializer());
	register(boolean.class, new BooleanSerializer());
	register(byte.class, new ByteSerializer());
	register(char.class, new CharSerializer());
	register(short.class, new ShortSerializer());
	register(long.class, new LongSerializer());
	register(double.class, new DoubleSerializer());
	register(void.class, new VoidSerializer());
}
 
开发者ID:HoratiusTang,项目名称:EsperDist,代码行数:64,代码来源:Kryo.java


示例9: SentinelEventDecoder

import com.esotericsoftware.kryo.serializers.MapSerializer; //导入依赖的package包/类
public SentinelEventDecoder() {
	kryo = new Kryo();
	kryo.register(HashMap.class, new MapSerializer());
}
 
开发者ID:atulsm,项目名称:Test_Projects,代码行数:5,代码来源:HbaseReadTimeSeries.java


示例10: Kryo

import com.esotericsoftware.kryo.serializers.MapSerializer; //导入依赖的package包/类
/** @param referenceResolver May be null to disable references. */
public Kryo (ClassResolver classResolver, ReferenceResolver referenceResolver, StreamFactory streamFactory) {
	if (classResolver == null) throw new IllegalArgumentException("classResolver cannot be null.");

	this.classResolver = classResolver;
	classResolver.setKryo(this);

	this.streamFactory = streamFactory;
	streamFactory.setKryo(this);

	this.referenceResolver = referenceResolver;
	if (referenceResolver != null) {
		referenceResolver.setKryo(this);
		references = true;
	}

	addDefaultSerializer(byte[].class, ByteArraySerializer.class);
	addDefaultSerializer(char[].class, CharArraySerializer.class);
	addDefaultSerializer(short[].class, ShortArraySerializer.class);
	addDefaultSerializer(int[].class, IntArraySerializer.class);
	addDefaultSerializer(long[].class, LongArraySerializer.class);
	addDefaultSerializer(float[].class, FloatArraySerializer.class);
	addDefaultSerializer(double[].class, DoubleArraySerializer.class);
	addDefaultSerializer(boolean[].class, BooleanArraySerializer.class);
	addDefaultSerializer(String[].class, StringArraySerializer.class);
	addDefaultSerializer(Object[].class, ObjectArraySerializer.class);
	addDefaultSerializer(BigInteger.class, BigIntegerSerializer.class);
	addDefaultSerializer(BigDecimal.class, BigDecimalSerializer.class);
	addDefaultSerializer(Class.class, ClassSerializer.class);
	addDefaultSerializer(Date.class, DateSerializer.class);
	addDefaultSerializer(Enum.class, EnumSerializer.class);
	addDefaultSerializer(EnumSet.class, EnumSetSerializer.class);
	addDefaultSerializer(Currency.class, CurrencySerializer.class);
	addDefaultSerializer(StringBuffer.class, StringBufferSerializer.class);
	addDefaultSerializer(StringBuilder.class, StringBuilderSerializer.class);
	addDefaultSerializer(Collections.EMPTY_LIST.getClass(), CollectionsEmptyListSerializer.class);
	addDefaultSerializer(Collections.EMPTY_MAP.getClass(), CollectionsEmptyMapSerializer.class);
	addDefaultSerializer(Collections.EMPTY_SET.getClass(), CollectionsEmptySetSerializer.class);
	addDefaultSerializer(Collections.singletonList(null).getClass(), CollectionsSingletonListSerializer.class);
	addDefaultSerializer(Collections.singletonMap(null, null).getClass(), CollectionsSingletonMapSerializer.class);
	addDefaultSerializer(Collections.singleton(null).getClass(), CollectionsSingletonSetSerializer.class);
	addDefaultSerializer(Collection.class, CollectionSerializer.class);
	addDefaultSerializer(TreeMap.class, TreeMapSerializer.class);
	addDefaultSerializer(Map.class, MapSerializer.class);
	addDefaultSerializer(KryoSerializable.class, KryoSerializableSerializer.class);
	addDefaultSerializer(TimeZone.class, TimeZoneSerializer.class);
	addDefaultSerializer(Calendar.class, CalendarSerializer.class);
	lowPriorityDefaultSerializerCount = defaultSerializers.size();

	// Primitives and string. Primitive wrappers automatically use the same registration as primitives.
	register(int.class, new IntSerializer());
	register(String.class, new StringSerializer());
	register(float.class, new FloatSerializer());
	register(boolean.class, new BooleanSerializer());
	register(byte.class, new ByteSerializer());
	register(char.class, new CharSerializer());
	register(short.class, new ShortSerializer());
	register(long.class, new LongSerializer());
	register(double.class, new DoubleSerializer());
}
 
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:61,代码来源:Kryo.java



注:本文中的com.esotericsoftware.kryo.serializers.MapSerializer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SubCommand类代码示例发布时间:2022-05-21
下一篇:
Java IWritableMount类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap