src/share/classes/sun/nio/cs/ext/DoubleByte.java

Print this page




 593                     } else {
 594                         if (dst.remaining() < 1)
 595                         return CoderResult.OVERFLOW;
 596                         dst.put((byte)bb);
 597                     }
 598                     mark++;
 599                 }
 600                 return CoderResult.UNDERFLOW;
 601             } finally {
 602                 src.position(mark);
 603             }
 604         }
 605 
 606         protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
 607             if (src.hasArray() && dst.hasArray())
 608                 return encodeArrayLoop(src, dst);
 609             else
 610                 return encodeBufferLoop(src, dst);
 611         }
 612 





 613         public int encode(char[] src, int sp, int len, byte[] dst) {
 614             int dp = 0;
 615             int sl = sp + len;
 616             int dl = dst.length;
 617             while (sp < sl) {
 618                 char c = src[sp++];
 619                 int bb = encodeChar(c);
 620                 if (bb == UNMAPPABLE_ENCODING) {
 621                     if (Character.isHighSurrogate(c) && sp < sl &&
 622                         Character.isLowSurrogate(src[sp])) {
 623                         sp++;
 624                     }
 625                     byte[] repl = replacement();
 626                     dst[dp++] = repl[0];
 627                     if (repl.length > 1)
 628                         dst[dp++] = repl[1];
 629                     continue;
 630                 } //else
 631                 if (bb > MAX_SINGLEBYTE) { // DoubleByte
 632                     dst[dp++] = (byte)(bb >> 8);
 633                     dst[dp++] = (byte)bb;
 634                 } else {                          // SingleByte
 635                     dst[dp++] = (byte)bb;
 636                 }
 637 
 638             }
 639             return dp;
 640         }
 641 
 642         public int encodeChar(char ch) {
 643             return c2b[c2bIndex[ch >> 8] + (ch & 0xff)];
 644         }
 645 


 860                     mark++;
 861                 }
 862                 return CoderResult.UNDERFLOW;
 863             } finally {
 864                 src.position(mark);
 865             }
 866         }
 867 
 868         public int encode(char[] src, int sp, int len, byte[] dst) {
 869             int dp = 0;
 870             int sl = sp + len;
 871             while (sp < sl) {
 872                 char c = src[sp++];
 873                 int bb = encodeChar(c);
 874 
 875                 if (bb == UNMAPPABLE_ENCODING) {
 876                     if (Character.isHighSurrogate(c) && sp < sl &&
 877                         Character.isLowSurrogate(src[sp])) {
 878                         sp++;
 879                     }
 880                     byte[] repl = replacement();
 881                     dst[dp++] = repl[0];
 882                     if (repl.length > 1)
 883                         dst[dp++] = repl[1];
 884                     continue;
 885                 } //else
 886                 if (bb > MAX_SINGLEBYTE) {           // DoubleByte
 887                     if (currentState == SBCS) {
 888                         currentState = DBCS;
 889                         dst[dp++] = SO;
 890                     }
 891                     dst[dp++] = (byte)(bb >> 8);
 892                     dst[dp++] = (byte)bb;
 893                 } else {                             // SingleByte
 894                     if (currentState == DBCS) {
 895                          currentState = SBCS;
 896                          dst[dp++] = SI;
 897                     }
 898                     dst[dp++] = (byte)bb;
 899                 }
 900             }


 593                     } else {
 594                         if (dst.remaining() < 1)
 595                         return CoderResult.OVERFLOW;
 596                         dst.put((byte)bb);
 597                     }
 598                     mark++;
 599                 }
 600                 return CoderResult.UNDERFLOW;
 601             } finally {
 602                 src.position(mark);
 603             }
 604         }
 605 
 606         protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
 607             if (src.hasArray() && dst.hasArray())
 608                 return encodeArrayLoop(src, dst);
 609             else
 610                 return encodeBufferLoop(src, dst);
 611         }
 612 
 613         protected byte[] repl = replacement();
 614         protected void implReplaceWith(byte[] newReplacement) {
 615             repl = newReplacement;
 616         }
 617 
 618         public int encode(char[] src, int sp, int len, byte[] dst) {
 619             int dp = 0;
 620             int sl = sp + len;
 621             int dl = dst.length;
 622             while (sp < sl) {
 623                 char c = src[sp++];
 624                 int bb = encodeChar(c);
 625                 if (bb == UNMAPPABLE_ENCODING) {
 626                     if (Character.isHighSurrogate(c) && sp < sl &&
 627                         Character.isLowSurrogate(src[sp])) {
 628                         sp++;
 629                     }

 630                     dst[dp++] = repl[0];
 631                     if (repl.length > 1)
 632                         dst[dp++] = repl[1];
 633                     continue;
 634                 } //else
 635                 if (bb > MAX_SINGLEBYTE) { // DoubleByte
 636                     dst[dp++] = (byte)(bb >> 8);
 637                     dst[dp++] = (byte)bb;
 638                 } else {                          // SingleByte
 639                     dst[dp++] = (byte)bb;
 640                 }
 641 
 642             }
 643             return dp;
 644         }
 645 
 646         public int encodeChar(char ch) {
 647             return c2b[c2bIndex[ch >> 8] + (ch & 0xff)];
 648         }
 649 


 864                     mark++;
 865                 }
 866                 return CoderResult.UNDERFLOW;
 867             } finally {
 868                 src.position(mark);
 869             }
 870         }
 871 
 872         public int encode(char[] src, int sp, int len, byte[] dst) {
 873             int dp = 0;
 874             int sl = sp + len;
 875             while (sp < sl) {
 876                 char c = src[sp++];
 877                 int bb = encodeChar(c);
 878 
 879                 if (bb == UNMAPPABLE_ENCODING) {
 880                     if (Character.isHighSurrogate(c) && sp < sl &&
 881                         Character.isLowSurrogate(src[sp])) {
 882                         sp++;
 883                     }

 884                     dst[dp++] = repl[0];
 885                     if (repl.length > 1)
 886                         dst[dp++] = repl[1];
 887                     continue;
 888                 } //else
 889                 if (bb > MAX_SINGLEBYTE) {           // DoubleByte
 890                     if (currentState == SBCS) {
 891                         currentState = DBCS;
 892                         dst[dp++] = SO;
 893                     }
 894                     dst[dp++] = (byte)(bb >> 8);
 895                     dst[dp++] = (byte)bb;
 896                 } else {                             // SingleByte
 897                     if (currentState == DBCS) {
 898                          currentState = SBCS;
 899                          dst[dp++] = SI;
 900                     }
 901                     dst[dp++] = (byte)bb;
 902                 }
 903             }