/** {@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; } 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); } }
@Override public S fromByteBuffer(ByteBuffer bytes) { if ((bytes == null) || !bytes.hasArray()) { return null; } bytes = bytes.duplicate(); bytes.rewind(); if (bytes.limit() < prefixBytes.remaining()) { log.error("Unprefixed value received, throwing exception..."); throw new HectorSerializationException("Unexpected prefix value"); } if (compareByteArrays(prefixBytes.array(), prefixBytes.arrayOffset() + prefixBytes.position(), prefixBytes.remaining(), bytes.array(), bytes.arrayOffset() + bytes.position(), prefixBytes.remaining()) != 0) { return null; // incorrect prefix, return nothing } bytes.position(prefixBytes.remaining()); S s = suffixSerializer.fromByteBuffer(bytes); return s; }
@Override public Object fromByteBuffer(ByteBuffer bytes) { if ((bytes == null) || !bytes.hasRemaining()) { return null; } try { int l = bytes.remaining(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes.array(), bytes.arrayOffset() + bytes.position(), l); ObjectInputStream ois; if(classLoader == null) { ois = new ObjectInputStream(bais); } else { ois = new CustomClassLoaderObjectInputStream(classLoader, bais); } Object obj = ois.readObject(); bytes.position(bytes.position() + (l - ois.available())); ois.close(); return obj; } catch (Exception ex) { throw new HectorSerializationException(ex); } }
/** {@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 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 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 public S fromByteBuffer(ByteBuffer bytes) { if ((bytes == null) || !bytes.hasArray()) { return null; } bytes = bytes.duplicate(); bytes.rewind(); if (compareByteArrays(prefixBytes.array(), prefixBytes.arrayOffset() + prefixBytes.position(), prefixBytes.remaining(), bytes.array(), bytes.arrayOffset() + bytes.position(), prefixBytes.remaining()) != 0) { log.error("Unprefixed value received, throwing exception..."); throw new HectorSerializationException("Unexpected prefix value"); } bytes.position(prefixBytes.remaining()); S s = suffixSerializer.fromByteBuffer(bytes); return s; }
@Override public S fromByteBuffer(ByteBuffer bytes) { if ((bytes == null) || !bytes.hasArray()) { return null; } bytes = bytes.duplicate(); bytes.rewind(); if (bytes.limit() < prefixBytes.remaining()) { log.error("Unprefixed value received, throwing exception..."); throw new HectorSerializationException("Unexpected prefix value"); } if (compareByteArrays(prefixBytes.array(), prefixBytes.arrayOffset() + prefixBytes.position(), prefixBytes.remaining(), bytes.array(), bytes.arrayOffset() + bytes.position(), prefixBytes.remaining()) != 0) { return null; // incorrect prefix, return nothing } bytes.position(prefixBytes.remaining()); S s = suffixSerializer.fromByteBuffer(bytes); return s; }
@Override public Object fromByteBuffer(ByteBuffer bytes) { if ((bytes == null) || !bytes.hasRemaining()) { return null; } try { int l = bytes.remaining(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes.array(), bytes.arrayOffset() + bytes.position(), l); ObjectInputStream ois; if(classLoader == null) { ois = new ObjectInputStream(bais); } else { ois = new CustomClassLoaderObjectInputStream(classLoader, bais); } Object obj = ois.readObject(); bytes.position(bytes.position() + (l - ois.available())); ois.close(); return obj; } catch (Exception ex) { throw new HectorSerializationException(ex); } }
@Override public Object fromByteBuffer(ByteBuffer bytes) { if ((bytes == null) || !bytes.hasRemaining()) { return null; } try { int l = bytes.remaining(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes.array(), bytes.arrayOffset() + bytes.position(), l); ObjectInputStream ois; if(classLoader == null) { ois = new ObjectInputStream(bais); } else { ois = new CustomClassLoaderObjectInputStream(classLoader, bais); } Object obj = ois.readObject(); bytes.position(bytes.position() + (l - ois.available())); ois.close(); return obj; } catch (Exception ex) { throw new HectorSerializationException(ex); } }