/** {@inheritDoc} */ @Override public Object fromByteBuffer(ByteBuffer bytes) { if (bytes == null || !bytes.hasRemaining()) { return null; } int l = bytes.remaining(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes.array(), bytes.arrayOffset() + bytes.position(), l); try { XMLStreamReader reader = createStreamReader(bais); Object ret = unmarshaller.get().unmarshal(reader); reader.close(); return ret; } catch (JAXBException e) { throw new HectorSerializationException( "Jaxb exception occurred during deserialization.", e); } catch (XMLStreamException e) { throw new HectorSerializationException("Exception reading XML stream.", e); } }
/** {@inheritDoc} */ @Override public ByteBuffer toByteBuffer(Object obj) { if (obj == null) { return null; } ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try { XMLStreamWriter writer = createStreamWriter(buffer); marshaller.get().marshal(obj, writer); writer.flush(); writer.close(); } catch (JAXBException e) { throw new HectorSerializationException("Object to serialize " + obj + " does not seem compatible with the configured JaxbContext;" + " note this Serializer works only with JAXBable objects.", e); } catch (XMLStreamException e) { throw new HectorSerializationException( "Exception occurred writing XML stream.", e); } return ByteBuffer.wrap(buffer.toByteArray()); }
@Override protected Serializer<Object> getSerializer() { return new JaxbSerializer(JaxbString.class); }
/** {@inheritDoc} */ @Override public Object fromByteBuffer(ByteBuffer bytes) { if (bytes == null || !bytes.hasRemaining()) { return null; } int l = bytes.remaining(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes.array(), bytes.arrayOffset() + bytes.position(), l); try { XMLStreamReader reader = createStreamReader(bais); Object ret = unmarshaller.get().unmarshal(reader); reader.close(); return ret; } catch (JAXBException e) { throw new HectorSerializationException( "Jaxb exception occurred during deserialization.", e); } catch (XMLStreamException e) { throw new HectorSerializationException("Exception reading XML stream.", e); } }
/** {@inheritDoc} */ @Override public ByteBuffer toByteBuffer(Object obj) { if (obj == null) { return null; } ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try { XMLStreamWriter writer = createStreamWriter(buffer); marshaller.get().marshal(obj, writer); writer.flush(); writer.close(); } catch (JAXBException e) { throw new HectorSerializationException("Object to serialize " + obj + " does not seem compatible with the configured JaxbContext;" + " note this Serializer works only with JAXBable objects.", e); } catch (XMLStreamException e) { throw new HectorSerializationException( "Exception occurred writing XML stream.", e); } return ByteBuffer.wrap(buffer.toByteArray()); }
/** {@inheritDoc} */ @Override public Object fromByteBuffer(ByteBuffer bytes) { if (bytes == null || !bytes.hasRemaining()) { return null; } ByteArrayInputStream bais = new ByteArrayInputStream(bytes.array()); try { XMLStreamReader reader = createStreamReader(bais); Object ret = unmarshaller.get().unmarshal(reader); reader.close(); return ret; } catch (JAXBException e) { throw new HectorSerializationException( "Jaxb exception occurred during deserialization.", e); } catch (XMLStreamException e) { throw new HectorSerializationException("Exception reading XML stream.", e); } }
/** {@inheritDoc} */ @Override public ByteBuffer toByteBuffer(Object obj) { if (obj == null) { return null; } ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try { XMLStreamWriter writer = createStreamWriter(buffer); marshaller.get().marshal(obj, writer); writer.flush(); writer.close(); } catch (JAXBException e) { throw new HectorSerializationException("Object to serialize " + obj + " does not seem compatible with the configured JaxbContext;" + " note this Serializer works only with JAXBable objects.", e); } catch (XMLStreamException e) { throw new HectorSerializationException( "Exception occurred writing XML stream.", e); } return ByteBuffer.wrap(buffer.toByteArray()); }