@Override
	public void run() {
		super.run();
		mUi.updateProgressState("Parser started", 0);
		
		try
		{
			if (mInputDictionary != null)
				addWordsFromInputStream(mInputDictionary, true, mTotalDictionaryChars, LOOKING_FOR_WORD_START);
			addWordsFromInputStream(mInput, (mInputDictionary == null), mTotalChars, LOOKING_FOR_SPACE);
		} catch (IOException e) {
			e.printStackTrace();
			mUi.showErrorMessage(e.getMessage());
		}
		finally
		{
			mUi.updateProgressState("Parser ending...", 0);
			try {
				mInput.close();
				mUi.updateProgressState("Sorting words (have "+mWords.size()+" words)...", 0);
				List<WordWithCount> sortedList = removeNonFrequentWords();
				mUi.updateProgressState("Creating XML (will use "+mMaxWords+" words)...", 0);
				createXml(sortedList);
				mOutput.flush();
				mOutput.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				mUi.showErrorMessage(e.getMessage());
			}
			mUi.updateProgressState("Parser ended. Found "+mWords.size()+" words.", 100);
			mUi.onEnded();
		}
	}