Output_UnicodeLittleUnmarked.java 1.2 KB

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