本文整理汇总了Java中org.apache.commons.lang.SerializationException类的典型用法代码示例。如果您正苦于以下问题:Java SerializationException类的具体用法?Java SerializationException怎么用?Java SerializationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerializationException类属于org.apache.commons.lang包,在下文中一共展示了SerializationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: next
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
@Override
public Vector next() {
try {
// refill the ByteBuffer if not enough bytes left to read
if (bb.remaining() < Ints.BYTES)
if (refill() < Ints.BYTES)
throw new IllegalStateException("Could not read from input file");
// peek the size of the vector
bb.mark();
// vector size in bytes = int + long + size * (int + double)
final int vectorBytes = (bb.getInt() + 1) * (Ints.BYTES + Doubles.BYTES);
bb.reset();
if (bb.remaining() < vectorBytes)
if (refill() < vectorBytes)
throw new IllegalStateException("Internal vector buffer too small");
// now we are sure that the ByteBuffer contains the whole next vector
current.read(bb);
} catch (IOException e) {
e.printStackTrace();
throw new SerializationException();
}
numReads++;
return current;
}
示例2: saveResult
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
private static void saveResult(final AnalysisResultFuture result, final Resource resultResource) {
final AnalysisResultSaveHandler analysisResultSaveHandler =
new AnalysisResultSaveHandler(result, resultResource);
try {
analysisResultSaveHandler.saveOrThrow();
} catch (final SerializationException e) {
// attempt to save what we can - and then rethrow
final AnalysisResult safeAnalysisResult = analysisResultSaveHandler.createSafeAnalysisResult();
if (safeAnalysisResult == null) {
logger.error("Serialization of result failed without any safe result elements to persist");
} else {
final Map<ComponentJob, AnalyzerResult> unsafeResultElements =
analysisResultSaveHandler.getUnsafeResultElements();
logger.error("Serialization of result failed with the following unsafe elements: {}",
unsafeResultElements);
logger.warn("Partial AnalysisResult will be persisted to filename '{}'",
resultResource.getQualifiedPath());
analysisResultSaveHandler.saveWithoutUnsafeResultElements();
}
// rethrow the exception regardless
throw e;
}
}
示例3: saveOrThrow
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
private static void saveOrThrow(final AnalysisResult analysisResult, final Resource resource) {
final SimpleAnalysisResult simpleAnalysisResult;
if (analysisResult instanceof SimpleAnalysisResult) {
simpleAnalysisResult = (SimpleAnalysisResult) analysisResult;
} else {
simpleAnalysisResult =
new SimpleAnalysisResult(analysisResult.getResultMap(), analysisResult.getCreationDate());
}
final OutputStream out = resource.write();
try {
SerializationUtils.serialize(simpleAnalysisResult, out);
} catch (final SerializationException e) {
logger.error("Error serializing analysis result: " + analysisResult, e);
throw e;
} finally {
FileHelper.safeClose(out);
}
}
示例4: getUnsafeResultElements
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
/**
* Gets a map of unsafe result elements, ie. elements that cannot be saved
* because serialization fails.
*
* @return
*/
public Map<ComponentJob, AnalyzerResult> getUnsafeResultElements() {
if (_unsafeResultElements == null) {
_unsafeResultElements = new LinkedHashMap<>();
final Map<ComponentJob, AnalyzerResult> resultMap = _analysisResult.getResultMap();
for (final Entry<ComponentJob, AnalyzerResult> entry : resultMap.entrySet()) {
final AnalyzerResult analyzerResult = entry.getValue();
try {
SerializationUtils.serialize(analyzerResult, new NullOutputStream());
} catch (final SerializationException e) {
_unsafeResultElements.put(entry.getKey(), analyzerResult);
}
}
}
return _unsafeResultElements;
}
示例5: testMultiget_TranscoderExecption
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
@Test(expected = ExecutionException.class)
public void testMultiget_TranscoderExecption() throws ExecutionException, InterruptedException, TimeoutException {
final Transcoder<Serializable> transcoder = new Transcoder<Serializable>() {
@Override
public Serializable decode(final byte[] b) {
throw new SerializationException("QQQQQ YYYYY");
}
@Override
public byte[] encode(final Serializable t) {
return SerializationUtils.serialize(t);
}
};
final MemcachedClient<Object, Serializable> client = createClient(transcoder);
client.setAsync("meh", "its here").get();
client.getBulkAsync(Lists.newArrayList("meh", "bah")).get(1, TimeUnit.MINUTES);
}
示例6: deserialize
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
@Override
public <T> T deserialize(byte[] bytes, Class<T> clazz) throws SerializationException {
try {
T message = clazz.newInstance();
Schema schema = getSchema(clazz);
ProtostuffIOUtil.mergeFrom(bytes, message, schema);
return message;
} catch (Throwable e) {
throw new SerializationException(e.getMessage(), e);
}
}
示例7: serialize
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
@Override
public byte[] serialize(Object obj) throws SerializationException {
LinkedBuffer buffer = LinkedBuffer.allocate(1024);
try {
Schema schema = getSchema(obj.getClass());
return ProtostuffIOUtil.toByteArray(obj, schema, buffer);
} catch (Throwable e) {
throw new SerializationException(e.getMessage(), e);
} finally {
buffer.clear();
}
}
示例8: saveAttempt
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
public boolean saveAttempt() {
try {
saveOrThrow();
return true;
} catch (final SerializationException e) {
return false;
}
}
示例9: encode
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
public String encode(Object object) throws SerializationException {
if (object == null) {
return null;
}
return new String(Base64.encodeBase64(HessianZipSerializer
.encode(object)));
}
示例10: decode
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public T decode(final byte[] b) {
final Template<?> template = messagePack.lookup(valueType);
try {
final Value value = messagePack.read(b);
return (T) template.read(new Converter(messagePack, value), null);
} catch (final IOException e) {
throw new SerializationException("Failed to decode to type " + valueType.getTypeName(), e);
}
}
示例11: encode
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
@Override
public byte[] encode(final T t) {
try {
return messagePack.write(t);
} catch (final IOException e) {
throw new SerializationException("Failed to encode input " + t.getClass().getSimpleName() + " to type " + valueType.getTypeName(), e);
}
}
示例12: decode
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
@Override
public T decode(final byte[] b) {
try {
return objectMapper.readValue(b, valueType);
} catch (final IOException e) {
throw new SerializationException("Failed to decode to type " + valueType.getSimpleName(), e);
}
}
示例13: encode
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
@Override
public byte[] encode(final T t) {
try {
return objectMapper.writeValueAsBytes(t);
} catch (final JsonProcessingException e) {
throw new SerializationException("Failed to encode input " + t.getClass().getSimpleName() + " to type " + valueType.getSimpleName(), e);
}
}
示例14: fromBytes
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
@Override
public Optional<Throwable> fromBytes(final byte[] bytes) {
try {
return Optional.<Throwable>of((Throwable) SerializationUtils.deserialize(bytes));
} catch (SerializationException | IllegalArgumentException e) {
LOG.log(Level.FINE, "Unable to deserialize a Throwable.", e);
return Optional.empty();
}
}
示例15: JaxBDeserializer
import org.apache.commons.lang.SerializationException; //导入依赖的package包/类
/**
* Constructs a JAX-WS deserializer for the specified class.
*
* @param clazz Class to deserialize.
* @throws SerializationException if unable to construct the deserializer.
*/
public JaxBDeserializer(Class<T> clazz) {
this.clazz = clazz;
try {
this.jaxbContext = JAXBContext.newInstance(clazz);
} catch (JAXBException e) {
throw new SerializationException(
String.format("Could not construct deserializer for class: %s.", clazz), e);
}
}