KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > impl > io > UTF8Reader


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2000-2004 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package com.sun.org.apache.xerces.internal.impl.io;
59
60 import java.io.InputStream JavaDoc;
61 import java.io.IOException JavaDoc;
62 import java.io.Reader JavaDoc;
63
64 import java.util.Locale JavaDoc;
65 import com.sun.org.apache.xerces.internal.util.MessageFormatter;
66 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
67
68 /**
69  * <p>A UTF-8 reader.</p>
70  *
71  * @author Andy Clark, IBM
72  *
73  * @version $Id: UTF8Reader.java,v 1.10 2004/03/04 19:27:13 mrglavas Exp $
74  */

75 public class UTF8Reader
76     extends Reader JavaDoc {
77
78     //
79
// Constants
80
//
81

82     /** Default byte buffer size (2048). */
83     public static final int DEFAULT_BUFFER_SIZE = 2048;
84
85     // debugging
86

87     /** Debug read. */
88     private static final boolean DEBUG_READ = false;
89
90     //
91
// Data
92
//
93

94     /** Input stream. */
95     protected InputStream JavaDoc fInputStream;
96
97     /** Byte buffer. */
98     protected byte[] fBuffer;
99
100     /** Offset into buffer. */
101     protected int fOffset;
102
103     /** Surrogate character. */
104     private int fSurrogate = -1;
105
106     // message formatter; used to produce localized
107
// exception messages
108
private MessageFormatter fFormatter = null;
109
110     //Locale to use for messages
111
private Locale JavaDoc fLocale = null;
112
113     //
114
// Constructors
115
//
116

117     /**
118      * Constructs a UTF-8 reader from the specified input stream
119      * using the default buffer size. Primarily for testing.
120      *
121      * @param inputStream The input stream.
122      */

123     public UTF8Reader(InputStream JavaDoc inputStream) {
124         this(inputStream, DEFAULT_BUFFER_SIZE, new XMLMessageFormatter(), Locale.getDefault());
125     } // <init>(InputStream, MessageFormatter)
126

127     /**
128      * Constructs a UTF-8 reader from the specified input stream
129      * using the default buffer size and the given MessageFormatter.
130      *
131      * @param inputStream The input stream.
132      * @param messageFormatter given MessageFormatter
133      * @param locale Locale to use for messages
134      */

135     public UTF8Reader(InputStream JavaDoc inputStream, MessageFormatter messageFormatter,
136             Locale JavaDoc locale) {
137         this(inputStream, DEFAULT_BUFFER_SIZE, messageFormatter, locale);
138     } // <init>(InputStream, MessageFormatter, Locale)
139

140     /**
141      * Constructs a UTF-8 reader from the specified input stream,
142      * buffer size and MessageFormatter.
143      *
144      * @param inputStream The input stream.
145      * @param size The initial buffer size.
146      * @param messageFormatter the formatter for localizing/formatting errors.
147      * @param locale the Locale to use for messages
148      */

149     public UTF8Reader(InputStream JavaDoc inputStream, int size,
150             MessageFormatter messageFormatter, Locale JavaDoc locale) {
151         fInputStream = inputStream;
152         fBuffer = new byte[size];
153         fFormatter = messageFormatter;
154         fLocale = locale;
155     } // <init>(InputStream, int, MessageFormatter, Locale)
156

157     //
158
// Reader methods
159
//
160

161     /**
162      * Read a single character. This method will block until a character is
163      * available, an I/O error occurs, or the end of the stream is reached.
164      *
165      * <p> Subclasses that intend to support efficient single-character input
166      * should override this method.
167      *
168      * @return The character read, as an integer in the range 0 to 16383
169      * (<tt>0x00-0xffff</tt>), or -1 if the end of the stream has
170      * been reached
171      *
172      * @exception IOException If an I/O error occurs
173      */

174     public int read() throws IOException JavaDoc {
175
176         // decode character
177
int c = fSurrogate;
178         if (fSurrogate == -1) {
179             // NOTE: We use the index into the buffer if there are remaining
180
// bytes from the last block read. -Ac
181
int index = 0;
182
183             // get first byte
184
int b0 = index == fOffset
185                    ? fInputStream.read() : fBuffer[index++] & 0x00FF;
186             if (b0 == -1) {
187                 return -1;
188             }
189
190             // UTF-8: [0xxx xxxx]
191
// Unicode: [0000 0000] [0xxx xxxx]
192
if (b0 < 0x80) {
193                 c = (char)b0;
194             }
195
196             // UTF-8: [110y yyyy] [10xx xxxx]
197
// Unicode: [0000 0yyy] [yyxx xxxx]
198
else if ((b0 & 0xE0) == 0xC0 && (b0 & 0x1E) != 0) {
199                 int b1 = index == fOffset
200                        ? fInputStream.read() : fBuffer[index++] & 0x00FF;
201                 if (b1 == -1) {
202                     expectedByte(2, 2);
203                 }
204                 if ((b1 & 0xC0) != 0x80) {
205                     invalidByte(2, 2, b1);
206                 }
207                 c = ((b0 << 6) & 0x07C0) | (b1 & 0x003F);
208             }
209
210             // UTF-8: [1110 zzzz] [10yy yyyy] [10xx xxxx]
211
// Unicode: [zzzz yyyy] [yyxx xxxx]
212
else if ((b0 & 0xF0) == 0xE0) {
213                 int b1 = index == fOffset
214                        ? fInputStream.read() : fBuffer[index++] & 0x00FF;
215                 if (b1 == -1) {
216                     expectedByte(2, 3);
217                 }
218                 if ((b1 & 0xC0) != 0x80
219                     || (b0 == 0xED && b1 >= 0xA0)
220                     || ((b0 & 0x0F) == 0 && (b1 & 0x20) == 0)) {
221                     invalidByte(2, 3, b1);
222                 }
223                 int b2 = index == fOffset
224                        ? fInputStream.read() : fBuffer[index++] & 0x00FF;
225                 if (b2 == -1) {
226                     expectedByte(3, 3);
227                 }
228                 if ((b2 & 0xC0) != 0x80) {
229                     invalidByte(3, 3, b2);
230                 }
231                 c = ((b0 << 12) & 0xF000) | ((b1 << 6) & 0x0FC0) |
232                     (b2 & 0x003F);
233             }
234
235             // UTF-8: [1111 0uuu] [10uu zzzz] [10yy yyyy] [10xx xxxx]*
236
// Unicode: [1101 10ww] [wwzz zzyy] (high surrogate)
237
// [1101 11yy] [yyxx xxxx] (low surrogate)
238
// * uuuuu = wwww + 1
239
else if ((b0 & 0xF8) == 0xF0) {
240                 int b1 = index == fOffset
241                        ? fInputStream.read() : fBuffer[index++] & 0x00FF;
242                 if (b1 == -1) {
243                     expectedByte(2, 4);
244                 }
245                 if ((b1 & 0xC0) != 0x80
246                     || ((b1 & 0x30) == 0 && (b0 & 0x07) == 0)) {
247                     invalidByte(2, 3, b1);
248                 }
249                 int b2 = index == fOffset
250                        ? fInputStream.read() : fBuffer[index++] & 0x00FF;
251                 if (b2 == -1) {
252                     expectedByte(3, 4);
253                 }
254                 if ((b2 & 0xC0) != 0x80) {
255                     invalidByte(3, 3, b2);
256                 }
257                 int b3 = index == fOffset
258                        ? fInputStream.read() : fBuffer[index++] & 0x00FF;
259                 if (b3 == -1) {
260                     expectedByte(4, 4);
261                 }
262                 if ((b3 & 0xC0) != 0x80) {
263                     invalidByte(4, 4, b3);
264                 }
265                 int uuuuu = ((b0 << 2) & 0x001C) | ((b1 >> 4) & 0x0003);
266                 if (uuuuu > 0x10) {
267                     invalidSurrogate(uuuuu);
268                 }
269                 int wwww = uuuuu - 1;
270                 int hs = 0xD800 |
271                          ((wwww << 6) & 0x03C0) | ((b1 << 2) & 0x003C) |
272                          ((b2 >> 4) & 0x0003);
273                 int ls = 0xDC00 | ((b2 << 6) & 0x03C0) | (b3 & 0x003F);
274                 c = hs;
275                 fSurrogate = ls;
276             }
277
278             // error
279
else {
280                 invalidByte(1, 1, b0);
281             }
282         }
283
284         // use surrogate
285
else {
286             fSurrogate = -1;
287         }
288
289         // return character
290
if (DEBUG_READ) {
291             System.out.println("read(): 0x"+Integer.toHexString(c));
292         }
293         return c;
294
295     } // read():int
296

297     /**
298      * Read characters into a portion of an array. This method will block
299      * until some input is available, an I/O error occurs, or the end of the
300      * stream is reached.
301      *
302      * @param ch Destination buffer
303      * @param offset Offset at which to start storing characters
304      * @param length Maximum number of characters to read
305      *
306      * @return The number of characters read, or -1 if the end of the
307      * stream has been reached
308      *
309      * @exception IOException If an I/O error occurs
310      */

311     public int read(char ch[], int offset, int length) throws IOException JavaDoc {
312
313         // handle surrogate
314
int out = offset;
315         if (fSurrogate != -1) {
316             ch[offset + 1] = (char)fSurrogate;
317             fSurrogate = -1;
318             length--;
319             out++;
320         }
321
322         // read bytes
323
int count = 0;
324         if (fOffset == 0) {
325             // adjust length to read
326
if (length > fBuffer.length) {
327                 length = fBuffer.length;
328             }
329
330             // perform read operation
331
count = fInputStream.read(fBuffer, 0, length);
332             if (count == -1) {
333                 return -1;
334             }
335             count += out - offset;
336         }
337
338         // skip read; last character was in error
339
// NOTE: Having an offset value other than zero means that there was
340
// an error in the last character read. In this case, we have
341
// skipped the read so we don't consume any bytes past the
342
// error. By signalling the error on the next block read we
343
// allow the method to return the most valid characters that
344
// it can on the previous block read. -Ac
345
else {
346             count = fOffset;
347             fOffset = 0;
348         }
349
350         // convert bytes to characters
351
final int total = count;
352         int in;
353         byte byte1;
354         final byte byte0 = 0;
355         for (in = 0; in < total; in++) {
356             byte1 = fBuffer[in];
357             if (byte1 >= byte0) {
358                 ch[out++] = (char)byte1;
359             }
360             else {
361                 break;
362             }
363         }
364         for ( ; in < total; in++) {
365             byte1 = fBuffer[in];
366
367             // UTF-8: [0xxx xxxx]
368
// Unicode: [0000 0000] [0xxx xxxx]
369
if (byte1 >= byte0) {
370                 ch[out++] = (char)byte1;
371                 continue;
372             }
373
374             // UTF-8: [110y yyyy] [10xx xxxx]
375
// Unicode: [0000 0yyy] [yyxx xxxx]
376
int b0 = byte1 & 0x0FF;
377             if ((b0 & 0xE0) == 0xC0 && (b0 & 0x1E) != 0) {
378                 int b1 = -1;
379                 if (++in < total) {
380                     b1 = fBuffer[in] & 0x00FF;
381                 }
382                 else {
383                     b1 = fInputStream.read();
384                     if (b1 == -1) {
385                         if (out > offset) {
386                             fBuffer[0] = (byte)b0;
387                             fOffset = 1;
388                             return out - offset;
389                         }
390                         expectedByte(2, 2);
391                     }
392                     count++;
393                 }
394                 if ((b1 & 0xC0) != 0x80) {
395                     if (out > offset) {
396                         fBuffer[0] = (byte)b0;
397                         fBuffer[1] = (byte)b1;
398                         fOffset = 2;
399                         return out - offset;
400                     }
401                     invalidByte(2, 2, b1);
402                 }
403                 int c = ((b0 << 6) & 0x07C0) | (b1 & 0x003F);
404                 ch[out++] = (char)c;
405                 count -= 1;
406                 continue;
407             }
408
409             // UTF-8: [1110 zzzz] [10yy yyyy] [10xx xxxx]
410
// Unicode: [zzzz yyyy] [yyxx xxxx]
411
if ((b0 & 0xF0) == 0xE0) {
412                 int b1 = -1;
413                 if (++in < total) {
414                     b1 = fBuffer[in] & 0x00FF;
415                 }
416                 else {
417                     b1 = fInputStream.read();
418                     if (b1 == -1) {
419                         if (out > offset) {
420                             fBuffer[0] = (byte)b0;
421                             fOffset = 1;
422                             return out - offset;
423                         }
424                         expectedByte(2, 3);
425                     }
426                     count++;
427                 }
428                 if ((b1 & 0xC0) != 0x80
429                     || (b0 == 0xED && b1 >= 0xA0)
430                     || ((b0 & 0x0F) == 0 && (b1 & 0x20) == 0)) {
431                     if (out > offset) {
432                         fBuffer[0] = (byte)b0;
433                         fBuffer[1] = (byte)b1;
434                         fOffset = 2;
435                         return out - offset;
436                     }
437                     invalidByte(2, 3, b1);
438                 }
439                 int b2 = -1;
440                 if (++in < total) {
441                     b2 = fBuffer[in] & 0x00FF;
442                 }
443                 else {
444                     b2 = fInputStream.read();
445                     if (b2 == -1) {
446                         if (out > offset) {
447                             fBuffer[0] = (byte)b0;
448                             fBuffer[1] = (byte)b1;
449                             fOffset = 2;
450                             return out - offset;
451                         }
452                         expectedByte(3, 3);
453                     }
454                     count++;
455                 }
456                 if ((b2 & 0xC0) != 0x80) {
457                     if (out > offset) {
458                         fBuffer[0] = (byte)b0;
459                         fBuffer[1] = (byte)b1;
460                         fBuffer[2] = (byte)b2;
461                         fOffset = 3;
462                         return out - offset;
463                     }
464                     invalidByte(3, 3, b2);
465                 }
466                 int c = ((b0 << 12) & 0xF000) | ((b1 << 6) & 0x0FC0) |
467                         (b2 & 0x003F);
468                 ch[out++] = (char)c;
469                 count -= 2;
470                 continue;
471             }
472
473             // UTF-8: [1111 0uuu] [10uu zzzz] [10yy yyyy] [10xx xxxx]*
474
// Unicode: [1101 10ww] [wwzz zzyy] (high surrogate)
475
// [1101 11yy] [yyxx xxxx] (low surrogate)
476
// * uuuuu = wwww + 1
477
if ((b0 & 0xF8) == 0xF0) {
478                 int b1 = -1;
479                 if (++in < total) {
480                     b1 = fBuffer[in] & 0x00FF;
481                 }
482                 else {
483                     b1 = fInputStream.read();
484                     if (b1 == -1) {
485                         if (out > offset) {
486                             fBuffer[0] = (byte)b0;
487                             fOffset = 1;
488                             return out - offset;
489                         }
490                         expectedByte(2, 4);
491                     }
492                     count++;
493                 }
494                 if ((b1 & 0xC0) != 0x80
495                     || ((b1 & 0x30) == 0 && (b0 & 0x07) == 0)) {
496                     if (out > offset) {
497                         fBuffer[0] = (byte)b0;
498                         fBuffer[1] = (byte)b1;
499                         fOffset = 2;
500                         return out - offset;
501                     }
502                     invalidByte(2, 4, b1);
503                 }
504                 int b2 = -1;
505                 if (++in < total) {
506                     b2 = fBuffer[in] & 0x00FF;
507                 }
508                 else {
509                     b2 = fInputStream.read();
510                     if (b2 == -1) {
511                         if (out > offset) {
512                             fBuffer[0] = (byte)b0;
513                             fBuffer[1] = (byte)b1;
514                             fOffset = 2;
515                             return out - offset;
516                         }
517                         expectedByte(3, 4);
518                     }
519                     count++;
520                 }
521                 if ((b2 & 0xC0) != 0x80) {
522                     if (out > offset) {
523                         fBuffer[0] = (byte)b0;
524                         fBuffer[1] = (byte)b1;
525                         fBuffer[2] = (byte)b2;
526                         fOffset = 3;
527                         return out - offset;
528                     }
529                     invalidByte(3, 4, b2);
530                 }
531                 int b3 = -1;
532                 if (++in < total) {
533                     b3 = fBuffer[in] & 0x00FF;
534                 }
535                 else {
536                     b3 = fInputStream.read();
537                     if (b3 == -1) {
538                         if (out > offset) {
539                             fBuffer[0] = (byte)b0;
540                             fBuffer[1] = (byte)b1;
541                             fBuffer[2] = (byte)b2;
542                             fOffset = 3;
543                             return out - offset;
544                         }
545                         expectedByte(4, 4);
546                     }
547                     count++;
548                 }
549                 if ((b3 & 0xC0) != 0x80) {
550                     if (out > offset) {
551                         fBuffer[0] = (byte)b0;
552                         fBuffer[1] = (byte)b1;
553                         fBuffer[2] = (byte)b2;
554                         fBuffer[3] = (byte)b3;
555                         fOffset = 4;
556                         return out - offset;
557                     }
558                     invalidByte(4, 4, b2);
559                 }
560
561                 // decode bytes into surrogate characters
562
int uuuuu = ((b0 << 2) & 0x001C) | ((b1 >> 4) & 0x0003);
563                 if (uuuuu > 0x10) {
564                     invalidSurrogate(uuuuu);
565                 }
566                 int wwww = uuuuu - 1;
567                 int zzzz = b1 & 0x000F;
568                 int yyyyyy = b2 & 0x003F;
569                 int xxxxxx = b3 & 0x003F;
570                 int hs = 0xD800 | ((wwww << 6) & 0x03C0) | (zzzz << 2) | (yyyyyy >> 4);
571                 int ls = 0xDC00 | ((yyyyyy << 6) & 0x03C0) | xxxxxx;
572
573                 // set characters
574
ch[out++] = (char)hs;
575                 ch[out++] = (char)ls;
576                 count -= 2;
577                 continue;
578             }
579
580             // error
581
if (out > offset) {
582                 fBuffer[0] = (byte)b0;
583                 fOffset = 1;
584                 return out - offset;
585             }
586             invalidByte(1, 1, b0);
587         }
588
589         // return number of characters converted
590
if (DEBUG_READ) {
591             System.out.println("read(char[],"+offset+','+length+"): count="+count);
592         }
593         return count;
594
595     } // read(char[],int,int)
596

597     /**
598      * Skip characters. This method will block until some characters are
599      * available, an I/O error occurs, or the end of the stream is reached.
600      *
601      * @param n The number of characters to skip
602      *
603      * @return The number of characters actually skipped
604      *
605      * @exception IOException If an I/O error occurs
606      */

607     public long skip(long n) throws IOException JavaDoc {
608
609         long remaining = n;
610         final char[] ch = new char[fBuffer.length];
611         do {
612             int length = ch.length < remaining ? ch.length : (int)remaining;
613             int count = read(ch, 0, length);
614             if (count > 0) {
615                 remaining -= count;
616             }
617             else {
618                 break;
619             }
620         } while (remaining > 0);
621
622         long skipped = n - remaining;
623         return skipped;
624
625     } // skip(long):long
626

627     /**
628      * Tell whether this stream is ready to be read.
629      *
630      * @return True if the next read() is guaranteed not to block for input,
631      * false otherwise. Note that returning false does not guarantee that the
632      * next read will block.
633      *
634      * @exception IOException If an I/O error occurs
635      */

636     public boolean ready() throws IOException JavaDoc {
637         return false;
638     } // ready()
639

640     /**
641      * Tell whether this stream supports the mark() operation.
642      */

643     public boolean markSupported() {
644         return false;
645     } // markSupported()
646

647     /**
648      * Mark the present position in the stream. Subsequent calls to reset()
649      * will attempt to reposition the stream to this point. Not all
650      * character-input streams support the mark() operation.
651      *
652      * @param readAheadLimit Limit on the number of characters that may be
653      * read while still preserving the mark. After
654      * reading this many characters, attempting to
655      * reset the stream may fail.
656      *
657      * @exception IOException If the stream does not support mark(),
658      * or if some other I/O error occurs
659      */

660     public void mark(int readAheadLimit) throws IOException JavaDoc {
661         throw new IOException JavaDoc(fFormatter.formatMessage(fLocale, "OperationNotSupported", new Object JavaDoc[]{"mark()", "UTF-8"}));
662     } // mark(int)
663

664     /**
665      * Reset the stream. If the stream has been marked, then attempt to
666      * reposition it at the mark. If the stream has not been marked, then
667      * attempt to reset it in some way appropriate to the particular stream,
668      * for example by repositioning it to its starting point. Not all
669      * character-input streams support the reset() operation, and some support
670      * reset() without supporting mark().
671      *
672      * @exception IOException If the stream has not been marked,
673      * or if the mark has been invalidated,
674      * or if the stream does not support reset(),
675      * or if some other I/O error occurs
676      */

677     public void reset() throws IOException JavaDoc {
678         fOffset = 0;
679         fSurrogate = -1;
680     } // reset()
681

682     /**
683      * Close the stream. Once a stream has been closed, further read(),
684      * ready(), mark(), or reset() invocations will throw an IOException.
685      * Closing a previously-closed stream, however, has no effect.
686      *
687      * @exception IOException If an I/O error occurs
688      */

689     public void close() throws IOException JavaDoc {
690         fInputStream.close();
691     } // close()
692

693     //
694
// Private methods
695
//
696

697     /** Throws an exception for expected byte. */
698     private void expectedByte(int position, int count)
699         throws MalformedByteSequenceException {
700
701         throw new MalformedByteSequenceException(fFormatter,
702             fLocale,
703             XMLMessageFormatter.XML_DOMAIN,
704             "ExpectedByte",
705             new Object JavaDoc[] {Integer.toString(position), Integer.toString(count)});
706
707     } // expectedByte(int,int)
708

709     /** Throws an exception for invalid byte. */
710     private void invalidByte(int position, int count, int c)
711         throws MalformedByteSequenceException {
712
713         throw new MalformedByteSequenceException(fFormatter,
714             fLocale,
715             XMLMessageFormatter.XML_DOMAIN,
716             "InvalidByte",
717             new Object JavaDoc [] {Integer.toString(position), Integer.toString(count)});
718
719     } // invalidByte(int,int,int)
720

721     /** Throws an exception for invalid surrogate bits. */
722     private void invalidSurrogate(int uuuuu) throws MalformedByteSequenceException {
723
724         throw new MalformedByteSequenceException(fFormatter,
725             fLocale,
726             XMLMessageFormatter.XML_DOMAIN,
727             "InvalidHighSurrogate",
728             new Object JavaDoc[] {Integer.toHexString(uuuuu)});
729
730     } // invalidSurrogate(int)
731

732 } // class UTF8Reader
733
Popular Tags