/** * Write the passed object to a {@link ByteBuffer}. * * @param aObject * The object to be written. May not be <code>null</code>. * @param aBuffer * The byte buffer to write to. If the buffer is too small, it is * automatically extended. May not be <code>null</code>. * @return {@link ESuccess} * @throws BufferOverflowException * If the ByteBuffer is too small */ @Nonnull default ESuccess write (@Nonnull final JAXBTYPE aObject, @Nonnull final ByteBuffer aBuffer) { return write (aObject, new ByteBufferOutputStream (aBuffer, false)); }
/** * Write the passed object to a {@link ByteBuffer} and return it (write). * * @param aObject * The object to be written. May not be <code>null</code>. * @return <code>null</code> if the passed domain object could not be * converted because of validation errors. */ @Nullable default ByteBuffer getAsByteBuffer (@Nonnull final JAXBTYPE aObject) { try (final ByteBufferOutputStream aBBOS = new ByteBufferOutputStream ()) { if (USE_JAXB_CHARSET_FIX) { return write (aObject, SafeXMLStreamWriter.create (aBBOS, getXMLWriterSettings ())).isFailure () ? null : aBBOS.getBuffer (); } return write (aObject, aBBOS).isFailure () ? null : aBBOS.getBuffer (); } }
/** * Write the passed object to a byte array and return the created byte array * (write). * * @param aObject * The object to be written. May not be <code>null</code>. * @return <code>null</code> if the passed domain object could not be * converted because of validation errors. */ @Nullable default byte [] getAsBytes (@Nonnull final JAXBTYPE aObject) { try (final ByteBufferOutputStream aBBOS = new ByteBufferOutputStream ()) { if (USE_JAXB_CHARSET_FIX) { return write (aObject, SafeXMLStreamWriter.create (aBBOS, getXMLWriterSettings ())).isFailure () ? null : aBBOS.getAsByteArray (); } return write (aObject, aBBOS).isFailure () ? null : aBBOS.getAsByteArray (); } }