~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to gnu/java/nio/charset/UTF_16Decoder.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
  static final int BIG_ENDIAN = 0;
55
55
  static final int LITTLE_ENDIAN = 1;
56
56
  static final int UNKNOWN_ENDIAN = 2;
 
57
  static final int MAYBE_BIG_ENDIAN = 3;
 
58
  static final int MAYBE_LITTLE_ENDIAN = 4;
57
59
 
58
60
  private static final char BYTE_ORDER_MARK = 0xFEFF;
59
61
  private static final char REVERSED_BYTE_ORDER_MARK = 0xFFFE;
81
83
            byte b2 = in.get ();
82
84
 
83
85
            // handle byte order mark
84
 
            if (byteOrder == UNKNOWN_ENDIAN)
 
86
            if (byteOrder == UNKNOWN_ENDIAN ||
 
87
                byteOrder == MAYBE_BIG_ENDIAN ||
 
88
                byteOrder == MAYBE_LITTLE_ENDIAN)
85
89
              {
86
90
                char c = (char) (((b1 & 0xFF) << 8) | (b2 & 0xFF));
87
91
                if (c == BYTE_ORDER_MARK)
88
92
                  {
 
93
                    if (byteOrder == MAYBE_LITTLE_ENDIAN)
 
94
                      {
 
95
                        return CoderResult.malformedForLength (2);
 
96
                      }
89
97
                    byteOrder = BIG_ENDIAN;
90
98
                    inPos += 2;
91
99
                    continue;
92
100
                  }
93
101
                else if (c == REVERSED_BYTE_ORDER_MARK)
94
102
                  {
 
103
                    if (byteOrder == MAYBE_BIG_ENDIAN)
 
104
                      {
 
105
                        return CoderResult.malformedForLength (2);
 
106
                      }
95
107
                    byteOrder = LITTLE_ENDIAN;
96
108
                    inPos += 2;
97
109
                    continue;
98
110
                  }
99
111
                else
100
112
                  {
101
 
                    // assume big endian, do not consume bytes,
 
113
                    // assume big or little endian, do not consume bytes,
102
114
                    // continue with normal processing
103
 
                    byteOrder = BIG_ENDIAN;
 
115
                    byteOrder = (byteOrder == MAYBE_LITTLE_ENDIAN ?
 
116
                                 LITTLE_ENDIAN : BIG_ENDIAN);
104
117
                  }
105
118
              }
106
119