XSSF: reduce memory usage by specifing default namespace for string keys in SharedStringsTable
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1092089 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8dbcaac6fb
commit
ade6735c43
@ -20,10 +20,7 @@ package org.apache.poi.xssf.model;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
@ -86,6 +83,14 @@ public class SharedStringsTable extends POIXMLDocumentPart {
|
|||||||
|
|
||||||
private SstDocument _sstDoc;
|
private SstDocument _sstDoc;
|
||||||
|
|
||||||
|
private final static XmlOptions options = new XmlOptions();
|
||||||
|
static {
|
||||||
|
options.put( XmlOptions.SAVE_INNER );
|
||||||
|
options.put( XmlOptions.SAVE_AGGRESSIVE_NAMESPACES );
|
||||||
|
options.put( XmlOptions.SAVE_USE_DEFAULT_NAMESPACE );
|
||||||
|
options.setSaveImplicitNamespaces(Collections.singletonMap("", "http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
|
||||||
|
}
|
||||||
|
|
||||||
public SharedStringsTable() {
|
public SharedStringsTable() {
|
||||||
super();
|
super();
|
||||||
_sstDoc = SstDocument.Factory.newInstance();
|
_sstDoc = SstDocument.Factory.newInstance();
|
||||||
@ -112,7 +117,7 @@ public class SharedStringsTable extends POIXMLDocumentPart {
|
|||||||
count = (int)sst.getCount();
|
count = (int)sst.getCount();
|
||||||
uniqueCount = (int)sst.getUniqueCount();
|
uniqueCount = (int)sst.getUniqueCount();
|
||||||
for (CTRst st : sst.getSiArray()) {
|
for (CTRst st : sst.getSiArray()) {
|
||||||
stmap.put(st.toString(), cnt);
|
stmap.put(getKey(st), cnt);
|
||||||
strings.add(st);
|
strings.add(st);
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
@ -121,6 +126,10 @@ public class SharedStringsTable extends POIXMLDocumentPart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getKey(CTRst st) {
|
||||||
|
return st.xmlText(options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a string item by index
|
* Return a string item by index
|
||||||
*
|
*
|
||||||
@ -164,7 +173,7 @@ public class SharedStringsTable extends POIXMLDocumentPart {
|
|||||||
* @return index the index of added entry
|
* @return index the index of added entry
|
||||||
*/
|
*/
|
||||||
public int addEntry(CTRst st) {
|
public int addEntry(CTRst st) {
|
||||||
String s = st.toString();
|
String s = getKey(st);
|
||||||
count++;
|
count++;
|
||||||
if (stmap.containsKey(s)) {
|
if (stmap.containsKey(s)) {
|
||||||
return stmap.get(s);
|
return stmap.get(s);
|
||||||
|
Loading…
Reference in New Issue
Block a user