java.nio.charset.CoderResult.malformedForLength()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中java.nio.charset.CoderResult.malformedForLength()方法的一些代码示例,展示了CoderResult.malformedForLength()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CoderResult.malformedForLength()方法的具体详情如下:
包路径:java.nio.charset.CoderResult
类名称:CoderResult
方法名:malformedForLength

CoderResult.malformedForLength介绍

[英]Gets a CoderResult object indicating a malformed-input error.
[中]获取一个CoderResult对象,该对象指示格式错误的输入错误。

代码示例

代码示例来源:origin: com.alibaba/fastjson

private static CoderResult lookupN(ByteBuffer src, int n) {
  for (int i = 1; i < n; i++) {
    if (isNotContinuation(src.get())) return CoderResult.malformedForLength(i);
  }
  return CoderResult.malformedForLength(n);
}

代码示例来源:origin: com.alibaba/fastjson

return CoderResult.malformedForLength(1);
case 2: // always 1
  return CoderResult.malformedForLength(1);
case 3:
  b1 = src.get();
  int b2 = src.get(); // no need to lookup b3
  return CoderResult.malformedForLength(((b1 == (byte) 0xe0 && (b2 & 0xe0) == 0x80) || isNotContinuation(b2)) ? 1 : 2);
case 4: // we don't care the speed here
  b1 = src.get() & 0xff;
  b2 = src.get() & 0xff;
  if (b1 > 0xf4 || (b1 == 0xf0 && (b2 < 0x90 || b2 > 0xbf)) || (b1 == 0xf4 && (b2 & 0xf0) != 0x80) || isNotContinuation(b2)) return CoderResult.malformedForLength(1);
  if (isNotContinuation(src.get())) return CoderResult.malformedForLength(2);
  return CoderResult.malformedForLength(3);
default:
  throw new IllegalStateException();

代码示例来源:origin: robovm/robovm

result = CoderResult.malformedForLength(in.remaining());
} else {
  return result;

代码示例来源:origin: robovm/robovm

result = CoderResult.malformedForLength(in.remaining());
} else {
  return result;

代码示例来源:origin: robovm/robovm

@Override protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
  if (!in.hasRemaining()) {
    return CoderResult.UNDERFLOW;
  }
  data[INPUT_OFFSET] = getArray(in);
  data[OUTPUT_OFFSET]= getArray(out);
  data[INVALID_CHARS] = 0; // Make sure we don't see earlier errors.
  try {
    int error = NativeConverter.encode(converterHandle, input, inEnd, output, outEnd, data, false);
    if (ICU.U_FAILURE(error)) {
      if (error == ICU.U_BUFFER_OVERFLOW_ERROR) {
        return CoderResult.OVERFLOW;
      } else if (error == ICU.U_INVALID_CHAR_FOUND) {
        return CoderResult.unmappableForLength(data[INVALID_CHARS]);
      } else if (error == ICU.U_ILLEGAL_CHAR_FOUND) {
        return CoderResult.malformedForLength(data[INVALID_CHARS]);
      } else {
        throw new AssertionError(error);
      }
    }
    // Decoding succeeded: give us more data.
    return CoderResult.UNDERFLOW;
  } finally {
    setPosition(in);
    setPosition(out);
  }
}

代码示例来源:origin: robovm/robovm

@Override protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
  if (!in.hasRemaining()) {
    return CoderResult.UNDERFLOW;
  }
  data[INPUT_OFFSET] = getArray(in);
  data[OUTPUT_OFFSET]= getArray(out);
  try {
    int error = NativeConverter.decode(converterHandle, input, inEnd, output, outEnd, data, false);
    if (ICU.U_FAILURE(error)) {
      if (error == ICU.U_BUFFER_OVERFLOW_ERROR) {
        return CoderResult.OVERFLOW;
      } else if (error == ICU.U_INVALID_CHAR_FOUND) {
        return CoderResult.unmappableForLength(data[INVALID_BYTES]);
      } else if (error == ICU.U_ILLEGAL_CHAR_FOUND) {
        return CoderResult.malformedForLength(data[INVALID_BYTES]);
      } else {
        throw new AssertionError(error);
      }
    }
    // Decoding succeeded: give us more data.
    return CoderResult.UNDERFLOW;
  } finally {
    setPosition(in);
    setPosition(out);
  }
}

代码示例来源:origin: robovm/robovm

@Override protected final CoderResult implFlush(CharBuffer out) {
  try {
    // ICU needs to see an empty input.
    input = EmptyArray.BYTE;
    inEnd = 0;
    data[INPUT_OFFSET] = 0;
    data[OUTPUT_OFFSET] = getArray(out);
    data[INVALID_BYTES] = 0; // Make sure we don't see earlier errors.
    int error = NativeConverter.decode(converterHandle, input, inEnd, output, outEnd, data, true);
    if (ICU.U_FAILURE(error)) {
      if (error == ICU.U_BUFFER_OVERFLOW_ERROR) {
        return CoderResult.OVERFLOW;
      } else if (error == ICU.U_TRUNCATED_CHAR_FOUND) {
        if (data[INPUT_OFFSET] > 0) {
          return CoderResult.malformedForLength(data[INPUT_OFFSET]);
        }
      }
    }
    return CoderResult.UNDERFLOW;
  } finally {
    setPosition(out);
    implReset();
  }
}

代码示例来源:origin: robovm/robovm

@Override protected CoderResult implFlush(ByteBuffer out) {
  try {
    // ICU needs to see an empty input.
    input = EmptyArray.CHAR;
    inEnd = 0;
    data[INPUT_OFFSET] = 0;
    data[OUTPUT_OFFSET] = getArray(out);
    data[INVALID_CHARS] = 0; // Make sure we don't see earlier errors.
    int error = NativeConverter.encode(converterHandle, input, inEnd, output, outEnd, data, true);
    if (ICU.U_FAILURE(error)) {
      if (error == ICU.U_BUFFER_OVERFLOW_ERROR) {
        return CoderResult.OVERFLOW;
      } else if (error == ICU.U_TRUNCATED_CHAR_FOUND) {
        if (data[INPUT_OFFSET] > 0) {
          return CoderResult.malformedForLength(data[INPUT_OFFSET]);
        }
      }
    }
    return CoderResult.UNDERFLOW;
  } finally {
    setPosition(out);
    implReset();
  }
}

代码示例来源:origin: apache/tika

@Override
protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
  if (in.hasRemaining() && !replacementErrorReturned) {
    replacementErrorReturned = true;
    return CoderResult.malformedForLength(in.remaining());
  }
  in.position(in.limit());
  return CoderResult.UNDERFLOW;
}

代码示例来源:origin: org.mule.glassfish.grizzly/grizzly-websockets

private static CoderResult malformedForLength(ByteBuffer src,
                       int sp,
                       CharBuffer dst,
                       int dp,
                       int malformedNB)
{
  updatePositions(src, sp, dst, dp);
  return CoderResult.malformedForLength(malformedNB);
}

代码示例来源:origin: com.sun.grizzly/grizzly-websockets

private static CoderResult malformedForLength(ByteBuffer src,
                       int sp,
                       CharBuffer dst,
                       int dp,
                       int malformedNB)
{
  updatePositions(src, sp, dst, dp);
  return CoderResult.malformedForLength(malformedNB);
}

代码示例来源:origin: org.glassfish.tyrus/tyrus-websocket-core

private static CoderResult malformedForLength(ByteBuffer src,
                       int sp,
                       CharBuffer dst,
                       int dp,
                       int malformedNB) {
  updatePositions(src, sp, dst, dp);
  return CoderResult.malformedForLength(malformedNB);
}

代码示例来源:origin: org.mule.glassfish.grizzly/grizzly-websockets

private static CoderResult malformedForLength(ByteBuffer src,
                       int mark,
                       int malformedNB)
{
  src.position(mark);
  return CoderResult.malformedForLength(malformedNB);
}

代码示例来源:origin: com.sun.grizzly/grizzly-websockets

private static CoderResult malformedForLength(ByteBuffer src,
                       int mark,
                       int malformedNB)
{
  src.position(mark);
  return CoderResult.malformedForLength(malformedNB);
}

代码示例来源:origin: org.glassfish.tyrus/tyrus-websocket-core

private static CoderResult malformedForLength(ByteBuffer src,
                       int mark,
                       int malformedNB) {
  src.position(mark);
  return CoderResult.malformedForLength(malformedNB);
}

代码示例来源:origin: com.beetstra.jutf7/jutf7

/**
 * <p>Resets the input buffer position to just before the last byte read, and returns
 * a result indicating to skip the last byte.</p>
 * 
 * @param in The input buffer
 * @return CoderResult.malformedForLength(1);
 */
private CoderResult malformed(ByteBuffer in) {
  in.position(in.position() - 1);
  return CoderResult.malformedForLength(1);
}

代码示例来源:origin: com.aliyun.openservices/ons-client

private static CoderResult lookupN(ByteBuffer src, int n) {
  for (int i = 1; i < n; i++) {
    if (isNotContinuation(src.get())) return CoderResult.malformedForLength(i);
  }
  return CoderResult.malformedForLength(n);
}

代码示例来源:origin: jobop/anylog

private static CoderResult lookupN(ByteBuffer src, int n) {
  for (int i = 1; i < n; i++) {
    if (isNotContinuation(src.get())) return CoderResult.malformedForLength(i);
  }
  return CoderResult.malformedForLength(n);
}

代码示例来源:origin: org.apache.tika/tika-parsers

@Override
protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
  if (in.hasRemaining() && !replacementErrorReturned) {
    replacementErrorReturned = true;
    return CoderResult.malformedForLength(in.remaining());
  }
  in.position(in.limit());
  return CoderResult.UNDERFLOW;
}

代码示例来源:origin: com.beetstra.jutf7/jutf7

protected CoderResult implFlush(CharBuffer out) {
  if ((base64mode && strict) || base64bitsWaiting())
    return CoderResult.malformedForLength(1);
  return CoderResult.UNDERFLOW;
}

相关文章