2

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();

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.

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

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!

EDIT: 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.

4

3 に答える 3

2

それを実行してコードを堅固にする方法はありません。1つは、この.convert()メソッドはFile引数として2つのsのみを取ります。

したがって、これは、拡張する必要があることを意味します。Fileこれは理論的には可能ですが、ライブラリコードを詳しく調べる必要があるため、非常に脆弱です。ライブラリコードはいつでも変更され、拡張クラスが機能しなくなる可能性があります。

(もちろん、RAMでバックアップされたファイルシステムを使用し、そのファイルシステムからの読み取り/書き込みを行う場合は、ディスクの書き込みを回避する方法があります)

于 2013-01-05T05:53:02.290 に答える
2

ファイルベースの変換は、ストリームベースの変換 ( StreamOpenOfficeDocumentConverterによって提供される) よりも高速ですが、OpenOffice.org サービスがローカルで実行されており、ファイルに対する適切なアクセス許可を持っている必要があります。

ディスクへの書き込みを避けるためにドキュメントを試してください:

convert(java.io.InputStream inputStream, DocumentFormat inputFormat, java.io.OutputStream outputStream, DocumentFormat outputFormat) 
于 2013-01-05T06:31:38.133 に答える
1

コモンズfileuploadがとにかくファイルシステムへのアップロードを書き込んだ可能性があります。

FileItemがDiskFileItemのインスタンスであるかどうかを確認します。この場合、DiskFileItemの書き込み実装は、渡したファイルオブジェクトにファイルを移動しようとします。書き込みがすでに行われているため、余分なディスクIOは発生していません。

于 2013-01-05T06:53:23.630 に答える