ASF Bugzilla – Attachment 34997 Details for
Bug 61104
new XWPFDocument(fis) is blocked
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
code file
DocxExtractor.java (text/plain), 2.31 KB, created by
zxh
on 2017-05-18 13:26:19 UTC
(
hide
)
Description:
code file
Filename:
MIME Type:
Creator:
zxh
Created:
2017-05-18 13:26:19 UTC
Size:
2.31 KB
patch
obsolete
>package io.transwarp.docutils; > >import io.transwarp.config.Constant; >import org.apache.poi.openxml4j.exceptions.InvalidFormatException; >import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >import org.apache.poi.openxml4j.opc.OPCPackage; >import org.apache.poi.xwpf.extractor.XWPFWordExtractor; >import org.apache.poi.xwpf.usermodel.XWPFDocument; >import org.apache.poi.xwpf.usermodel.XWPFParagraph; >import org.apache.xmlbeans.XmlException; >import org.slf4j.Logger; >import org.slf4j.LoggerFactory; > >import java.io.*; >import java.util.List; > >/** > * extract text from **.docx( word 2007) > * Created by zxh on 2017/5/1. > */ >public class DocxExtractor { > private static final Logger LOGGER = LoggerFactory.getLogger(DocxExtractor.class); > private File file; > private String outDir; > > public DocxExtractor(File file, String out) { > this.file = file; > this.outDir = out; > } > > public void extract() { > String textFile = outDir + "\\" + file.getName() + ".txt"; > XWPFDocument document = null; > XWPFWordExtractor extractor = null; > BufferedWriter writer = null; > > try { > writer = new BufferedWriter(new FileWriter(textFile)); > InputStream is = new FileInputStream(file); > > LOGGER.info("bytes:{}", is.available()); > LOGGER.info("SIGN1"); > document = new XWPFDocument(is); > LOGGER.info("SIGN2"); > if (null == document) { > LOGGER.info("document is null"); > } > > extractor = new XWPFWordExtractor(document); > writer.write(extractor.getText()); > writer.flush(); > LOGGER.info("Extract text from {}, write text to {}", file.getName(), textFile); > } catch (IOException e) { > LOGGER.error("Error in extracting text from {}, error msg is:{}", file.getAbsolutePath(), e.getMessage()); > } finally { > try { > if (null != document) { > document.close(); > } > > if (null != writer) { > writer.close(); > } > } catch (IOException e) { > LOGGER.error("Error in closing writer or document, msg is {}", e.getMessage()); > } > } > > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 61104
: 34997 |
34998