SmartDroidDeveloper / google-api-java-client

Automatically exported from code.google.com/p/google-api-java-client
0 stars 0 forks source link

Detect Unicode encoding for GSON library #153

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
External references, such as a standards document, or specification?

http://blog.publicobject.com/2010/08/handling-byte-order-mark-in-java.html

copied here (in case that blog goes away):

  public Reader inputStreamToReader(InputStream in) throws IOException {
    in.mark(3);
    int byte1 = in.read();
    int byte2 = in.read();
    if (byte1 == 0xFF && byte2 == 0xFE) {
      return new InputStreamReader(in, "UTF-16LE");
    } else if (byte1 == 0xFF && byte2 == 0xFF) {
      return new InputStreamReader(in, "UTF-16BE");
    } else {
      int byte3 = in.read();
      if (byte1 == 0xEF && byte2 == 0xBB && byte3 == 0xBF) {
        return new InputStreamReader(in, "UTF-8");
      } else {
        in.reset();
        return new InputStreamReader(in);
      }
    }
  }

Java environments (e.g. Java 6, Android 2.3, App Engine 1.4.2, or All)?

All

Please describe the feature requested.

Currently the GSON library implementation only supports UTF-8.  The algorithm 
above could potentially be used for supporting the other 3 Unicode encodings 
supported by the JSON specifications.

Original issue reported on code.google.com by yan...@google.com on 19 Mar 2011 at 9:32

GoogleCodeExporter commented 9 years ago
Moved to:
http://code.google.com/p/google-http-java-client/issues/detail?id=12

Original comment by yan...@google.com on 4 Jun 2011 at 4:12