Alachisoft.NCache.Common.JSON.BinaryJsonValue Maven / Gradle / Ivy
package Alachisoft.NCache.Common.JSON;
import Alachisoft.NCache.Common.Caching.UserBinaryObject;
import com.alachisoft.ncache.runtime.JSON.JsonValueType;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.Serializable;
public class BinaryJsonValue extends ExtendedJsonValueBase implements Serializable
{
///#region ------------------------------ Fields ------------------------------
private UserBinaryObject _userBinaryObject;
///#endregion
///#region ---------------------------- Properties ----------------------------
@Override
public JsonValueType getJsonType()
{
return JsonValueType.Binary;
}
@Override
public Object getValue()
{
return _userBinaryObject;
}
///#endregion
///#region --------------------------- Constructors ---------------------------
public BinaryJsonValue(UserBinaryObject userBinaryObject)
{
super();
_userBinaryObject = userBinaryObject;
if (userBinaryObject != null)
{
// TODO (IN FUTURE) 5.0 SP3: BinaryJsonValue size needs to be recalculated for Java
setSize(getSize() + userBinaryObject.getSize());
setInMemorySize(getInMemorySize() + userBinaryObject.getInMemorySize() + 24); // InMemorySize for UBO and .NET overhead (24)
}
}
///#endregion
///#region ----------------------------- Behavior -----------------------------
@Override
public String toJson()
{
if (_userBinaryObject == null)
return null;
try {
ByteArrayInputStream stream = new ByteArrayInputStream(_userBinaryObject.getTwoDimensionalArray());
String temp = new String(stream.readAllBytes());
stream.close();
return temp;
} catch (IOException e) {
return null;
}
}
@Override
public UserBinaryObject toUserBinaryObject()
{
return _userBinaryObject;
}
///#endregion
///#region ---------------------------- Overrides -----------------------------
@Override
public String toString()
{
return toJson();
}
///#endregion
}