Java-使用InputStream作为文件 [英] Java- using an InputStream as a File

查看:339
本文介绍了Java-使用InputStream作为文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 JODConverter . 生成PDF的方法的调用如下所示:

I'm trying to generate a PDF document from an uploaded ".docx" file using JODConverter. The call to the method that generates the PDF is something like this :

File inputFile = new File("document.doc");
File outputFile = new File("document.pdf");

// connect to an OpenOffice.org instance running on port 8100
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
connection.connect();

// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);

// close the connection
connection.disconnect();

我正在使用apache commons FileUpload 来处理docx文件的上传,我可以从中获取一个InputStream对象.我知道Java.io.File只是对系统中文件的抽象引用.

I'm using apache commons FileUpload to handle uploading the docx file, from which I can get an InputStream object. I'm aware that Java.io.File is just an abstract reference to a file in the system.

我想避免磁盘写操作(将InputStream保存到磁盘)和磁盘读操作(在JODConverter中读取保存的文件).

I want to avoid the disk write (saving the InputStream to disk) and the disk read (reading the saved file in JODConverter).

有什么办法可以获取引用输入流的File对象?避免磁盘IO的任何其他方法也可以!

Is there any way I can get a File object refering to an input stream? just any other way to avoid disk IO will also do!

我不在乎这是否会占用大量系统内存.该应用程序将被托管在一个很少有零个并行用户的LAN上.

I don't care if this will end up using a lot of system memory. The application is going to be hosted on a LAN with very little to zero number of parallel users.

推荐答案

基于文件的转换比基于流的转换更快(由

File-based conversions are faster than stream-based ones (provided by StreamOpenOfficeDocumentConverter) but they require the OpenOffice.org service to be running locally and have the correct permissions to the files.

尝试 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆