com.esotericsoftware.kryo.serializers.MapSerializer Java Examples

The following examples show how to use com.esotericsoftware.kryo.serializers.MapSerializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Http2JMeter.java    From jsflight with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: WikipediaLinkProbabilities.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public void storeData(File file) throws IOException {
	FileOutputStream fos = new FileOutputStream(file);

	Kryo kryo = new Kryo();
	kryo.register(HashMap.class, new MapSerializer());
	Output output = new Output(fos);
	kryo.writeClassAndObject(output, wikiLinkProbs);
	output.close();

	fos.close();
}
 
Example #3
Source File: WikipediaLinkProbabilities.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private Map<String, Double> loadData(File file) throws IOException, ClassNotFoundException {
	FileInputStream fis = new FileInputStream(file);

	Kryo kryo = new Kryo();
	kryo.register(HashMap.class, new MapSerializer());
	Input input = new Input(fis);
	Map<String, Double> probs = (Map<String, Double>) kryo.readClassAndObject(input);
	input.close();

	fis.close();
	return probs;
}
 
Example #4
Source File: MentionTokenFrequencyCounts.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public void storeData(File file) throws IOException {
	FileOutputStream fos = new FileOutputStream(file);

	Kryo kryo = new Kryo();
	kryo.register(HashMap.class, new MapSerializer());
	Output output = new Output(fos);
	kryo.writeClassAndObject(output, mentionTokenCounts);
	output.close();

	fos.close();
}
 
Example #5
Source File: MentionTokenFrequencyCounts.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private Map<String, Integer> loadData(File file) throws IOException, ClassNotFoundException {
	FileInputStream fis = new FileInputStream(file);

	Kryo kryo = new Kryo();
	kryo.register(HashMap.class, new MapSerializer());
	Input input = new Input(fis);
	Map<String, Integer> mentionTokenCounts = (Map<String, Integer>) kryo.readClassAndObject(input);
	input.close();

	fis.close();
	return mentionTokenCounts;
}
 
Example #6
Source File: AnnotationsSerializer.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: Http2JMeter.java    From jsflight with Apache License 2.0 4 votes vote down vote up
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;
}