本文整理汇总了Java中org.apache.commons.lang3.SerializationException类的典型用法代码示例。如果您正苦于以下问题:Java SerializationException类的具体用法?Java SerializationException怎么用?Java SerializationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerializationException类属于org.apache.commons.lang3包,在下文中一共展示了SerializationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listFromXml
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
public static <T> List<T> listFromXml(InputStream xml, Class<T> clazz) throws SerializationException {
JAXBContext context;
try {
context = JAXBContext.newInstance(GenericListWrapper.class, clazz);
Unmarshaller unmarshaller = context.createUnmarshaller();
@SuppressWarnings("unchecked")
GenericListWrapper<T> wrapper = (GenericListWrapper<T>) unmarshaller.unmarshal(new StreamSource(xml), GenericListWrapper.class)
.getValue();
return wrapper.getItems();
} catch (JAXBException e) {
throw new SerializationException(e);
}
}
示例2: addCoFunction
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
protected <OUT> SingleOutputStreamOperator<OUT, ?> addCoFunction(String functionName,
final Function function, TypeWrapper<IN1> in1TypeWrapper,
TypeWrapper<IN2> in2TypeWrapper, TypeWrapper<OUT> outTypeWrapper,
CoInvokable<IN1, IN2, OUT> functionInvokable) {
@SuppressWarnings({ "unchecked", "rawtypes" })
SingleOutputStreamOperator<OUT, ?> returnStream = new SingleOutputStreamOperator(
environment, functionName, outTypeWrapper);
try {
dataStream1.jobGraphBuilder.addCoTask(returnStream.getId(), functionInvokable,
in1TypeWrapper, in2TypeWrapper, outTypeWrapper, functionName,
SerializationUtils.serialize((Serializable) function),
environment.getDegreeOfParallelism());
} catch (SerializationException e) {
throw new RuntimeException("Cannot serialize user defined function");
}
dataStream1.connectGraph(dataStream1, returnStream.getId(), 1);
dataStream1.connectGraph(dataStream2, returnStream.getId(), 2);
// TODO consider iteration
return returnStream;
}
示例3: addSink
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
private DataStreamSink<OUT> addSink(DataStream<OUT> inputStream,
SinkFunction<OUT> sinkFunction, TypeWrapper<OUT> inTypeWrapper) {
DataStreamSink<OUT> returnStream = new DataStreamSink<OUT>(environment, "sink",
outTypeWrapper);
try {
jobGraphBuilder.addStreamVertex(returnStream.getId(), new SinkInvokable<OUT>(
sinkFunction), inTypeWrapper, null, "sink", SerializationUtils
.serialize(sinkFunction), degreeOfParallelism);
} catch (SerializationException e) {
throw new RuntimeException("Cannot serialize SinkFunction");
}
inputStream.connectGraph(inputStream.copy(), returnStream.getId(), 0);
return returnStream;
}
示例4: fromElements
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
/**
* Creates a new DataStream that contains the given elements. The elements
* must all be of the same type, for example, all of the String or Integer.
* The sequence of elements must not be empty. Furthermore, the elements
* must be serializable (as defined in java.io.Serializable), because the
* execution environment may ship the elements into the cluster.
*
* @param data
* The collection of elements to create the DataStream from.
* @param <OUT>
* type of the returned stream
* @return The DataStream representing the elements.
*/
public <OUT extends Serializable> DataStreamSource<OUT> fromElements(OUT... data) {
if (data.length == 0) {
throw new IllegalArgumentException(
"fromElements needs at least one element as argument");
}
TypeWrapper<OUT> outTypeWrapper = new ObjectTypeWrapper<OUT>(data[0]);
DataStreamSource<OUT> returnStream = new DataStreamSource<OUT>(this, "elements",
outTypeWrapper);
try {
SourceFunction<OUT> function = new FromElementsFunction<OUT>(data);
jobGraphBuilder.addStreamVertex(returnStream.getId(),
new SourceInvokable<OUT>(function), null, outTypeWrapper, "source",
SerializationUtils.serialize(function), 1);
} catch (SerializationException e) {
throw new RuntimeException("Cannot serialize elements");
}
return returnStream;
}
示例5: fromCollection
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
/**
* Creates a DataStream from the given non-empty collection. The type of the
* DataStream is that of the elements in the collection. The elements need
* to be serializable (as defined by java.io.Serializable), because the
* framework may move the elements into the cluster if needed.
*
* @param data
* The collection of elements to create the DataStream from.
* @param <OUT>
* type of the returned stream
* @return The DataStream representing the elements.
*/
public <OUT extends Serializable> DataStreamSource<OUT> fromCollection(Collection<OUT> data) {
if (data == null) {
throw new NullPointerException("Collection must not be null");
}
if (data.isEmpty()) {
throw new IllegalArgumentException("Collection must not be empty");
}
TypeWrapper<OUT> outTypeWrapper = new ObjectTypeWrapper<OUT>(data.iterator().next());
DataStreamSource<OUT> returnStream = new DataStreamSource<OUT>(this, "elements",
outTypeWrapper);
try {
SourceFunction<OUT> function = new FromElementsFunction<OUT>(data);
jobGraphBuilder.addStreamVertex(returnStream.getId(), new SourceInvokable<OUT>(
new FromElementsFunction<OUT>(data)), null, new ObjectTypeWrapper<OUT>(data
.iterator().next()), "source", SerializationUtils.serialize(function), 1);
} catch (SerializationException e) {
throw new RuntimeException("Cannot serialize collection");
}
return returnStream;
}
示例6: addSource
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
/**
* Ads a data source thus opening a {@link DataStream}.
*
* @param function
* the user defined function
* @param parallelism
* number of parallel instances of the function
* @param <OUT>
* type of the returned stream
* @return the data stream constructed
*/
public <OUT> DataStreamSource<OUT> addSource(SourceFunction<OUT> function, int parallelism) {
TypeWrapper<OUT> outTypeWrapper = new FunctionTypeWrapper<OUT>(function,
SourceFunction.class, 0);
DataStreamSource<OUT> returnStream = new DataStreamSource<OUT>(this, "source",
outTypeWrapper);
try {
jobGraphBuilder.addStreamVertex(returnStream.getId(),
new SourceInvokable<OUT>(function), null, outTypeWrapper, "source",
SerializationUtils.serialize(function), parallelism);
} catch (SerializationException e) {
throw new RuntimeException("Cannot serialize SourceFunction");
}
return returnStream;
}
示例7: Color
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
public Color(String serializedString)
{
String[] args = serializedString.replace("{", "").replace("}", "").split(":");
if (args.length != 3)
throw new SerializationException("Invalid color string: " + serializedString);
red = Integer.parseInt(args[0]);
green = Integer.parseInt(args[1]);
blue = Integer.parseInt(args[2]);
}
示例8: deserializeEstimator
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
/**
* Deserialize a {@link LoadProfileEstimator} according to {@link #serialize(LoadProfileEstimator, JSONArray)}.
*
* @param jsonObject that should be deserialized
* @return the {@link LoadProfileEstimator}
*/
private LoadProfileEstimator deserializeEstimator(JSONObject jsonObject) {
if (jsonObject.has("key")) {
final String key = jsonObject.getString("key");
final LoadProfileEstimator estimator = LoadProfileEstimators.createFromSpecification(key, this.configuration);
if (estimator == null) {
throw new SerializationException("Could not create estimator for key " + key);
}
return estimator;
} else if (jsonObject.has("load")) {
final LoadProfile load = JsonSerializables.deserialize(jsonObject.getJSONObject("load"), LoadProfile.class);
return new ConstantLoadProfileEstimator(load);
}
throw new SerializationException(String.format("Cannot deserialize load estimator from %s.", jsonObject));
}
示例9: deserialize
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
/**
* Deserializes an object.
*
* @param json that should be serialized
* @return the deserialized object
*/
@SuppressWarnings("unchecked")
default T deserialize(JSONObject json) {
if (JsonSerializables.isJsonNull(json)) return null;
try {
final Class<?> classTag = JsonSerializables.getClassTag(json);
if (classTag == null) {
throw new IllegalArgumentException(String.format("Cannot determine class from %s.", json));
}
return this.deserialize(json, (Class<? extends T>) classTag);
} catch (ClassNotFoundException e) {
throw new SerializationException("Could not load class.", e);
}
}
示例10: innerHasNext
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
@Override
protected boolean innerHasNext() {
if (cachedElement != null) {
return true;
} else {
try {
cachedElement = readNext();
return cachedElement != null;
} catch (final SerializationException e) {
return false;
}
}
}
示例11: isEmptyOrInconsistent
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
public boolean isEmptyOrInconsistent() {
try {
getFirstValue();
getLastValue();
} catch (final Throwable t) {
if (Throwables.isCausedByType(t, SerializationException.class)) {
//e.g. fst: unable to find class for code 88 after version upgrade
log.warn("Table data for [%s] is inconsistent and needs to be reset. Exception during getLastValue: %s",
hashKey, t.toString());
return true;
} else {
//unexpected exception, since RemoteFastSerializingSerde only throws SerializingException
throw Throwables.propagate(t);
}
}
try (ICloseableIterator<File> files = readRangeFiles(null, null).iterator()) {
boolean noFileFound = true;
while (files.hasNext()) {
final File file = files.next();
if (!file.exists()) {
log.warn("Table data for [%s] is inconsistent and needs to be reset. Missing file: [%s]", hashKey,
file);
return true;
}
noFileFound = false;
}
return noFileFound;
}
}
示例12: fromBytes
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public synchronized E fromBytes(final byte[] bytes) {
if (bytes.length == 0) {
return null;
}
try {
return (E) coder.toObject(bytes);
} catch (final Throwable t) {
throw new SerializationException(t);
}
}
示例13: toXml
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
public static String toXml(Object obj) throws SerializationException {
StringWriter sw = new StringWriter();
try {
JAXBContext context = JAXBContext.newInstance(obj.getClass());
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(obj, sw);
return sw.toString();
} catch (JAXBException e) {
throw new SerializationException(e);
}
}
示例14: fromXml
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
/**
* Deserializes an XML String
*
* @param xml
* @return
*/
public static Object fromXml(String xml, String packageName) throws SerializationException {
StringReader in = new StringReader(xml);
try {
JAXBContext context = JAXBContext.newInstance(packageName);
Object obj = context
.createUnmarshaller().unmarshal(in);
return obj;
} catch (JAXBException e) {
throw new SerializationException(e);
}
}
示例15: serialize
import org.apache.commons.lang3.SerializationException; //导入依赖的package包/类
public byte[] serialize(Serializable o) {
try {
return xStream.toXML(o).getBytes();
} catch (BaseException e) {
throw new SerializationException(e);
}
}