gt:                                             index += (int)c & 0xFF;
context: /*
   *  Licensed to the Apache Software Foundation (ASF) under one or more
   *  contributor license agreements.  See the NOTICE file distributed with
   *  this work for additional information regarding copyright ownership.
   *  The ASF licenses this file to You under the Apache License, Version 2.0
   *  (the "License"); you may not use this file except in compliance with
   *  the License.  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.harmony.niochar.charset.additional;
  
  import java.nio.ByteBuffer;
  import java.nio.CharBuffer;
  import java.nio.charset.Charset;
  import java.nio.charset.CharsetDecoder;
  import java.nio.charset.CharsetEncoder;
  import java.nio.charset.CoderResult;
  
  import org.apache.harmony.nio.AddressUtil;
  import org.apache.harmony.niochar.CharsetProviderImpl;
  
  public class windows_1256 extends Charset {
  
          public windows_1256(String csName, String[] aliases) {
              super(csName, aliases);
          }
  
          public boolean contains(Charset cs) {
              return cs.name().equalsIgnoreCase("IBM367") || cs.name().equalsIgnoreCase("US-ASCII") || cs.name().equalsIgnoreCase("windows-1256") ;
          }
  
          public CharsetDecoder newDecoder() {
              return new Decoder(this);
          }
  
          public CharsetEncoder newEncoder() {
              return new Encoder(this);
          }
  
  	private static final class Decoder extends CharsetDecoder{
  		private Decoder(Charset cs){
  			super(cs, 1, 1);
  
  		}
  
  		private native int nDecode(char[] array, int arrPosition, int remaining, long outAddr, int absolutePos);
  
  
  		protected CoderResult decodeLoop(ByteBuffer bb, CharBuffer cb){
                          int cbRemaining = cb.remaining();
  		        if(CharsetProviderImpl.hasLoadedNatives() && bb.isDirect() && bb.hasRemaining() && cb.hasArray()){
  		            int toProceed = bb.remaining();
  		            int cbPos = cb.position();
  		            int bbPos = bb.position();
  		            boolean throwOverflow = false; 
  		            if( cbRemaining < toProceed ) { 
  		                toProceed = cbRemaining;
                                  throwOverflow = true;
                              }
                              int res = nDecode(cb.array(), cb.arrayOffset()+cbPos, toProceed, AddressUtil.getDirectBufferAddress(bb), bbPos);
                              bb.position(bbPos+res);
                              cb.position(cbPos+res);
                              if(throwOverflow) return CoderResult.OVERFLOW;
                          }else{
                              if(bb.hasArray() && cb.hasArray()) {
                                  int rem = bb.remaining();
                                  rem = cbRemaining >= rem ? rem : cbRemaining;
                                  byte[] bArr = bb.array();
                                  char[] cArr = cb.array();
                                  int bStart = bb.position();
                                  int cStart = cb.position();
                                  int i;
                                  for(i=bStart; i<bStart+rem; i++) {
                                      int in = (int)bArr[i];
                                      if(in < 0 && in >= -128){
                                          int index = (int)in + 128;
                                          cArr[cStart++] = (char)arr[index];
                                      }else {
                                          cArr[cStart++] = (char)(in & 0xFF);
                                      }
                                  }
                                  bb.position(i);
                                  cb.position(cStart);
                                  if(rem == cbRemaining && bb.hasRemaining()) return CoderResult.OVERFLOW;
                              } else {
                                  while(bb.hasRemaining()){
                                      if( cbRemaining == 0 ) return CoderResult.OVERFLOW;
                                      int in = (int)bb.get();
                                      if(in < 0 && in >= -128){
                                          int index = (int)in + 128;
                                          cb.put(arr[index]);
                                      }else {
                                          cb.put((char)(in & 0xFF));
                                      }
                                  cbRemaining--;
                                  }
                              }
  			} 
                          return CoderResult.UNDERFLOW;
  		}
  
  		final static char[] arr = {
                  0x20AC,0x067E,0x201A,0x0192,0x201E,0x2026,0x2020,0x2021,
                  0x02C6,0x2030,0x0679,0x2039,0x0152,0x0686,0x0698,0x0688,
                  0x06AF,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014,
                  0x06A9,0x2122,0x0691,0x203A,0x0153,0x200C,0x200D,0x06BA,
                  0x00A0,0x060C,0x00A2,0x00A3,0x00A4,0x00A5,0x00A6,0x00A7,
                  0x00A8,0x00A9,0x06BE,0x00AB,0x00AC,0x00AD,0x00AE,0x00AF,
                  0x00B0,0x00B1,0x00B2,0x00B3,0x00B4,0x00B5,0x00B6,0x00B7,
                  0x00B8,0x00B9,0x061B,0x00BB,0x00BC,0x00BD,0x00BE,0x061F,
                  0x06C1,0x0621,0x0622,0x0623,0x0624,0x0625,0x0626,0x0627,
                  0x0628,0x0629,0x062A,0x062B,0x062C,0x062D,0x062E,0x062F,
                  0x0630,0x0631,0x0632,0x0633,0x0634,0x0635,0x0636,0x00D7,
                  0x0637,0x0638,0x0639,0x063A,0x0640,0x0641,0x0642,0x0643,
                  0x00E0,0x0644,0x00E2,0x0645,0x0646,0x0647,0x0648,0x00E7,
                  0x00E8,0x00E9,0x00EA,0x00EB,0x0649,0x064A,0x00EE,0x00EF,
                  0x064B,0x064C,0x064D,0x064E,0x00F4,0x064F,0x0650,0x00F7,
                  0x0651,0x00F9,0x0652,0x00FB,0x00FC,0x200E,0x200F,0x06D2
  		};
          }
  
  	private static final class Encoder extends CharsetEncoder{
  		private Encoder(Charset cs){
  			super(cs, 1, 1);
  		}
                     
  		private native void nEncode(long outAddr, int absolutePos, char[] array, int arrPosition, int[] res);
                                                                                                                            
  		protected CoderResult encodeLoop(CharBuffer cb, ByteBuffer bb){
                          int bbRemaining = bb.remaining();
                          if(CharsetProviderImpl.hasLoadedNatives() && bb.isDirect() && cb.hasRemaining() && cb.hasArray()){
  		            int toProceed = cb.remaining();
  		            int cbPos = cb.position();
  		            int bbPos = bb.position();
  		            boolean throwOverflow = false; 
  		            if( bbRemaining < toProceed ) { 
  		                toProceed = bbRemaining; 
                                  throwOverflow = true;
                              }
                              int[] res = {toProceed, 0};
                              nEncode(AddressUtil.getDirectBufferAddress(bb), bbPos, cb.array(), cb.arrayOffset()+cbPos, res);
                              if( res[0] <= 0 ) {
                                  bb.position(bbPos-res[0]);
                                  cb.position(cbPos-res[0]);
                                  if(res[1]!=0) {
                                      if(res[1] < 0)
                                          return CoderResult.malformedForLength(-res[1]);
                                      else
                                          return CoderResult.unmappableForLength(res[1]);
                                  }
                              }else{
                                  bb.position(bbPos+res[0]);
                                  cb.position(cbPos+res[0]);
                                  if(throwOverflow) return CoderResult.OVERFLOW;
                              }
                          }else{
                              if(bb.hasArray() && cb.hasArray()) {
                                  byte[] byteArr = bb.array();
                                  char[] charArr = cb.array();
                                  int rem = cb.remaining();
                                  int byteArrStart = bb.position();
                                  rem = bbRemaining <= rem ? bbRemaining : rem;
                                  int x;
                                  for(x = cb.position(); x < cb.position()+rem; x++) {
                                      char c = charArr[x];
                                      if(c > (char)0x2122){
                                          if (c >= 0xD800 && c <= 0xDFFF) {
                                              if(x+1 < cb.limit()) {
                                                  char c1 = charArr[x+1];
                                                  if(c1 >= 0xD800 && c1 <= 0xDFFF) {
                                                      cb.position(x); bb.position(byteArrStart);
                                                      return CoderResult.unmappableForLength(2);
                                                  }
                                              } else {
                                                  cb.position(x); bb.position(byteArrStart);
                                                  return CoderResult.UNDERFLOW;
                                              }
                                              cb.position(x); bb.position(byteArrStart);
                                              return CoderResult.malformedForLength(1);
                                          }
                                          cb.position(x); bb.position(byteArrStart);
                                          return CoderResult.unmappableForLength(1);
                                      }else{
                                          if(c < 0x80) {
                                              byteArr[byteArrStart++] = (byte)c;
                                          } else {
                                              int index = (int)c >> 8;
                                              index = encodeIndex[index];
                                              if(index < 0) {
                                                  cb.position(x); bb.position(byteArrStart);
                                                  return CoderResult.unmappableForLength(1);
                                              }
                                              index <<= 8;
  