-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New way of finding hidden and visible sheets to avoid gc overhead lim…
…it exceeded exception. Just proof of concept, still needs to be tidied up
- Loading branch information
Matthew
authored and
Matthew
committed
Sep 1, 2018
1 parent
c119289
commit f56f9eb
Showing
6 changed files
with
262 additions
and
9 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/main/java/com/poiji/bind/mapping/WorkBookContentHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.poiji.bind.mapping; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.xml.sax.Attributes; | ||
import org.xml.sax.ContentHandler; | ||
import org.xml.sax.Locator; | ||
import org.xml.sax.SAXException; | ||
|
||
/** | ||
* | ||
* @author Matthew 2018/09/01 | ||
*/ | ||
public class WorkBookContentHandler implements ContentHandler { | ||
|
||
public List<WorkBookSheet> sheets = new ArrayList<>(); | ||
private WorkBookSheet individualSheet; | ||
|
||
@Override | ||
public void setDocumentLocator(Locator locator) { | ||
} | ||
|
||
@Override | ||
public void startDocument() throws SAXException { | ||
} | ||
|
||
@Override | ||
public void endDocument() throws SAXException { | ||
} | ||
|
||
@Override | ||
public void startPrefixMapping(String prefix, String uri) throws SAXException { | ||
} | ||
|
||
@Override | ||
public void endPrefixMapping(String prefix) throws SAXException { | ||
} | ||
|
||
@Override | ||
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { | ||
|
||
if (qName.equals("sheet")) { | ||
individualSheet = new WorkBookSheet(); | ||
|
||
for (int i = 0; i < atts.getLength(); i++) { | ||
|
||
// Attribute: name:Sheet3 | ||
// Attribute: sheetId:3 | ||
// Attribute: state:hidden | ||
if (atts.getQName(i).equals("name")) { | ||
individualSheet.name = atts.getValue(i); | ||
} | ||
if (atts.getQName(i).equals("sheetId")) { | ||
individualSheet.sheetId = atts.getValue(i); | ||
} | ||
if (atts.getQName(i).equals("state")) { | ||
individualSheet.state = atts.getValue(i); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void endElement(String uri, String localName, String qName) throws SAXException { | ||
|
||
if (qName.equals("sheet")) { | ||
sheets.add(individualSheet); | ||
individualSheet = null; | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void characters(char[] ch, int start, int length) throws SAXException { | ||
} | ||
|
||
@Override | ||
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { | ||
} | ||
|
||
@Override | ||
public void processingInstruction(String target, String data) throws SAXException { | ||
} | ||
|
||
@Override | ||
public void skippedEntity(String name) throws SAXException { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.poiji.bind.mapping; | ||
|
||
/** | ||
* | ||
* @author Matthew 2018/09/01 | ||
*/ | ||
public class WorkBookSheet { | ||
|
||
public String name; | ||
public String sheetId; | ||
public String state; | ||
|
||
@Override | ||
public String toString() { | ||
return "WorkBookSheet{" + "name=" + name + ", sheetId=" + sheetId + ", state=" + state + '}'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/java/com/poiji/deserialize/DeserializersHiddenSheetLargeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.poiji.deserialize; | ||
|
||
import com.poiji.bind.Poiji; | ||
import com.poiji.deserialize.model.byid.Person; | ||
import com.poiji.option.PoijiOptions; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import static com.poiji.util.Data.unmarshallingPersons; | ||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assert.fail; | ||
|
||
@RunWith(Parameterized.class) | ||
public class DeserializersHiddenSheetLargeTest { | ||
|
||
private final String path; | ||
private final List<Person> expectedPersonList; | ||
private final Class<?> expectedException; | ||
|
||
public DeserializersHiddenSheetLargeTest(String path, List<Person> expectedPersonList, Class<?> expectedException) { | ||
this.path = path; | ||
this.expectedPersonList = expectedPersonList; | ||
this.expectedException = expectedException; | ||
} | ||
|
||
@Parameterized.Parameters(name = "{index}: ({0})={1}") | ||
public static Iterable<Object[]> queries() { | ||
return Arrays.asList(new Object[][]{ | ||
{"src/test/resources/hidden_very_large.xlsx", unmarshallingPersons(), null}, | ||
{"src/test/resources/hidden_very_large.xls", unmarshallingPersons(), null} | ||
}); | ||
} | ||
|
||
@Test | ||
public void testIgnoreHiddenSheets() { | ||
try { | ||
PoijiOptions poijiOptions = PoijiOptions.PoijiOptionsBuilder.settings().ignoreHiddenSheets(true).build(); | ||
|
||
List<Person> people = Poiji.fromExcel(new File(path), Person.class, poijiOptions); | ||
assertEquals(expectedPersonList.get(0).getRow(), people.get(0).getRow()); | ||
assertEquals(expectedPersonList.get(1).getRow(), people.get(1).getRow()); | ||
assertEquals(expectedPersonList.get(2).getRow(), people.get(2).getRow()); | ||
assertEquals(expectedPersonList.get(3).getRow(), people.get(3).getRow()); | ||
assertEquals(expectedPersonList.get(4).getRow(), people.get(4).getRow()); | ||
} catch (Exception e) { | ||
if (expectedException == null) { | ||
fail(e.getMessage()); | ||
} else { | ||
assertThat(e, instanceOf(expectedException)); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void testProcessHiddenSheets() { | ||
PoijiOptions poijiOptions = PoijiOptions.PoijiOptionsBuilder.settings().ignoreHiddenSheets(false).build(); | ||
List<Person> people = Poiji.fromExcel(new File(path), Person.class, poijiOptions); | ||
assertEquals(people.size(), 0); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.