com.alachisoft.ncache.serialization.standard.io.surrogates.UInt16ArraySerializationSurrogate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-serialization Show documentation
Show all versions of nc-serialization Show documentation
Internal package of Alachisoft.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
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 UInt16ArraySerializationSurrogate extends SerializationSurrogateImpl implements BuiltinSerializationSurrogate {
/**
* Creates a new instance of DoubleSerializationSurrogate
*/
public UInt16ArraySerializationSurrogate() {
super(UInt16ArraySerializationSurrogate.class);
}
@Override
public Object instantiate(NCacheObjectInput input)
throws NCacheInstantiationException {
try {
int length = input.readInt();
return new int[length];
} catch (IOException ex) {
throw new NCacheInstantiationException(ex);
}
}
@Override
public Object readDirect(NCacheObjectInput input, Object graph) throws NCacheInstantiationException, NCacheIOException {
try {
int[] integer = (int[]) graph;
for (int i = 0; i < integer.length; i++) {
integer[i] = input.readUInt16();
}
return integer;
} 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.
*/
public void writeDirect(NCacheObjectOutput output, Object graph)
throws NCacheIOException {
try {
int[] integer = ((int[]) graph);
output.writeInt(integer.length);
for (int i = 0; i < integer.length; i++) {
output.writeUInt16(integer[i]);
}
} catch (IOException ex) {
throw new NCacheIOException(ex);
}
}
@Override
public void skipDirect(NCacheObjectInput input, Object graph) throws NCacheInstantiationException, NCacheIOException {
try {
int[] integer = (int[]) graph;
for (int i = 0; i < integer.length; i++) {
input.skipUInt16();
}
} catch (IOException ex) {
throw new NCacheIOException(ex);
}
}
}