import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ConnectException;import org.springframework.stereotype.Service;import com.artofsolving.jodconverter.DefaultDocumentFormatRegistry;
import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.DocumentFamily;
import com.artofsolving.jodconverter.DocumentFormat;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
import com.siyue.base.service.BaseService;import org.apache.log4j.Logger;@Service
public class OpenOfficeService extends BaseService{  
private static Logger logger = Logger.getLogger(LoginService.class);
   private String ip = "127.0.0.1";  
   // private String ip = "192.168.0.122";  
    private int port = 9900;  
    OpenOfficeConnection con = null;   
    public void convert(InputStream in,OutputStream out) {  
     String text="<!DOCTYPE html><html><head><title>word.html</title></head><body>转换</body></html>";
     in=new ByteArrayInputStream(text.getBytes());
        try {  
            if (con == null) {  
                con = new SocketOpenOfficeConnection(ip,port);  
            }  
            con.connect();  
            DocumentConverter converter = new OpenOfficeDocumentConverter(con);  
            DefaultDocumentFormatRegistry formatReg = new DefaultDocumentFormatRegistry();   
            DocumentFormat doc = formatReg.getFormatByFileExtension("odt") ;
            DocumentFormat html = formatReg.getFormatByFileExtension("html") ;
            converter.convert(in, html, out, doc);
            try {
in.close();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
            con.disconnect();  
        } catch (ConnectException e) {  
            logger.error("OpenOffice异常", e);  
            try {  
                if (con != null) {  
                    con.disconnect();  
                    con = null;  
                }  
            } catch (Exception e1) {  
                logger.error(e);  
            }  
        }  
    }  
转完之后是乱码