1 package org.paneris.messageboard.receivemail;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.File;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7 import java.io.InputStream;
8 import java.io.OutputStream;
9 import java.util.Random;
10
11 import org.paneris.util.IoUtils;
12
13
14
15 public class WordToHTML {
16
17 private static Random tempGen = null;
18
19 public static byte[] translated(byte[] wordDoc,
20 String tempDir, String imgDir)
21 throws IOException {
22 return translated(new ByteArrayInputStream(wordDoc), tempDir, imgDir);
23 }
24
25 public static byte[] translated(InputStream wordDoc,
26 String tempDir, String imgDir)
27 throws IOException {
28
29 if (tempGen == null)
30 tempGen = new Random();
31
32 File temp = new File(
33 tempDir + "/__WordToHTML." + tempGen.nextLong() + ".doc");
34
35 try {
36 OutputStream tempO = new FileOutputStream(temp);
37 IoUtils.copy(wordDoc, 10000, tempO);
38 tempO.close();
39
40 String[] args = { "/usr/local/bin/wvHtml-wrapper", tempDir,
41 "--dir", imgDir, temp.getPath() };
42
43 return IoUtils.slurpOutputOf_bytes(args, 10000, 1000000);
44 }
45 finally {
46 temp.delete();
47 }
48 }
49 }