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

com.mongodb.spark.pickle.ObjectIdConstructor Maven / Gradle / Ivy

Go to download

The MongoDB Connector for Hadoop is a plugin for Hadoop that provides the ability to use MongoDB as an input source and/or an output destination.

There is a newer version: 2.0.2
Show newest version
package com.mongodb.spark.pickle;

import net.razorvine.pickle.IObjectConstructor;
import net.razorvine.pickle.PickleException;
import org.bson.BSON;
import org.bson.types.ObjectId;

public class ObjectIdConstructor implements IObjectConstructor {

    public static class ObjectIdBox extends BSONValueBox {
        private ObjectId oid;
        static {
            BSON.addEncodingHook(ObjectIdBox.class, getTransformer());
        }

        // CHECKSTYLE:OFF
        public void __setstate__(final String state) {
            // CHECKSTYLE:ON
            byte[] oidBytes = new byte[state.length()];
            for (int i = 0; i < state.length(); ++i) {
                oidBytes[i] = (byte) state.charAt(i);
            }
            this.oid = new ObjectId(oidBytes);
        }

        @Override
        public ObjectId get() {
            return this.oid;
        }
    }

    @Override
    public Object construct(final Object[] args) {
        if (args.length != 0) {
            throw new PickleException(
              "ObjectId constructor requires 0 arguments, not " + args.length);
        }
        return new ObjectIdBox();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy