Click here to Skip to main content
15,895,011 members
Articles / Programming Languages / Java / Java SE

OpenNxSerialization

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
16 Jun 2009GPL32 min read 20.4K   177   9  
Speed up object serialization in Java.
/*
 * @(#)NxLongSerializationSurrogate.java	1.0
 *
 * Created on September 18, 2008, 12:59 PM
 *
 * Copyright 2008 NeXtreme Innovations, Inc. All rights reserved.
 * "NeXtreme Innovations" PROPRIETARY/CONFIDENTIAL. Use is subject
 * to license terms.
 */

package com.nextreme.opennxserialization.standard.io.surrogates;

import com.nextreme.opennxserialization.core.io.NxObjectInput;
import com.nextreme.opennxserialization.core.io.NxObjectOutput;
import com.nextreme.opennxserialization.core.io.surrogates.NxBuiltinSerializationSurrogate;
import com.nextreme.opennxserialization.core.io.surrogates.NxIOException;
import com.nextreme.opennxserialization.core.io.surrogates.NxInstantiationException;
import com.nextreme.opennxserialization.core.io.surrogates.NxSerializationSurrogate;
import com.nextreme.opennxserialization.core.io.surrogates.NxSerializationSurrogateBase;
import java.io.IOException;

/**
 * NxLongSerializationSurrogate is responsible for writing and reading
 * instances of Long class.
 *
 * @version 1.0, September 18, 2008
 */
public class NxLongSerializationSurrogate
        extends NxSerializationSurrogateBase
        implements NxSerializationSurrogate, NxBuiltinSerializationSurrogate
{


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

    /**
     * Read and return an object. The class that implements this interface
     * defines where the object is "read" from.
     *
     * @param input the stream to read data from in order to restore the object.
     * @return the object read from the stream
     * @exception java.lang.ClassNotFoundException If the class of a serialized
     *      object cannot be found.
     * @exception IOException If any of the usual Input/Output
     * related exceptions occur.
     */
    public Object readObject(NxObjectInput input)
	throws NxInstantiationException, NxIOException
    {
        try {
            return input.readLong();
        } catch (IOException ex) {
            throw new NxIOException(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 .
     * @exception IOException Any of the usual Input/Output related exceptions.
     */
    public void writeObject(NxObjectOutput output, Object graph)
      throws NxIOException
    {
        try {
            output.writeLong((Long)graph);
        } catch (IOException ex) {
            throw new NxIOException(ex);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Architect
Pakistan Pakistan
Let a = b ....... (1)
a - b = a - b
a^2 - ab = a^2 - ab
a^2 - ab = a^2 - b^2 (from 1)
a (a - b) = (a + b) (a - b)
a = (a + b) ...... (2)

if a = 1
1 = (1 + 1) (from 1 & 2)
1 = 2 !!

Comments and Discussions