class XMLUtilities {

    public static InputStream writeXMLObjectToInputStreamAsync(final Object jaxbElement, Class<?>... classes)
    {
        final Class<?>[] contextClasses;
        if (classes == null || classes.length == 0)
        {
            contextClasses = new Class<?>[] { jaxbElement.getClass() };
        }
        else
        {
            contextClasses = classes;
        }
        PipedInputStream is = new PipedInputStream();
        final OutputStream os;
        try
        {
            os = new PipedOutputStream(is);
        }
        catch (IOException e)
        {
            LOGGER.error("Failed to create output stream: " + e, e);
            return null;
        }
        new Thread()
        {
            @Override
            public void run()
            {
                try
                {
                    JAXBContextHelper.getCachedContext(contextClasses).createMarshaller().marshal(jaxbElement, os);
                }
                catch (JAXBException e)
                {
                    LOGGER.error("Error marshalling JAXB object: " + e, e);
                }
                finally
                {
                    try
                    {
                        os.close();
                    }
                    catch (IOException e)
                    {
                        LOGGER.warn("Failed to close output stream: " + e, e);
                    }
                }
            }
        }.start();
        return is;
    }

    private  XMLUtilities();

}