티스토리 뷰
Jsoup으로 xml 열심히 파싱하고 있었는데...
텍스트 파일 하나가 1.2G..
MemoryOutOfException이 발생하여 검색을 하니 StAX(Streaming API for XML) 를 쓰면 해결이 될거라고...
다만 StAX로 다하려니 파싱해서 데이터 넣기가 너무 불편해 ㅠㅠ
블록별로 변수에 넣어서 Jsoup으로 파싱!
결과적으론 1.2G 끄떡없다! ㅎㅎ
<Actors>
<ActorInfo id="1">
<Name>윤나무</Name>
<Age>27</Age>
</ActorInfo >
<ActorInfo id="2">
<Name>정동화</Name>
<Age>28</Age>
</ActorInfo>
<ActorInfo>
...
</ActorInfo>
</Actors>
public static void data() {
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
try {
String file = "data/bigFile.xml";
XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(new FileInputStream(file));
String data = "";
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
if(event.toString().contains("< ActorInfo ")){
// xml parsing with Jsoup
parseXml(data);
data = event.toString();
} else {
data += event.toString();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
참고 : http://proinlab.com/archives/1161
'Dev' 카테고리의 다른 글
Quartz Job Scheduler (쿼츠 스케줄러) (0) | 2018.01.09 |
---|---|
osx에서 jmeter로 테스트하기 (0) | 2017.11.20 |
Tomcat 환경변수 (0) | 2017.07.13 |
ssh : Permission denied. (0) | 2017.07.05 |
SNS url 캐시 삭제 (0) | 2016.12.21 |
- Total
- Today
- Yesterday
- getdate
- #csvreader
- JoinColumn
- iTerm
- 계층형
- oracle12
- CloudSearch
- OneToMany
- db connect
- could not initialize proxy - no Session
- tomcat
- Big xml 파싱
- aws cloudsearch
- StAX
- 엘라스틱서치
- org.hibernate.LazyInitializationException
- 단축키
- Elasticsearch
- Python
- JPA 오류
- JPA
- ojdbc7
- timestamp
- 서버 환경변수
- cloudsearch 비용
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |