okio.Buffer.writeUtf8CodePoint()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(102)

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

Buffer.writeUtf8CodePoint介绍

暂无

代码示例

代码示例来源:origin: square/okhttp

/** Returns {@code s} with control characters and non-ASCII characters replaced with '?'. */
private static String toHumanReadableAscii(String s) {
 for (int i = 0, length = s.length(), c; i < length; i += Character.charCount(c)) {
  c = s.codePointAt(i);
  if (c > '\u001f' && c < '\u007f') continue;
  Buffer buffer = new Buffer();
  buffer.writeUtf8(s, 0, i);
  buffer.writeUtf8CodePoint('?');
  for (int j = i + Character.charCount(c); j < length; j += Character.charCount(c)) {
   c = s.codePointAt(j);
   buffer.writeUtf8CodePoint(c > '\u001f' && c < '\u007f' ? c : '?');
  }
  return buffer.readUtf8();
 }
 return s;
}

代码示例来源:origin: square/okhttp

static void percentDecode(Buffer out, String encoded, int pos, int limit, boolean plusIsSpace) {
 int codePoint;
 for (int i = pos; i < limit; i += Character.charCount(codePoint)) {
  codePoint = encoded.codePointAt(i);
  if (codePoint == '%' && i + 2 < limit) {
   int d1 = decodeHexDigit(encoded.charAt(i + 1));
   int d2 = decodeHexDigit(encoded.charAt(i + 2));
   if (d1 != -1 && d2 != -1) {
    out.writeByte((d1 << 4) + d2);
    i += 2;
    continue;
   }
  } else if (codePoint == '+' && plusIsSpace) {
   out.writeByte(' ');
   continue;
  }
  out.writeUtf8CodePoint(codePoint);
 }
}

代码示例来源:origin: square/retrofit

private static void canonicalizeForPath(Buffer out, String input, int pos, int limit,
  boolean alreadyEncoded) {
 Buffer utf8Buffer = null; // Lazily allocated.
 int codePoint;
 for (int i = pos; i < limit; i += Character.charCount(codePoint)) {
  codePoint = input.codePointAt(i);
  if (alreadyEncoded
    && (codePoint == '\t' || codePoint == '\n' || codePoint == '\f' || codePoint == '\r')) {
   // Skip this character.
  } else if (codePoint < 0x20 || codePoint >= 0x7f
    || PATH_SEGMENT_ALWAYS_ENCODE_SET.indexOf(codePoint) != -1
    || (!alreadyEncoded && (codePoint == '/' || codePoint == '%'))) {
   // Percent encode this character.
   if (utf8Buffer == null) {
    utf8Buffer = new Buffer();
   }
   utf8Buffer.writeUtf8CodePoint(codePoint);
   while (!utf8Buffer.exhausted()) {
    int b = utf8Buffer.readByte() & 0xff;
    out.writeByte('%');
    out.writeByte(HEX_DIGITS[(b >> 4) & 0xf]);
    out.writeByte(HEX_DIGITS[b & 0xf]);
   }
  } else {
   // This character doesn't need encoding. Just copy it over.
   out.writeUtf8CodePoint(codePoint);
  }
 }
}

代码示例来源:origin: airbnb/DeepLinkDispatch

static void percentDecode(Buffer out, String encoded, int pos, int limit) {
 int codePoint;
 for (int i = pos; i < limit; i += Character.charCount(codePoint)) {
  codePoint = encoded.codePointAt(i);
  if (codePoint == '%' && i + 2 < limit) {
   int d1 = decodeHexDigit(encoded.charAt(i + 1));
   int d2 = decodeHexDigit(encoded.charAt(i + 2));
   if (d1 != -1 && d2 != -1) {
    out.writeByte((d1 << 4) + d2);
    i += 2;
    continue;
   }
  }
  out.writeUtf8CodePoint(codePoint);
 }
}

代码示例来源:origin: square/okhttp

encodedCharBuffer.writeUtf8CodePoint(codePoint);
} else {
 encodedCharBuffer.writeString(input, i, i + Character.charCount(codePoint), charset);
out.writeUtf8CodePoint(codePoint);

代码示例来源:origin: com.squareup.okhttp3/okhttp

static void percentDecode(Buffer out, String encoded, int pos, int limit, boolean plusIsSpace) {
 int codePoint;
 for (int i = pos; i < limit; i += Character.charCount(codePoint)) {
  codePoint = encoded.codePointAt(i);
  if (codePoint == '%' && i + 2 < limit) {
   int d1 = decodeHexDigit(encoded.charAt(i + 1));
   int d2 = decodeHexDigit(encoded.charAt(i + 2));
   if (d1 != -1 && d2 != -1) {
    out.writeByte((d1 << 4) + d2);
    i += 2;
    continue;
   }
  } else if (codePoint == '+' && plusIsSpace) {
   out.writeByte(' ');
   continue;
  }
  out.writeUtf8CodePoint(codePoint);
 }
}

代码示例来源:origin: com.squareup.retrofit2/retrofit

private static void canonicalizeForPath(Buffer out, String input, int pos, int limit,
  boolean alreadyEncoded) {
 Buffer utf8Buffer = null; // Lazily allocated.
 int codePoint;
 for (int i = pos; i < limit; i += Character.charCount(codePoint)) {
  codePoint = input.codePointAt(i);
  if (alreadyEncoded
    && (codePoint == '\t' || codePoint == '\n' || codePoint == '\f' || codePoint == '\r')) {
   // Skip this character.
  } else if (codePoint < 0x20 || codePoint >= 0x7f
    || PATH_SEGMENT_ALWAYS_ENCODE_SET.indexOf(codePoint) != -1
    || (!alreadyEncoded && (codePoint == '/' || codePoint == '%'))) {
   // Percent encode this character.
   if (utf8Buffer == null) {
    utf8Buffer = new Buffer();
   }
   utf8Buffer.writeUtf8CodePoint(codePoint);
   while (!utf8Buffer.exhausted()) {
    int b = utf8Buffer.readByte() & 0xff;
    out.writeByte('%');
    out.writeByte(HEX_DIGITS[(b >> 4) & 0xf]);
    out.writeByte(HEX_DIGITS[b & 0xf]);
   }
  } else {
   // This character doesn't need encoding. Just copy it over.
   out.writeUtf8CodePoint(codePoint);
  }
 }
}

代码示例来源:origin: airbnb/DeepLinkDispatch

utf8Buffer = new Buffer();
utf8Buffer.writeUtf8CodePoint(codePoint);
while (!utf8Buffer.exhausted()) {
 int b = utf8Buffer.readByte() & 0xff;
out.writeUtf8CodePoint(codePoint);

代码示例来源:origin: square/okio

@Test public void writeCodePointBeyondUnicodeMaximum() throws Exception {
 Buffer buffer = new Buffer();
 try {
  buffer.writeUtf8CodePoint(0x110000);
  fail();
 } catch (IllegalArgumentException expected) {
 }
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

encodedCharBuffer.writeUtf8CodePoint(codePoint);
} else {
 encodedCharBuffer.writeString(input, i, i + Character.charCount(codePoint), charset);
out.writeUtf8CodePoint(codePoint);

代码示例来源:origin: square/okio

private void assertCodePointEncoded(String hex, int... codePoints) throws Exception {
 Buffer buffer = new Buffer();
 for (int codePoint : codePoints) {
  buffer.writeUtf8CodePoint(codePoint);
 }
 assertEquals(buffer.readByteString(), ByteString.decodeHex(hex));
}

代码示例来源:origin: square/okio

private void assertStringEncoded(String hex, String string) throws Exception {
  ByteString expectedUtf8 = ByteString.decodeHex(hex);

  // Confirm our expectations are consistent with the platform.
  ByteString platformUtf8 = ByteString.of(string.getBytes("UTF-8"));
  assertEquals(expectedUtf8, platformUtf8);

  // Confirm our implementation matches those expectations.
  ByteString actualUtf8 = new Buffer().writeUtf8(string).readByteString();
  assertEquals(expectedUtf8, actualUtf8);

  // Confirm we are consistent when writing one code point at a time.
  Buffer bufferUtf8 = new Buffer();
  for (int i = 0; i < string.length(); ) {
   int c = string.codePointAt(i);
   bufferUtf8.writeUtf8CodePoint(c);
   i += Character.charCount(c);
  }
  assertEquals(expectedUtf8, bufferUtf8.readByteString());

  // Confirm we are consistent when measuring lengths.
  assertEquals(expectedUtf8.size(), Utf8.size(string));
  assertEquals(expectedUtf8.size(), Utf8.size(string, 0, string.length()));
 }
}

代码示例来源:origin: huxq17/tractor

@Override public BufferedSink writeUtf8CodePoint(int codePoint) throws IOException {
 if (closed) throw new IllegalStateException("closed");
 buffer.writeUtf8CodePoint(codePoint);
 return emitCompleteSegments();
}

代码示例来源:origin: apache/servicemix-bundles

/** Returns {@code s} with control characters and non-ASCII characters replaced with '?'. */
private static String toHumanReadableAscii(String s) {
 for (int i = 0, length = s.length(), c; i < length; i += Character.charCount(c)) {
  c = s.codePointAt(i);
  if (c > '\u001f' && c < '\u007f') continue;
  Buffer buffer = new Buffer();
  buffer.writeUtf8(s, 0, i);
  buffer.writeUtf8CodePoint('?');
  for (int j = i + Character.charCount(c); j < length; j += Character.charCount(c)) {
   c = s.codePointAt(j);
   buffer.writeUtf8CodePoint(c > '\u001f' && c < '\u007f' ? c : '?');
  }
  return buffer.readUtf8();
 }
 return s;
}

代码示例来源:origin: com.squareup.okhttp3/okhttp-urlconnection

/** Returns {@code s} with control characters and non-ASCII characters replaced with '?'. */
private static String toHumanReadableAscii(String s) {
 for (int i = 0, length = s.length(), c; i < length; i += Character.charCount(c)) {
  c = s.codePointAt(i);
  if (c > '\u001f' && c < '\u007f') continue;
  Buffer buffer = new Buffer();
  buffer.writeUtf8(s, 0, i);
  buffer.writeUtf8CodePoint('?');
  for (int j = i + Character.charCount(c); j < length; j += Character.charCount(c)) {
   c = s.codePointAt(j);
   buffer.writeUtf8CodePoint(c > '\u001f' && c < '\u007f' ? c : '?');
  }
  return buffer.readUtf8();
 }
 return s;
}

代码示例来源:origin: io.apptik.comm/jus-java

/** Returns {@code s} with control characters and non-ASCII characters replaced with '?'. */
public static String toHumanReadableAscii(String s) {
 for (int i = 0, length = s.length(), c; i < length; i += Character.charCount(c)) {
  c = s.codePointAt(i);
  if (c > '\u001f' && c < '\u007f') continue;
  Buffer buffer = new Buffer();
  buffer.writeUtf8(s, 0, i);
  for (int j = i; j < length; j += Character.charCount(c)) {
   c = s.codePointAt(j);
   buffer.writeUtf8CodePoint(c > '\u001f' && c < '\u007f' ? c : '?');
  }
  return buffer.readUtf8();
 }
 return s;
}

代码示例来源:origin: huxq17/SwipeCardsView

/** Returns {@code s} with control characters and non-ASCII characters replaced with '?'. */
public static String toHumanReadableAscii(String s) {
 for (int i = 0, length = s.length(), c; i < length; i += Character.charCount(c)) {
  c = s.codePointAt(i);
  if (c > '\u001f' && c < '\u007f') continue;
  Buffer buffer = new Buffer();
  buffer.writeUtf8(s, 0, i);
  for (int j = i; j < length; j += Character.charCount(c)) {
   c = s.codePointAt(j);
   buffer.writeUtf8CodePoint(c > '\u001f' && c < '\u007f' ? c : '?');
  }
  return buffer.readUtf8();
 }
 return s;
}

代码示例来源:origin: com.github.ljun20160606/okhttp

/** Returns {@code s} with control characters and non-ASCII characters replaced with '?'. */
public static String toHumanReadableAscii(String s) {
 for (int i = 0, length = s.length(), c; i < length; i += Character.charCount(c)) {
  c = s.codePointAt(i);
  if (c > '\u001f' && c < '\u007f') continue;
  Buffer buffer = new Buffer();
  buffer.writeUtf8(s, 0, i);
  for (int j = i; j < length; j += Character.charCount(c)) {
   c = s.codePointAt(j);
   buffer.writeUtf8CodePoint(c > '\u001f' && c < '\u007f' ? c : '?');
  }
  return buffer.readUtf8();
 }
 return s;
}

代码示例来源:origin: duzechao/OKHttpUtils

/** Returns {@code s} with control characters and non-ASCII characters replaced with '?'. */
public static String toHumanReadableAscii(String s) {
 for (int i = 0, length = s.length(), c; i < length; i += Character.charCount(c)) {
  c = s.codePointAt(i);
  if (c > '\u001f' && c < '\u007f') continue;
  Buffer buffer = new Buffer();
  buffer.writeUtf8(s, 0, i);
  for (int j = i; j < length; j += Character.charCount(c)) {
   c = s.codePointAt(j);
   buffer.writeUtf8CodePoint(c > '\u001f' && c < '\u007f' ? c : '?');
  }
  return buffer.readUtf8();
 }
 return s;
}

代码示例来源:origin: huxq17/tractor

/** Returns {@code s} with control characters and non-ASCII characters replaced with '?'. */
public static String toHumanReadableAscii(String s) {
 for (int i = 0, length = s.length(), c; i < length; i += Character.charCount(c)) {
  c = s.codePointAt(i);
  if (c > '\u001f' && c < '\u007f') continue;
  Buffer buffer = new Buffer();
  buffer.writeUtf8(s, 0, i);
  for (int j = i; j < length; j += Character.charCount(c)) {
   c = s.codePointAt(j);
   buffer.writeUtf8CodePoint(c > '\u001f' && c < '\u007f' ? c : '?');
  }
  return buffer.readUtf8();
 }
 return s;
}

相关文章