Tabnine Logo
UTF8
Code IndexAdd Tabnine to your IDE (free)

How to use
UTF8
in
com.wizzardo.tools.misc

Best Java code snippets using com.wizzardo.tools.misc.UTF8 (Showing top 20 results out of 315)

origin: com.wizzardo.tools/tools-misc

public static int decode(byte[] bytes, int offset, int length, char[] chars) {
  return decode(bytes, offset, length, chars, 0);
}
origin: wizzardo/tools

public static byte[] encode(char[] chars) {
  return encode(chars, 0, chars.length);
}
origin: wizzardo/tools

/**
 * @return byte array with UTF-8 encoded string
 **/
public byte[] toBytes() {
  if (utf8Buffer == null)
    utf8Buffer = new UTF8();
  return utf8Buffer.toBytes(buffer, 0, length);
}
origin: wizzardo/tools

public static byte[] encode(char[] chars, int off, int length) {
  byte[] bytes = new byte[count(chars, off, length)];
  encode(chars, off, length, bytes);
  return bytes;
}
origin: com.wizzardo.tools/tools-misc

    b1 = bytes[offset++];
    b2 = bytes[offset++];
    if (isMalformed3(b, b1, b2)) {
      chars[i++] = MALFORMED;
    } else {
      char ch = (char) (b << 12 ^ b1 << 6 ^ b2 ^ -123008);
      if (isSurrogate(ch)) {
        chars[i++] = MALFORMED;
      } else {
    if (offset >= to || !isMalformed3_2(b, bytes[offset])) {
      chars[i++] = MALFORMED;
      return i;
  int b3 = bytes[offset++];
  int value = b << 18 ^ b1 << 12 ^ b2 << 6 ^ b3 ^ 3678080;
  if (!isMalformed4(b1, b2, b3) && isSupplementaryCodePoint(value)) {
    chars[i++] = highSurrogate(value);
    chars[i++] = lowSurrogate(value);
  } else {
    chars[i++] = MALFORMED;
  if (i1 <= 244 && (offset >= to || !isMalformed4_2(i1, bytes[offset] & 0xff))) {
    ++offset;
    if (offset >= to || !isMalformed4_3(bytes[offset])) {
      chars[i++] = MALFORMED;
      return i;
if (isNotContinuation(b1)) {
origin: com.wizzardo.tools/tools-misc

public byte[] toBytes(char[] chars, int offset, int length) {
  if (buffer == null || buffer.length < length * 4)
    buffer = new byte[length * 4];
  return encodeAndTrim(chars, offset, length, buffer);
}
origin: wizzardo/tools

    b1 = bytes[offset++];
    b2 = bytes[offset++];
    if (isMalformed3(b, b1, b2)) {
      chars[i++] = MALFORMED;
    } else {
      char ch = (char) (b << 12 ^ b1 << 6 ^ b2 ^ -123008);
      if (isSurrogate(ch)) {
        chars[i++] = MALFORMED;
      } else {
    if (offset >= to || !isMalformed3_2(b, bytes[offset])) {
      chars[i++] = MALFORMED;
      return i;
  int b3 = bytes[offset++];
  int value = b << 18 ^ b1 << 12 ^ b2 << 6 ^ b3 ^ 3678080;
  if (!isMalformed4(b1, b2, b3) && isSupplementaryCodePoint(value)) {
    chars[i++] = highSurrogate(value);
    chars[i++] = lowSurrogate(value);
  } else {
    chars[i++] = MALFORMED;
  if (i1 <= 244 && (offset >= to || !isMalformed4_2(i1, bytes[offset] & 0xff))) {
    ++offset;
    if (offset >= to || !isMalformed4_3(bytes[offset])) {
      chars[i++] = MALFORMED;
      return i;
if (isNotContinuation(b1)) {
origin: com.wizzardo.tools/tools-misc

public static byte[] encode(char[] chars, int off, int length) {
  byte[] bytes = new byte[count(chars, off, length)];
  encode(chars, off, length, bytes);
  return bytes;
}
origin: wizzardo/tools

public byte[] toBytes(char[] chars, int offset, int length) {
  if (buffer == null || buffer.length < length * 4)
    buffer = new byte[length * 4];
  return encodeAndTrim(chars, offset, length, buffer);
}
origin: com.wizzardo.tools/tools-misc

context.buffer[cl++] = bytes[offset++];
context.length = 0;
if (decode(context.buffer, 0, cl, chars, context).charsOffset == i) { // 2 bytes
  if (offset < to) {
    context.buffer[cl++] = bytes[offset++];
    context.length = 0;
    if (decode(context.buffer, 0, cl, chars, context).charsOffset == i) {// 3 bytes
      if (offset < to) {
        context.buffer[cl++] = bytes[offset++];
        context.length = 0;
        i = decode(context.buffer, 0, cl, chars, context).charsOffset; // 4 bytes
      } else {
        context.length = cl;
        b1 = bytes[offset++];
        b2 = bytes[offset++];
        if (isMalformed3(b, b1, b2)) {
          chars[i++] = MALFORMED;
        } else {
          char ch = (char) (b << 12 ^ b1 << 6 ^ b2 ^ -123008);
          if (isSurrogate(ch)) {
            chars[i++] = MALFORMED;
          } else {
        if (offset >= to || !isMalformed3_2(b, bytes[offset])) {
          return context.update(i, bytes, offset - 1, to);
      int b3 = bytes[offset++];
      int value = b << 18 ^ b1 << 12 ^ b2 << 6 ^ b3 ^ 3678080;
origin: wizzardo/tools

public void toBytes(Supplier<byte[]> bytesSupplier, UTF8.BytesConsumer bytesConsumer) {
  UTF8.encode(buffer, 0, length, bytesSupplier, bytesConsumer);
}
origin: wizzardo/tools

public static int decode(byte[] bytes, int offset, int length, char[] chars) {
  return decode(bytes, offset, length, chars, 0);
}
origin: com.wizzardo.tools/tools-misc

/**
 * @return byte array with UTF-8 encoded string
 **/
public byte[] toBytes() {
  if (utf8Buffer == null)
    utf8Buffer = new UTF8();
  return utf8Buffer.toBytes(buffer, 0, length);
}
origin: wizzardo/tools

context.buffer[cl++] = bytes[offset++];
context.length = 0;
if (decode(context.buffer, 0, cl, chars, context).charsOffset == i) { // 2 bytes
  if (offset < to) {
    context.buffer[cl++] = bytes[offset++];
    context.length = 0;
    if (decode(context.buffer, 0, cl, chars, context).charsOffset == i) {// 3 bytes
      if (offset < to) {
        context.buffer[cl++] = bytes[offset++];
        context.length = 0;
        i = decode(context.buffer, 0, cl, chars, context).charsOffset; // 4 bytes
      } else {
        context.length = cl;
        b1 = bytes[offset++];
        b2 = bytes[offset++];
        if (isMalformed3(b, b1, b2)) {
          chars[i++] = MALFORMED;
        } else {
          char ch = (char) (b << 12 ^ b1 << 6 ^ b2 ^ -123008);
          if (isSurrogate(ch)) {
            chars[i++] = MALFORMED;
          } else {
        if (offset >= to || !isMalformed3_2(b, bytes[offset])) {
          return context.update(i, bytes, offset - 1, to);
      int b3 = bytes[offset++];
      int value = b << 18 ^ b1 << 12 ^ b2 << 6 ^ b3 ^ 3678080;
origin: com.wizzardo.tools/tools-misc

public void toBytes(Supplier<byte[]> bytesSupplier, UTF8.BytesConsumer bytesConsumer) {
  UTF8.encode(buffer, 0, length, bytesSupplier, bytesConsumer);
}
origin: wizzardo/tools

for (int i = 0; i <= 0x7F; i++) {
  bytes[0] = (byte) i;
  int r = UTF8.decode(bytes, 0, bytes.length, chars);
  Assert.assertEquals(new String(bytes, charset), new String(chars, 0, r));
  for (int j = 0; j < 256; j++) {
    bytes[1] = (byte) (j & 0x7f | 0x80);
    int r = UTF8.decode(bytes, 0, bytes.length, chars);
    Assert.assertEquals(i + " " + j, new String(bytes, charset), new String(chars, 0, r));
    for (int k = 0; k < 64; k++) {
      bytes[2] = (byte) (k & 0x7f | 0x80);
      int r = UTF8.decode(bytes, 0, bytes.length, chars);
      String expected = new String(bytes, charset);
      if (expected.charAt(0) >= '\uD800' && expected.charAt(0) <= '\uDFFF')
      for (int m = 0; m < 64; m++) {
        bytes[3] = (byte) (m & 0x7f | 0x80);
        int r = UTF8.decode(bytes, 0, bytes.length, chars);
        if (r == 1 && chars[0] == '�') {
          char[] c = new String(bytes, charset).toCharArray();
origin: com.wizzardo.tools/tools-misc

    b1 = bytes[offset++];
    b2 = bytes[offset++];
    if (isMalformed3(b, b1, b2)) {
      chars[i++] = MALFORMED;
    } else {
      char ch = (char) (b << 12 ^ b1 << 6 ^ b2 ^ -123008);
      if (isSurrogate(ch)) {
        chars[i++] = MALFORMED;
      } else {
    if (offset >= to || !isMalformed3_2(b, bytes[offset])) {
      return offsets.update(i, offset - 1);
  int b3 = bytes[offset++];
  int value = b << 18 ^ b1 << 12 ^ b2 << 6 ^ b3 ^ 3678080;
  if (!isMalformed4(b1, b2, b3) && isSupplementaryCodePoint(value)) {
    chars[i++] = highSurrogate(value);
    chars[i++] = lowSurrogate(value);
  } else {
    chars[i++] = MALFORMED;
  if (i1 <= 244 && (offset >= to || !isMalformed4_2(i1, bytes[offset] & 0xff))) {
    offset++;
    if (offset >= to || !isMalformed4_3(bytes[offset]))
      return offsets.update(i, offset - 2);
if (isNotContinuation(b1)) {
  chars[i++] = MALFORMED;
  --offset;
origin: com.wizzardo.tools/tools-misc

public static byte[] encode(char[] chars) {
  return encode(chars, 0, chars.length);
}
origin: wizzardo/tools

@Test
public void decode_continuous_1() throws UnsupportedEncodingException {
  String s = "€";
  char[] chars = new char[1];
  byte[] bytes = s.getBytes("utf-8");
  Assert.assertEquals(3, bytes.length);
  int read;
  UTF8.DecodeOffsets offsets = new UTF8.DecodeOffsets();
  read = 1;
  offsets = UTF8.decode(bytes, read, chars, offsets);
  Assert.assertEquals(0, offsets.bytesOffset);
  Assert.assertEquals(0, offsets.charsOffset);
  read++;
  offsets = UTF8.decode(bytes, read, chars, offsets);
  Assert.assertEquals(0, offsets.bytesOffset);
  Assert.assertEquals(0, offsets.charsOffset);
  read++;
  offsets = UTF8.decode(bytes, read, chars, offsets);
  Assert.assertEquals(3, offsets.bytesOffset);
  Assert.assertEquals(1, offsets.charsOffset);
  Assert.assertEquals(s.charAt(0), chars[0]);
}
origin: wizzardo/tools

    b1 = bytes[offset++];
    b2 = bytes[offset++];
    if (isMalformed3(b, b1, b2)) {
      chars[i++] = MALFORMED;
    } else {
      char ch = (char) (b << 12 ^ b1 << 6 ^ b2 ^ -123008);
      if (isSurrogate(ch)) {
        chars[i++] = MALFORMED;
      } else {
    if (offset >= to || !isMalformed3_2(b, bytes[offset])) {
      return offsets.update(i, offset - 1);
  int b3 = bytes[offset++];
  int value = b << 18 ^ b1 << 12 ^ b2 << 6 ^ b3 ^ 3678080;
  if (!isMalformed4(b1, b2, b3) && isSupplementaryCodePoint(value)) {
    chars[i++] = highSurrogate(value);
    chars[i++] = lowSurrogate(value);
  } else {
    chars[i++] = MALFORMED;
  if (i1 <= 244 && (offset >= to || !isMalformed4_2(i1, bytes[offset] & 0xff))) {
    offset++;
    if (offset >= to || !isMalformed4_3(bytes[offset]))
      return offsets.update(i, offset - 2);
if (isNotContinuation(b1)) {
  chars[i++] = MALFORMED;
  --offset;
com.wizzardo.tools.miscUTF8

Javadoc

Created by wizzardo on 30.03.15.

Most used methods

  • decode
  • encode
  • <init>
  • count
  • encodeAndTrim
  • highSurrogate
  • isMalformed3
  • isMalformed3_2
  • isMalformed4
  • isMalformed4_2
  • isMalformed4_3
  • isNotContinuation
  • isMalformed4_3,
  • isNotContinuation,
  • isSupplementaryCodePoint,
  • isSurrogate,
  • lowSurrogate,
  • parseSurrogate,
  • toBytes

Popular in Java

  • Start an intent from android
  • scheduleAtFixedRate (Timer)
  • findViewById (Activity)
  • setContentView (Activity)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • Permission (java.security)
    Legacy security code; do not use.
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now