n8han/giter8 — Issue #26: Error "java.nio.charset.MalformedInputException: Input length = 1"
Author: eed3si9n
Created: 2011-10-18 05:47:38+00:00
State: open

## steps

```
$ g8 eed3si9n/xitrum

Giter8 template for a new Xitrum project. See
http://ngocdaothanh.github.com/xitrum for more information.

version [1.0-SNAPSHOT]: [ENTER]
name [my_project]: [ENTER]
```

## problem

```
java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(CoderResult.java:260)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:319)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.read(BufferedReader.java:157)
at scala.io.BufferedSource$$anonfun$1$$anonfun$apply$mcI$sp$1.apply$mcI$sp(BufferedSource.scala:28)
at scala.io.Codec.wrap(Codec.scala:63)
at scala.io.BufferedSource$$anonfun$1.apply(BufferedSource.scala:28)
at scala.io.BufferedSource$$anonfun$1.apply(BufferedSource.scala:28)
at scala.collection.Iterator$$anon$13.next(Iterator.scala:149)
at scala.collection.Iterator$$anon$24.hasNext(Iterator.scala:484)
at scala.collection.Iterator$$anon$19.hasNext(Iterator.scala:368)
at scala.io.Source.hasNext(Source.scala:239)
at scala.collection.Iterator$class.foreach(Iterator.scala:631)
at scala.io.Source.foreach(Source.scala:181)
at scala.collection.TraversableOnce$class.addString(TraversableOnce.scala:505)
at scala.io.Source.addString(Source.scala:181)
at scala.collection.TraversableOnce$class.mkString(TraversableOnce.scala:470)
at scala.io.Source.mkString(Source.scala:181)
at scala.collection.TraversableOnce$class.mkString(TraversableOnce.scala:481)
at scala.io.Source.mkString(Source.scala:181)
at scala.collection.TraversableOnce$class.mkString(TraversableOnce.scala:488)
at scala.io.Source.mkString(Source.scala:181)
at dispatch.HandlerVerbs$$anonfun$$greater$minus$1.apply(handlers.scala:83)
at dispatch.HandlerVerbs$$anonfun$$greater$minus$1.apply(handlers.scala:83)
at dispatch.HandlerVerbs$$anonfun$$greater$tilde$1.apply(handlers.scala:78)
at dispatch.HandlerVerbs$$anonfun$$greater$tilde$1.apply(handlers.scala:77)
at dispatch.HandlerVerbs$$anonfun$$greater$greater$1.apply(handlers.scala:69)
at dispatch.HandlerVerbs$$anonfun$$greater$greater$1.apply(handlers.scala:59)
at dispatch.Handler$$anonfun$apply$3.apply(handlers.scala:37)
at dispatch.Handler$$anonfun$apply$3.apply(handlers.scala:36)
at dispatch.HttpExecutor$$anonfun$when$1.apply(executor.scala:51)
at dispatch.HttpExecutor$$anonfun$when$1.apply(executor.scala:50)
at dispatch.HttpExecutor$$anonfun$x$2.apply(executor.scala:41)
at dispatch.HttpExecutor$$anonfun$x$2.apply(executor.scala:36)
at dispatch.BlockingHttp$$anonfun$execute$1.apply(Http.scala:54)
at dispatch.Http.pack(Http.scala:25)
at dispatch.BlockingHttp$class.execute(Http.scala:53)
at dispatch.Http.execute(Http.scala:21)
at dispatch.HttpExecutor$class.x(executor.scala:36)
at dispatch.Http.x(Http.scala:21)
at dispatch.HttpExecutor$class.when(executor.scala:50)
at dispatch.Http.when(Http.scala:21)
at dispatch.HttpExecutor$class.apply(executor.scala:60)
at dispatch.Http.apply(Http.scala:21)
at giter8.Apply$$anonfun$write$1.apply(apply.scala:102)
at giter8.Apply$$anonfun$write$1.apply(apply.scala:93)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:61)
at scala.collection.immutable.List.foreach(List.scala:45)
at giter8.Apply$class.write(apply.scala:93)
at giter8.Giter8.write(giter8.scala:3)
at giter8.Apply$$anonfun$inspect$2.apply(apply.scala:35)
at giter8.Apply$$anonfun$inspect$2.apply(apply.scala:17)
at scala.Either$RightProjection.flatMap(Either.scala:275)
at giter8.Apply$class.inspect(apply.scala:17)
at giter8.Giter8.inspect(giter8.scala:3)
at giter8.Giter8.run(giter8.scala:15)
at giter8.Giter8.run(giter8.scala:3)
at xsbt.boot.Launch$.run(Launch.scala:54)
at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:43)
at xsbt.boot.Launch$.launch(Launch.scala:68)
at xsbt.boot.Launch$.apply(Launch.scala:14)
at xsbt.boot.Boot$.runImpl(Boot.scala:24)
at xsbt.boot.Boot$.main(Boot.scala:15)
at xsbt.boot.Boot.main(Boot.scala)
Error during sbt execution: java.nio.charset.MalformedInputException: Input length = 1
```

## expectation
either works, or the situation is handled more gracefully.

## note
this likely relates to the fact that dispatch apparently going against the RFC and assuming UTF-8. see [ouch -- bitten by default (request) charset (_ == UTF-8)](https://groups.google.com/forum/#!topic/dispatch-scala/0DMCsmLYCiY).

```scala
case Text(_) =>
http(show(repo, hash) >- { in =>
val fw = new FileWriter(f)
fw.write(new StringTemplate(in).setAttributes(parameters).toString)
fw.close()
})
```