use of com.abubusoft.kripton.exception.KriptonRuntimeException in project kripton by xcesco.
the class BeanDaoImpl method serializer1.
/**
* for param serializer1 serialization
*/
private byte[] serializer1(BeanInner[] value) {
if (value == null) {
return null;
}
KriptonJsonContext context = KriptonBinder.jsonBind();
try (KriptonByteArrayOutputStream stream = new KriptonByteArrayOutputStream();
JacksonWrapperSerializer wrapper = context.createSerializer(stream)) {
JsonGenerator jacksonSerializer = wrapper.jacksonGenerator;
int fieldCount = 0;
jacksonSerializer.writeStartObject();
if (value != null) {
int n = value.length;
BeanInner item;
// write wrapper tag
jacksonSerializer.writeFieldName("element");
jacksonSerializer.writeStartArray();
for (int i = 0; i < n; i++) {
item = value[i];
if (item == null) {
jacksonSerializer.writeNull();
} else {
beanInnerBindMap.serializeOnJackson(item, jacksonSerializer);
}
}
jacksonSerializer.writeEndArray();
}
jacksonSerializer.writeEndObject();
jacksonSerializer.flush();
return stream.toByteArray();
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
use of com.abubusoft.kripton.exception.KriptonRuntimeException in project kripton by xcesco.
the class BeanDaoImpl method parser1.
/**
* for param parser1 parsing
*/
private BeanInner[] parser1(byte[] input) {
if (input == null) {
return null;
}
KriptonJsonContext context = KriptonBinder.jsonBind();
try (JacksonWrapperParser wrapper = context.createParser(input)) {
JsonParser jacksonParser = wrapper.jacksonParser;
// START_OBJECT
jacksonParser.nextToken();
// value of "element"
jacksonParser.nextValue();
BeanInner[] result = null;
if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
ArrayList<BeanInner> collection = new ArrayList<>();
BeanInner item = null;
while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
item = null;
} else {
item = beanInnerBindMap.parseOnJackson(jacksonParser);
}
collection.add(item);
}
result = CollectionUtils.asArray(collection, new BeanInner[collection.size()]);
}
return result;
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
use of com.abubusoft.kripton.exception.KriptonRuntimeException in project kripton by xcesco.
the class BindCharDataSource method build.
/**
* <p>Build instance. This method can be used only one time, on the application start.</p>
*/
public static BindCharDataSource build(DataSourceOptions options) {
BindCharDataSource result = instance;
if (result == null) {
synchronized (mutex) {
result = instance;
if (result == null) {
instance = result = new BindCharDataSource(options);
SQLiteDatabase database = instance.openWritableDatabase();
try {
} catch (Throwable e) {
Logger.error(e.getMessage());
e.printStackTrace();
} finally {
instance.close();
}
} else {
throw new KriptonRuntimeException("Datasource BindCharDataSource is already builded");
}
}
} else {
throw new KriptonRuntimeException("Datasource BindCharDataSource is already builded");
}
return result;
}
use of com.abubusoft.kripton.exception.KriptonRuntimeException in project kripton by xcesco.
the class BindDoubleDataSource method build.
/**
* <p>Build instance. This method can be used only one time, on the application start.</p>
*/
public static BindDoubleDataSource build(DataSourceOptions options) {
BindDoubleDataSource result = instance;
if (result == null) {
synchronized (mutex) {
result = instance;
if (result == null) {
instance = result = new BindDoubleDataSource(options);
SQLiteDatabase database = instance.openWritableDatabase();
try {
} catch (Throwable e) {
Logger.error(e.getMessage());
e.printStackTrace();
} finally {
instance.close();
}
} else {
throw new KriptonRuntimeException("Datasource BindDoubleDataSource is already builded");
}
}
} else {
throw new KriptonRuntimeException("Datasource BindDoubleDataSource is already builded");
}
return result;
}
use of com.abubusoft.kripton.exception.KriptonRuntimeException in project kripton by xcesco.
the class CharDaoImpl method parser1.
/**
* for param parser1 parsing
*/
private char[] parser1(byte[] input) {
if (input == null) {
return null;
}
KriptonJsonContext context = KriptonBinder.jsonBind();
try (JacksonWrapperParser wrapper = context.createParser(input)) {
JsonParser jacksonParser = wrapper.jacksonParser;
// START_OBJECT
jacksonParser.nextToken();
// value of "element"
jacksonParser.nextValue();
char[] result = null;
if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
ArrayList<Character> collection = new ArrayList<>();
Character item = null;
while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
item = null;
} else {
item = Character.valueOf((char) jacksonParser.getIntValue());
}
collection.add(item);
}
result = CollectionUtils.asCharacterTypeArray(collection);
}
return result;
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
Aggregations