class TXTParser extends AbstractParser {

	@Override
	public String parse(File file, String filename, String encoding, Locale locale, String tenant) {
		FileInputStream fis = null;
		BufferedInputStream bis = null;
		try {
			fis = new FileInputStream(file);
			bis = new BufferedInputStream(fis);

			String enc = encoding;
			if (StringUtils.isEmpty(enc)) {
				// Determine the most probable encoding
				try {
					CharsetDetector cd = new CharsetDetector();
					cd.setText(bis);
					CharsetMatch cm = cd.detect();
					if (cm != null) {
						if (Charset.isSupported(cm.getName()))
							enc = cm.getName();
					}
				} catch (Throwable th) {
					log.warn("Error during TXT fileNameCharset detection", th);
				}
			}
			return parse(bis, filename, enc, locale, tenant);
		} catch (Throwable ex) {
			log.warn("Failed to extract TXT text content", ex);
		} finally {
			try {
				if (bis != null)
					bis.close();
				if (fis != null)
					fis.close();
			} catch (IOException e) {
				log.warn(e.getMessage(), e);
			}
		}
		return "";
	}

}