- opennxserialization10.zip
- OpenNxSerialization.10
- Bin
- Benchmark.jar
- lib
- OpenNxSerialization.Core_1.0.0.0.jar
- OpenNxSerialization.Standard_1.0.0.0.jar
- README.TXT
- clean.bat
- Docs
- OpenNxSerialization.Core
- OpenNxSerialization.Standard
- Lib
- OpenNxSerialization.Core_1.0.0.0.jar
- OpenNxSerialization.Standard_1.0.0.0.jar
- License.rtf
- Readme.txt
- Samples
- Src
- clean.bat
- OpenNxSerialization.Core_1.0.0.0
- build.xml
- nbproject
- src
- com
- nextreme
- opennxserialization
- core
- test
- OpenNxSerialization.Standard_1.0.0.0
- build.xml
- nbproject
- src
- com
- nextreme
- opennxserialization
- standard
- test
|
/*
* @(#)NxShortArraySerializationSurrogate.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.NxBlockDataInputStream;
import com.nextreme.opennxserialization.core.io.NxBlockDataOutputStream;
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.NxSerializationSurrogateImpl;
import java.io.IOException;
/**
* NxShortArraySerializationSurrogate is responsible for writing and reading
* instances of short[] class.
*
* @version 1.0, September 18, 2008
*/
public class NxShortArraySerializationSurrogate
extends NxSerializationSurrogateImpl
implements NxBuiltinSerializationSurrogate
{
/** Creates a new instance of NxObjectArraySerializationSurrogate */
public NxShortArraySerializationSurrogate()
{
super(short[].class);
}
/**
* Creates instance of type returned by getRealClass(). This is different from NxSerializationSurrogateBase.createTypeInstance()
* in the sense that an NxObjectInput object is passed as parameter that can be used to read creation specific
* information from the stream. For example it can be used to read the length of the array before actually
* reading the values.
*
* The default implementation simply delegates to super.createTypeInstance().
*
* @param input stream reader
* @exception NxInstantiationException Object creation related exceptions.
* @return Object that this surrogate must deserialize
*/
@Override
public Object instantiate(NxObjectInput input)
throws NxInstantiationException
{
try {
int length = input.readInt();
return new short[length];
} catch (IOException ex) {
throw new NxInstantiationException(ex);
}
}
/**
* Read an object of type returned by getRealClass() from the stream reader.
* A fresh instance of the object is passed as parameter.
* The surrogate should populate fields in the object from data on the stream
*
* @param input stream reader
* @param graph a fresh instance of the object that the surrogate must deserialize.
* @exception NxInstantiationException Object creation related exceptions.
* @exception NxIOException Any of the usual Input/Output related exceptions.
* @return object read from the stream reader
*/
public Object readDirect(NxObjectInput input, Object graph)
throws NxInstantiationException, NxIOException
{
short[] array = (short[])graph;
int len = array.length;
NxBlockDataInputStream bin =
(NxBlockDataInputStream) input.getContext().getUserItem("__bin");
try {
if(bin != null)
{
bin.readShorts(array, 0, len);
}
else
{
for (int i = 0; i < len; i++)
array[i] = input.readShort();
}
} catch (IOException ex) {
throw new NxIOException(ex);
}
return array;
}
/**
* Write an object of type returned by getRealClass() to the stream writer
*
* @param output stream writer
* @param graph object to be written to the stream reader
* @exception NxIOException Any of the usual Input/Output related exceptions.
*/
public void writeDirect(NxObjectOutput output, Object graph)
throws NxIOException
{
short[] array = (short[])graph;
int len = array.length;
NxBlockDataOutputStream bout =
(NxBlockDataOutputStream)output.getContext().getUserItem("__bout");
try {
if(bout != null)
{
bout.writeShorts(array, 0, len);
}
else
{
output.writeInt(len);
for (int i = 0; i < len; i++)
output.writeShort(array[i]);
}
} 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.
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 !!