X-Git-Url: http://gitweb.fperrin.net/?p=DictionaryPC.git;a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2Fengine%2FWiktionarySplitter.java;h=290a58fccc1e38a6c36acdd44f2cb08cf42abb40;hp=6839904516abd6293c9cd6f6dcedc546ed39ecc7;hb=ee1dbfb669462305a1c07e4d804a90af79f5d39f;hpb=aad37bfcc3c1a1772d5fba894d7471c2b09b64ee diff --git a/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java b/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java index 6839904..290a58f 100644 --- a/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java +++ b/src/com/hughes/android/dictionary/engine/WiktionarySplitter.java @@ -14,10 +14,13 @@ package com.hughes.android.dictionary.engine; +import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.DataOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.InputStream; import java.io.IOException; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -30,6 +33,7 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import org.apache.xerces.jaxp.SAXParserFactoryImpl; +import org.apache.commons.compress.compressors.CompressorStreamFactory; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -83,7 +87,17 @@ public class WiktionarySplitter extends org.xml.sax.helpers.DefaultHandler { // Do it. try { - parser.parse(new File(pathToSelectorsEntry.getKey()), this); + File input = new File(pathToSelectorsEntry.getKey() + ".bz2"); + if (!input.exists()) input = new File(pathToSelectorsEntry.getKey() + ".gz"); + if (!input.exists()) input = new File(pathToSelectorsEntry.getKey() + ".xz"); + if (!input.exists()) { + // Fallback to uncompressed file + parser.parse(new File(pathToSelectorsEntry.getKey()), this); + } else { + InputStream compressedIn = new BufferedInputStream(new FileInputStream(input)); + InputStream in = new CompressorStreamFactory().createCompressorInputStream(compressedIn); + parser.parse(new BufferedInputStream(in), this); + } } catch (Exception e) { System.err.println("Exception during parse, lastPageTitle=" + lastPageTitle + ", titleBuilder=" + titleBuilder.toString()); throw e;