title: Apache Tika 1.16 TXTParser Failed to detect character encoding in sbt build
body: <p>I am building a project that I had in Eclipse using sbt assembly. I have a very large and complex build.sbt file as I had many conflicts.</p>
  
  <p>Everything works correctly for pdf, pptx, odt and docx files using the PDF, OOXML and OpenDocument parsers in tika 1.16. However when I try to parse a txt file (UTF-8 encoded) using the TXTParser I get the following error:</p>
  
  <pre><code>org.apache.tika.exception.TikaException: Failed to detect the character encoding of a document
      at org.apache.tika.detect.AutoDetectReader.detect(AutoDetectReader.java:77)
      at org.apache.tika.detect.AutoDetectReader.&lt;init&gt;(AutoDetectReader.java:108)
      at org.apache.tika.detect.AutoDetectReader.&lt;init&gt;(AutoDetectReader.java:114)
      at org.apache.tika.parser.txt.TXTParser.parse(TXTParser.java:79)`
  </code></pre>
  
  <p>from this line in my Scala code:</p>
  
  <pre><code>val content = theParser.parse(stream.open(), chandler, meta, pContext)
  </code></pre>
  
  <p>where stream is a PortableDataStream, chandler is a new BodyContentHandler, meta is a new Metadata and pContext is a new ParseContext.</p>
  
  <p>If I use AutoDetectParser instead I get the following error:</p>
  
  <pre><code>org.apache.jena.shared.SyntaxError: unknown
      at org.apache.jena.rdf.model.impl.NTripleReader.read(NTripleReader.java:73)
      at org.apache.jena.rdf.model.impl.NTripleReader.read(NTripleReader.java:58)
      at org.apache.jena.rdf.model.impl.ModelCom.read(ModelCom.java:305)
  </code></pre>
  
  <p>from this line in my Scala code:</p>
  
  <pre><code>val response = model.read(stream, null, "N-TRIPLES")
  </code></pre>
  
  <p>where stream is an InputStream.</p>
  
  <p>I think this is due to an empty response from Tika (so the same problem).</p>
  
  <p>I am pretty sure this is probably a dependency issue in my over-complex build.sbt file but after many hours of trying, I definitely need help.</p>
  
  <p>One positive is that everything works perfectly if no txt file is input so this is likely my last issue!</p>
  
  <p>Finally, here is my build.sbt file that I build using <code>sbt clean assembly</code>:</p>
  
  <pre><code>scalaVersion := "2.11.8"
  version      := "1.0.0"
  name := "crawldocs"
  conflictManager := ConflictManager.strict
  mainClass in assembly := Some("com.addlesee.crawling.CrawlHiccup")
  libraryDependencies ++= Seq(
    "org.apache.tika" % "tika-core" % "1.16",
    "org.apache.tika" % "tika-parsers" % "1.16" excludeAll(
      ExclusionRule(organization = "*", name = "guava")
    ),
      "com.blazegraph" % "bigdata-core" % "2.0.0" excludeAll(
      ExclusionRule(organization = "*", name = "collection-0.7"),
      ExclusionRule(organization = "*", name = "commons-cli"),
      ExclusionRule(organization = "*", name = "commons-codec"),
      ExclusionRule(organization = "*", name = "commons-csv"),
      ExclusionRule(organization = "*", name = "commons-io"),
      ExclusionRule(organization = "*", name = "commons-lang3"),
      ExclusionRule(organization = "*", name = "commons-logging"),
      ExclusionRule(organization = "*", name = "httpclient"),
      ExclusionRule(organization = "*", name = "httpclient-cache"),
      ExclusionRule(organization = "*", name = "httpcore"),
      ExclusionRule(organization = "*", name = "httpmime"),
      ExclusionRule(organization = "*", name = "jackson-annotations"),
      ExclusionRule(organization = "*", name = "jackson-core"),
      ExclusionRule(organization = "*", name = "jackson-databind"),
      ExclusionRule(organization = "*", name = "jcl-over-slf4j"),
      ExclusionRule(organization = "*", name = "jena-cmds"),
      ExclusionRule(organization = "*", name = "jena-rdfconnection"),
      ExclusionRule(organization = "*", name = "jena-tdb"),
      ExclusionRule(organization = "*", name = "jsonld-java"),
      ExclusionRule(organization = "*", name = "libthrift"),
      ExclusionRule(organization = "*", name = "log4j"),
      ExclusionRule(organization = "*", name = "slf4j-api"),
      ExclusionRule(organization = "*", name = "slf4j-log4j12"),
      ExclusionRule(organization = "*", name = "xercesImpl"),
      ExclusionRule(organization = "*", name = "xml-apis")
    ),
      "org.scalaj" %% "scalaj-http" % "2.3.0",
    "org.apache.jena" % "apache-jena" % "3.4.0" excludeAll(
      ExclusionRule(organization = "*", name = "commons-cli"),
      ExclusionRule(organization = "*", name = "commons-codec"),
      ExclusionRule(organization = "*", name = "commons-csv"),
      ExclusionRule(organization = "*", name = "commons-lang3"),
      ExclusionRule(organization = "*", name = "httpclient"),
      ExclusionRule(organization = "*", name = "httpclient-cache"),
      ExclusionRule(organization = "*", name = "httpcore"),
      ExclusionRule(organization = "*", name = "jackson-core"),
      ExclusionRule(organization = "*", name = "jackson-databind"),
      ExclusionRule(organization = "*", name = "jcl-over-slf4j"),
      ExclusionRule(organization = "*", name = "jena-rdfconnection"),
      ExclusionRule(organization = "*", name = "slf4j-api")
    ),
      "org.apache.jena" % "apache-jena-libs" % "3.4.0" excludeAll(
      ExclusionRule(organization = "*", name = "commons-cli"),
      ExclusionRule(organization = "*", name = "commons-codec"),
      ExclusionRule(organization = "*", name = "commons-csv"),
      ExclusionRule(organization = "*", name = "commons-lang3"),
      ExclusionRule(organization = "*", name = "httpclient"),
      ExclusionRule(organization = "*", name = "httpclient-cache"),
      ExclusionRule(organization = "*", name = "httpcore"),
      ExclusionRule(organization = "*", name = "jackson-core"),
      ExclusionRule(organization = "*", name = "jackson-databind"),
      ExclusionRule(organization = "*", name = "jcl-over-slf4j"),
      ExclusionRule(organization = "*", name = "jena-rdfconnection"),
      ExclusionRule(organization = "*", name = "slf4j-api")
    ),
      "org.noggit" % "noggit" % "0.6",
      "com.typesafe.scala-logging" %% "scala-logging" % "3.7.2" excludeAll(
      ExclusionRule(organization = "*", name = "slf4j-api")
    ),
    "org.apache.spark" % "spark-core_2.11" % "2.2.0" excludeAll(
      ExclusionRule(organization = "*", name = "breeze_2.11"),
      ExclusionRule(organization = "*", name = "hadoop-hdfs"),
      ExclusionRule(organization = "*", name = "hadoop-annotations"),
      ExclusionRule(organization = "*", name = "hadoop-common"),
      ExclusionRule(organization = "*", name = "hadoop-mapreduce-client-app"),
      ExclusionRule(organization = "*", name = "hadoop-mapreduce-client-common"),
      ExclusionRule(organization = "*", name = "hadoop-mapreduce-client-core"),
      ExclusionRule(organization = "*", name = "hadoop-mapreduce-client-jobclient"),
      ExclusionRule(organization = "*", name = "hadoop-mapreduce-client-shuffle"),
      ExclusionRule(organization = "*", name = "hadoop-yarn-api"),
      ExclusionRule(organization = "*", name = "hadoop-yarn-client"),
      ExclusionRule(organization = "*", name = "hadoop-yarn-common"),
      ExclusionRule(organization = "*", name = "hadoop-yarn-server-common"),
      ExclusionRule(organization = "*", name = "hadoop-yarn-server-web-proxy"),
      ExclusionRule(organization = "*", name = "activation"),
      ExclusionRule(organization = "*", name = "hive-exec"),
      ExclusionRule(organization = "*", name = "scala-compiler"),
      ExclusionRule(organization = "*", name = "spire_2.11"),
      ExclusionRule(organization = "*", name = "commons-compress"),
      ExclusionRule(organization = "*", name = "slf4j-api"),
      ExclusionRule(organization = "*", name = "guava"),
      ExclusionRule(organization = "*", name = "commons-codec"),
      ExclusionRule(organization = "*", name = "commons-io"),
      ExclusionRule(organization = "*", name = "gson"),
      ExclusionRule(organization = "*", name = "httpclient"),
      ExclusionRule(organization = "*", name = "zookeeper"),
      ExclusionRule(organization = "*", name = "jettison"),
      ExclusionRule(organization = "*", name = "jackson-core"),
      ExclusionRule(organization = "*", name = "httpcore"),
      ExclusionRule(organization = "*", name = "bcprov-jdk15on"),
      ExclusionRule(organization = "*", name = "jul-to-slf4j"),
      ExclusionRule(organization = "*", name = "jcl-over-slf4j"),
      ExclusionRule(organization = "*", name = "commons-cli"),
      ExclusionRule(organization = "*", name = "slf4j-log4j12"),
      ExclusionRule(organization = "*", name = "curator-framework")
    ),
    "org.scala-lang" % "scala-xml" % "2.11.0-M4",
    "org.apache.hadoop" % "hadoop-mapreduce-client-core" % "2.7.3" excludeAll(
      ExclusionRule(organization = "*", name = "commons-codec"),
      ExclusionRule(organization = "*", name = "commons-cli"),
      ExclusionRule(organization = "*", name = "slf4j-api"),
      ExclusionRule(organization = "*", name = "commons-io"),
      ExclusionRule(organization = "*", name = "jettison"),
      ExclusionRule(organization = "*", name = "avro"),
      ExclusionRule(organization = "*", name = "commons-compress"),
      ExclusionRule(organization = "*", name = "slf4j-log4j12"),
      ExclusionRule(organization = "*", name = "netty")
    ),
    "org.apache.hadoop" % "hadoop-common" % "2.7.3" excludeAll(
      ExclusionRule(organization = "*", name = "commons-codec"),
      ExclusionRule(organization = "*", name = "commons-cli"),
      ExclusionRule(organization = "*", name = "slf4j-api"),
      ExclusionRule(organization = "*", name = "commons-math3"),
      ExclusionRule(organization = "*", name = "commons-io"),
      ExclusionRule(organization = "*", name = "jets3t"),
      ExclusionRule(organization = "*", name = "gson"),
      ExclusionRule(organization = "*", name = "avro"),
      ExclusionRule(organization = "*", name = "httpclient"),
      ExclusionRule(organization = "*", name = "zookeeper"),
      ExclusionRule(organization = "*", name = "commons-compress"),
      ExclusionRule(organization = "*", name = "slf4j-log4j12"),
      ExclusionRule(organization = "*", name = "commons-net"),
      ExclusionRule(organization = "*", name = "curator-recipes"),
      ExclusionRule(organization = "*", name = "jsr305")
    )
  )
  assemblyMergeStrategy in assembly := {
   case PathList("META-INF", xs @ _*) =&gt; MergeStrategy.discard
   case x =&gt; MergeStrategy.first
  }
  </code></pre>