On Mon, Jan 11, 2010 at 10:34 AM, Jos Snellings <jos.snelli...@pandora.be>wrote:

> That is right!
> It is just a confusing situation :-(
> The filter works fine. The init() method of a generator does not give a
> chance to call setCharacterEncoding, as the parsing already happened.
> The good thing is that the code is already in spring, so, no new
> external dependencies. Maybe later on I add a
> "tryToGuessEncodingFilter".
>
>
Trying to guess encodings isn't a good idea, in general.  About the only one
that can be reliably detected is UTF-8.  In past projects, I've done
something like this:

  String result;
  try {
    result = new String(someBytes, "UTF-8");
  catch (EncodingError e) {
    result = new String(someBytes, "Windows-1252");
  }

In my experience, Windows-1252 was a better guess than ISO-8859-1, as users
tend to paste in stuff from word documents with curly quotes.

-Dom

Reply via email to