src/java.base/share/classes/sun/nio/cs/US_ASCII.java

Print this page




 129                 return decodeBufferLoop(src, dst);
 130         }
 131 
 132         private char repl = '\uFFFD';
 133         protected void implReplaceWith(String newReplacement) {
 134             repl = newReplacement.charAt(0);
 135         }
 136 
 137         public int decode(byte[] src, int sp, int len, char[] dst) {
 138             int dp = 0;
 139             len = Math.min(len, dst.length);
 140             while (dp < len) {
 141                 byte b = src[sp++];
 142                 if (b >= 0)
 143                     dst[dp++] = (char)b;
 144                 else
 145                     dst[dp++] = repl;
 146             }
 147             return dp;
 148         }




 149     }
 150 
 151     private static class Encoder extends CharsetEncoder
 152                                  implements ArrayEncoder {
 153 
 154         private Encoder(Charset cs) {
 155             super(cs, 1.0f, 1.0f);
 156         }
 157 
 158         public boolean canEncode(char c) {
 159             return c < 0x80;
 160         }
 161 
 162         public boolean isLegalReplacement(byte[] repl) {
 163             return (repl.length == 1 && repl[0] >= 0) ||
 164                    super.isLegalReplacement(repl);
 165         }
 166 
 167         private final Surrogate.Parser sgp = new Surrogate.Parser();
 168         private CoderResult encodeArrayLoop(CharBuffer src,


 242             int dp = 0;
 243             int sl = sp + Math.min(len, dst.length);
 244             while (sp < sl) {
 245                 char c = src[sp++];
 246                 if (c < 0x80) {
 247                     dst[dp++] = (byte)c;
 248                     continue;
 249                 }
 250                 if (Character.isHighSurrogate(c) && sp < sl &&
 251                     Character.isLowSurrogate(src[sp])) {
 252                     if (len > dst.length) {
 253                         sl++;
 254                         len--;
 255                     }
 256                     sp++;
 257                 }
 258                 dst[dp++] = repl;
 259             }
 260             return dp;
 261         }




 262     }
 263 
 264 }


 129                 return decodeBufferLoop(src, dst);
 130         }
 131 
 132         private char repl = '\uFFFD';
 133         protected void implReplaceWith(String newReplacement) {
 134             repl = newReplacement.charAt(0);
 135         }
 136 
 137         public int decode(byte[] src, int sp, int len, char[] dst) {
 138             int dp = 0;
 139             len = Math.min(len, dst.length);
 140             while (dp < len) {
 141                 byte b = src[sp++];
 142                 if (b >= 0)
 143                     dst[dp++] = (char)b;
 144                 else
 145                     dst[dp++] = repl;
 146             }
 147             return dp;
 148         }
 149 
 150         public boolean isASCIICompatible() {
 151             return true;
 152         }
 153     }
 154 
 155     private static class Encoder extends CharsetEncoder
 156                                  implements ArrayEncoder {
 157 
 158         private Encoder(Charset cs) {
 159             super(cs, 1.0f, 1.0f);
 160         }
 161 
 162         public boolean canEncode(char c) {
 163             return c < 0x80;
 164         }
 165 
 166         public boolean isLegalReplacement(byte[] repl) {
 167             return (repl.length == 1 && repl[0] >= 0) ||
 168                    super.isLegalReplacement(repl);
 169         }
 170 
 171         private final Surrogate.Parser sgp = new Surrogate.Parser();
 172         private CoderResult encodeArrayLoop(CharBuffer src,


 246             int dp = 0;
 247             int sl = sp + Math.min(len, dst.length);
 248             while (sp < sl) {
 249                 char c = src[sp++];
 250                 if (c < 0x80) {
 251                     dst[dp++] = (byte)c;
 252                     continue;
 253                 }
 254                 if (Character.isHighSurrogate(c) && sp < sl &&
 255                     Character.isLowSurrogate(src[sp])) {
 256                     if (len > dst.length) {
 257                         sl++;
 258                         len--;
 259                     }
 260                     sp++;
 261                 }
 262                 dst[dp++] = repl;
 263             }
 264             return dp;
 265         }
 266 
 267         public boolean isASCIICompatible() {
 268             return true;
 269         }
 270     }
 271 
 272 }