Source for gnu.gcj.convert.Output_UnicodeLittleUnmarked

   1: /* Copyright (C) 2004  Free Software Foundation
   2: 
   3:    This file is part of libgcj.
   4: 
   5: This software is copyrighted work licensed under the terms of the
   6: Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
   7: details.  */
   8: 
   9: package gnu.gcj.convert;
  10: 
  11: /**
  12:  * Convert to Unicode Little Endian, no marker
  13:  */
  14: public class Output_UnicodeLittleUnmarked extends UnicodeToBytes
  15: {
  16:   public String getName() { return "UnicodeLittleUnmarked"; }
  17: 
  18:   /** Convert chars to bytes.
  19:     * Converted bytes are written to buf, starting at count.
  20:     * @param inbuffer source of characters to convert
  21:     * @param inpos index of initial character in inbuffer to convert
  22:     * @param inlength number of characters to convert
  23:     * @return number of chars converted
  24:     * Also, this.count is increment by the number of bytes converted.
  25:     */
  26:   public int write (char[] inbuffer, int inpos, int inlength)
  27:   {
  28:     int avail = buf.length - count;
  29:     if (inlength * 2 > avail)
  30:       inlength = avail / 2;
  31:     for (int i = inlength; i > 0; i--)
  32:       {
  33:         char c = inbuffer[inpos++];
  34:         buf[count] = (byte)c;
  35:         buf[count+1] = (byte)(c >> 8);
  36:     count += 2;
  37:       }
  38:     return inlength;
  39:   }
  40: }