org.apache.solr.common.util
Class ByteUtils

java.lang.Object
  extended by org.apache.solr.common.util.ByteUtils

public class ByteUtils
extends Object


Constructor Summary
ByteUtils()
           
 
Method Summary
static int UTF16toUTF8(CharSequence s, int offset, int len, byte[] result, int resultOffset)
          Writes UTF8 into the byte array, starting at offset.
static String UTF8toUTF16(byte[] utf8, int offset, int len)
          Convert UTF8 bytes into a String
static int UTF8toUTF16(byte[] utf8, int offset, int len, char[] out, int out_offset)
          Converts utf8 to utf16 and returns the number of 16 bit Java chars written.
static void UTF8toUTF16(byte[] utf8, int offset, int len, org.noggit.CharArr out)
          Convert UTF8 bytes into UTF16 characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteUtils

public ByteUtils()
Method Detail

UTF8toUTF16

public static int UTF8toUTF16(byte[] utf8,
                              int offset,
                              int len,
                              char[] out,
                              int out_offset)
Converts utf8 to utf16 and returns the number of 16 bit Java chars written. Full characters are read, even if this reads past the length passed (and can result in an ArrayOutOfBoundsException if invalid UTF8 is passed). Explicit checks for valid UTF8 are not performed. The char[] out should probably have enough room to hold the worst case of each byte becoming a Java char.


UTF8toUTF16

public static void UTF8toUTF16(byte[] utf8,
                               int offset,
                               int len,
                               org.noggit.CharArr out)
Convert UTF8 bytes into UTF16 characters.


UTF8toUTF16

public static String UTF8toUTF16(byte[] utf8,
                                 int offset,
                                 int len)
Convert UTF8 bytes into a String


UTF16toUTF8

public static int UTF16toUTF8(CharSequence s,
                              int offset,
                              int len,
                              byte[] result,
                              int resultOffset)
Writes UTF8 into the byte array, starting at offset. The caller should ensure that there is enough space for the worst-case scenario.

Returns:
the number of bytes written


Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.