com.alachisoft.ncache.serialization.standard.io.surrogates.BigDecimalSerializationSurrogate 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.*;
import java.io.IOException;
import java.math.BigDecimal;
/**
* @author Basit Anwer
*/
public class BigDecimalSerializationSurrogate extends SerializationSurrogateBase implements SerializationSurrogate, BuiltinSerializationSurrogate {
/**
* Creates a new instance of BigIntegerSerializationSurrogate
*/
public BigDecimalSerializationSurrogate() {
super(BigDecimal.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
* @throws java.lang.ClassNotFoundException If the class of a serialized
* object cannot be found.
* @throws NCacheIOException If any of the usual Input/Output
* related exceptions occur.
*/
public Object readObject(NCacheObjectInput input) throws NCacheInstantiationException, NCacheIOException {
try {
return new BigDecimal((String) input.readObject());
} catch (IOException ex) {
throw new NCacheIOException(ex);
} catch (Exception ex1) {
throw new NCacheIOException(ex1);
}
}
/**
* 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 writeObject(NCacheObjectOutput output, Object graph)
throws NCacheIOException {
try {
BigDecimal bigD = (BigDecimal) graph;
output.writeObject(bigD.toPlainString());
} catch (IOException ex) {
throw new NCacheIOException(ex);
}
}
public void skipObject(NCacheObjectInput input) throws NCacheInstantiationException, NCacheIOException {
try {
input.readObject();
} catch (IOException ex) {
throw new NCacheIOException(ex);
} catch (Exception ex1) {
throw new NCacheIOException(ex1);
}
}
}