FopFactory中如何将MemoryStream转为StreamSource?

How to transfer MemoryStream to StreamSource in FopFactory?

我在 FopFactory 运行 连接包 IKVM 和 FOP 中使用以下代码:

using org.apache.fop.tools;
using org.apache.fop.apps;
using org.xml.sax;
using java.io;

public void PDF(MemoryStream inpFile, string pdfFile)
{
OutputStream os = new BufferedOutputStream(new FileOutputStream(new java.io.File(pdfFile)));

    try
    {
        FopFactory fopFactory = FopFactory.newInstance();
        Fop fop = fopFactory.newFop("application/pdf", os);
        FOUserAgent foUserAgent = fop.getUserAgent();
        javax.xml.transform.TransformerFactory factory = javax.xml.transform.TransformerFactory.newInstance();
        javax.xml.transform.Transformer transformer = factory.newTransformer();
        javax.xml.transform.Source src = new javax.xml.transform.stream.StreamSource(inpFile);
        javax.xml.transform.Result res = new javax.xml.transform.sax.SAXResult(fop.getDefaultHandler());
        transformer.transform(src, res);
    }

    catch (Exception ex)
    {                
        throw ex;
    }

    finally
    {
        os.close();
    }
}

如何将 MemoryStream inpFile 传输到 FopFactory 中的javax.xml.transform.stream.StreamSource?

我找到了解决问题的办法。我从这里使用了 class DotNetInputStream 。在我的代码中,我添加了:

java.io.InputStream streamFile = new DotNetInputStream(inpFile);

并在 FopFactory 中将 InputStream 传输到 StreamSource:

javax.xml.transform.Source src = new javax.xml.transform.stream.StreamSource(streamFile);