Java 类org.apache.commons.lang.SerializationException 实例源码

项目:sssj    文件:BinaryVectorStreamReader.java   
@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;
}
项目:DataCleaner    文件:Main.java   
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;
    }
}
项目:DataCleaner    文件:AnalysisResultSaveHandler.java   
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);
    }
}
项目:DataCleaner    文件:AnalysisResultSaveHandler.java   
/**
 * 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;
}
项目:ob1k    文件:MemcachedClientTest.java   
@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);
}
项目:bee    文件:ProtostuffSerializer.java   
@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);
    }
}
项目:bee    文件:ProtostuffSerializer.java   
@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();
    }
}
项目:DataCleaner    文件:AnalysisResultSaveHandler.java   
public boolean saveAttempt() {
    try {
        saveOrThrow();
        return true;
    } catch (final SerializationException e) {
        return false;
    }
}
项目:jresplus    文件:CookiesEncodeImpl.java   
public String encode(Object object) throws SerializationException {
    if (object == null) {
        return null;
    }
    return new String(Base64.encodeBase64(HessianZipSerializer
            .encode(object)));
}
项目:ob1k    文件:MessagePackTranscoder.java   
@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);
  }
}
项目:ob1k    文件:MessagePackTranscoder.java   
@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);
  }
}
项目:ob1k    文件:JsonTranscoder.java   
@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);
  }
}
项目:ob1k    文件:JsonTranscoder.java   
@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);
  }
}
项目:reef    文件:DefaultExceptionCodec.java   
@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();
  }
}
项目:googleads-java-lib    文件:JaxBDeserializer.java   
/**
 * 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);
  }
}
项目:googleads-java-lib    文件:JaxBDeserializer.java   
/**
 * Deserializes the object.
 *
 * @throws SerializationException if we cannot deserialize the object.
 */
public T deserialize(Source source) {
  try {
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    JAXBElement<T> jaxbElement = unmarshaller.unmarshal(source, clazz);
    return jaxbElement.getValue();
  } catch (JAXBException e) {
    throw new SerializationException(
        String.format("Could not deserialize %s object from source %s.", clazz, source), e);
  }
}
项目:googleads-java-lib    文件:JaxBSerializer.java   
/**
 * Constructs a JAX-WS serializer for the specified class.
 *
 * @param clazz Class to serialize.
 * @param qname A QName representing the local name for the class - this will be used as the root
 *        tag name.
 * @throws SerializationException if unable to construct the serializer.
 */
public JaxBSerializer(Class<T> clazz, QName qname) {
  this.clazz = clazz;
  this.qname = qname;
  try {
    this.jaxbContext = JAXBContext.newInstance(clazz);
  } catch (JAXBException e) {
    throw new SerializationException(
        String.format(
            "Could not construct a serializer for class %s and QName %s.", clazz, qname),
        e);
  }
}
项目:googleads-java-lib    文件:JaxBSerializer.java   
/**
 * Serializes the object with the option to include or exclude the XML declaration.
 *
 * @throws SerializationException if we cannot serialize the object.
 */
public String serialize(T object, boolean includeXmlDeclaration) {
  try {
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.valueOf(!includeXmlDeclaration));
    JAXBElement<T> element =
        new JAXBElement<T>(qname, clazz, object);
    StringWriter stringWriter = new StringWriter();
    marshaller.marshal(element, stringWriter);
    return stringWriter.toString();
  } catch (JAXBException e) {
    throw new SerializationException(String.format("Could not serialize object: %s.", object), e);
  }
}
项目:bee    文件:AbstractSerializer.java   
@Override
public InvocationRequest newRequest(InvokerContext invokerContext) throws SerializationException {
    return new DefaultRequest(invokerContext);
}
项目:bee    文件:AbstractSerializer.java   
@Override
public InvocationResponse newResponse() throws SerializationException {
    return new DefaultResponse();
}
项目:bee    文件:ProtostuffSerializer.java   
@Override
public DefaultRequest deserializeRequest(byte[] bytes) throws SerializationException {
    return deserialize(bytes, DefaultRequest.class);
}
项目:bee    文件:ProtostuffSerializer.java   
@Override
public DefaultResponse deserializeResponse(byte[] bytes) throws SerializationException {
    return deserialize(bytes, DefaultResponse.class);
}
项目:bee    文件:ProtostuffSerializer.java   
@Override
public byte[] serializeRequest(Object request) throws SerializationException {
    return serialize(request);
}
项目:bee    文件:ProtostuffSerializer.java   
@Override
public byte[] serializeResponse(Object response) throws SerializationException {
    return serialize(response);
}
项目:DataCleaner    文件:AnalysisResultSaveHandler.java   
public void saveOrThrow() throws SerializationException {
    saveOrThrow(_analysisResult, _resource);
}
项目:jresplus    文件:CookiesEncodeImpl.java   
public Object decode(String str) throws SerializationException {
    if (StringUtil.isEmpty(str) == true) {
        return null;
    }
    return HessianZipSerializer.decode(Base64.decodeBase64(str));
}
项目:transloader    文件:SerializationCloningStrategy.java   
/**
 * {@inheritDoc}
 * 
 * @throws ClassCastException if the given <code>original</code> object is not {@link Serializable}
 * @throws SerializationException if serialization fails
 * @throws IOException if input fails during deserialization
 * @throws ClassNotFoundException if the <code>targetClassLoader</code> cannot find a required class
 */
public Object cloneObjectUsingClassLoader(Object original, ClassLoader targetClassLoader)
        throws ClassCastException, SerializationException, IOException, ClassNotFoundException {
    Assert.areNotNull(original, targetClassLoader);
    byte[] serializedOriginal = SerializationUtils.serialize((Serializable) original);
    return new ClassLoaderObjectInputStream(targetClassLoader, new ByteArrayInputStream(serializedOriginal)).readObject();
}
项目:java-sandbox    文件:SerializationCloningStrategy.java   
/**
    * {@inheritDoc}
    *
    * @throws ClassCastException     if the given <code>original</code> object is not {@link Serializable}
    * @throws SerializationException if serialization fails
    * @throws IOException            if input fails during deserialization
    * @throws ClassNotFoundException if the <code>targetClassLoader</code> cannot find a required class
    */
   public Object cloneObjectUsing(ClassLoader targetLoader, Object original) throws ClassCastException, SerializationException, IOException, ClassNotFoundException {
       Assert.areNotNull(targetLoader, original);
       byte[] serializedOriginal = SerializationUtils.serialize((Serializable) original);
       return deserialize(serializedOriginal, targetLoader);
}
项目:bee    文件:Serializer.java   
public <T> T deserialize(byte[] bytes, Class<T> clazz) throws SerializationException;
项目:bee    文件:Serializer.java   
public Object deserializeRequest(byte[] bytes) throws SerializationException;
项目:bee    文件:Serializer.java   
public DefaultResponse deserializeResponse(byte[] bytes) throws SerializationException;
项目:bee    文件:Serializer.java   
public byte[] serialize(Object body) throws SerializationException;
项目:bee    文件:Serializer.java   
public byte[] serializeRequest(Object request) throws SerializationException;
项目:bee    文件:Serializer.java   
public byte[] serializeResponse(Object response) throws SerializationException;
项目:bee    文件:Serializer.java   
public InvocationRequest newRequest(InvokerContext invokerContext) throws SerializationException;
项目:bee    文件:Serializer.java   
public InvocationResponse newResponse() throws SerializationException;
项目:jresplus    文件:Encode.java   
public String encode(Object object) throws SerializationException;
项目:jresplus    文件:Encode.java   
public Object decode(String str) throws SerializationException;