All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.droidkit.bser.Bser Maven / Gradle / Ivy

package com.droidkit.bser;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by ex3ndr on 17.10.14.
 */
public class Bser {
    public static  T parse(Class clazz, InputStream inputStream) throws IOException {
        T res;
        try {
            res = clazz.newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }

        BserValues reader = new BserValues(BserParser.deserialize(inputStream));
        res.parse(reader);
        return res;
    }

    public static  T parse(Class clazz, String fileName) throws IOException {
        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream(fileName);
            return parse(clazz, inputStream);
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
    }

    public static  T parse(Class clazz, byte[] data) throws IOException {
        return parse(clazz, new ByteArrayInputStream(data));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy