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

com.alachisoft.ncache.serialization.standard.io.surrogates.UInt32ArraySerializationSurrogate Maven / Gradle / Ivy

There is a newer version: 5.3.3
Show newest version
package com.alachisoft.ncache.serialization.standard.io.surrogates;

import com.alachisoft.ncache.serialization.core.io.NCacheObjectInput;
import com.alachisoft.ncache.serialization.core.io.NCacheObjectOutput;
import com.alachisoft.ncache.serialization.core.io.surrogates.BuiltinSerializationSurrogate;
import com.alachisoft.ncache.serialization.core.io.surrogates.NCacheIOException;
import com.alachisoft.ncache.serialization.core.io.surrogates.NCacheInstantiationException;
import com.alachisoft.ncache.serialization.core.io.surrogates.SerializationSurrogateImpl;

import java.io.IOException;

/**
 * @author Basit Anwer
 */
public class UInt32ArraySerializationSurrogate extends SerializationSurrogateImpl implements BuiltinSerializationSurrogate {

    /**
     * Creates a new instance of LongSerializationSurrogate
     */
    public UInt32ArraySerializationSurrogate() {
        super(UInt32ArraySerializationSurrogate.class);
    }

    @Override
    public Object instantiate(NCacheObjectInput input)
            throws NCacheInstantiationException {
        try {
            int length = input.readInt();
            return new long[length];
        } catch (IOException ex) {
            throw new NCacheInstantiationException(ex);
        }
    }

    @Override
    public Object readDirect(NCacheObjectInput input, Object graph) throws NCacheInstantiationException, NCacheIOException {
        try {
            long[] longValue = (long[]) graph;
            for (int i = 0; i < longValue.length; i++) {
                longValue[i] = input.readUInt32();
            }
            return longValue;
        } catch (IOException ex) {
            throw new NCacheIOException(ex);
        }
    }

    /**
     * Write an object to the underlying storage or stream.  The
     * class that implements this interface defines how the object is
     * written.
     *
     * @param output the stream to write the object to.
     * @param graph  the object to write .
     * @throws NCacheIOException Any of the usual Input/Output related exceptions.
     */
    @Override
    public void writeDirect(NCacheObjectOutput output, Object graph) throws NCacheIOException {
        try {
            long[] longValue = ((long[]) graph);
            output.writeInt(longValue.length);
            for (int i = 0; i < longValue.length; i++) {
                output.writeUInt32(longValue[i]);
            }
        } catch (IOException ex) {
            throw new NCacheIOException(ex);
        }
    }

    @Override
    public void skipDirect(NCacheObjectInput input, Object graph) throws NCacheInstantiationException, NCacheIOException {
        try {
            long[] longValue = (long[]) graph;
            for (int i = 0; i < longValue.length; i++) {
                input.skipUInt32();
            }
        } catch (IOException ex) {
            throw new NCacheIOException(ex);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy