org.apache.hadoop.io.Text.utf8Length()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(95)

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

Text.utf8Length介绍

[英]For the given string, returns the number of UTF-8 bytes required to encode the string.
[中]对于给定字符串,返回编码字符串所需的UTF-8字节数。

代码示例

代码示例来源:origin: edu.umd/cloud9

public int remoteAddOrGet(String word) {
  int res = 0;
  try {
    os.writeByte(Text.utf8Length(word));
    Text.writeString(os, word);
    os.writeByte(0);
    os.flush();
    res = is.readInt();
  } catch (IOException e) {
    throw new RuntimeException("Caught " +e);
  }
  return res;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

public void testUtf8Length() {
 assertEquals("testUtf8Length1 error   !!!",
     1, Text.utf8Length(new String(new char[]{(char)1})));
 assertEquals("testUtf8Length127 error !!!",
     1, Text.utf8Length(new String(new char[]{(char)127})));
 assertEquals("testUtf8Length128 error !!!",
     2, Text.utf8Length(new String(new char[]{(char)128})));
 assertEquals("testUtf8Length193 error !!!",
     2, Text.utf8Length(new String(new char[]{(char)193})));
 assertEquals("testUtf8Length225 error !!!",
     2, Text.utf8Length(new String(new char[]{(char)225})));
 assertEquals("testUtf8Length254 error !!!",
     2, Text.utf8Length(new String(new char[]{(char)254})));
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

public void testUtf8Length() {
 assertEquals("testUtf8Length1 error   !!!",
     1, Text.utf8Length(new String(new char[]{(char)1})));
 assertEquals("testUtf8Length127 error !!!",
     1, Text.utf8Length(new String(new char[]{(char)127})));
 assertEquals("testUtf8Length128 error !!!",
     2, Text.utf8Length(new String(new char[]{(char)128})));
 assertEquals("testUtf8Length193 error !!!",
     2, Text.utf8Length(new String(new char[]{(char)193})));
 assertEquals("testUtf8Length225 error !!!",
     2, Text.utf8Length(new String(new char[]{(char)225})));
 assertEquals("testUtf8Length254 error !!!",
     2, Text.utf8Length(new String(new char[]{(char)254})));
}

代码示例来源:origin: org.apache.hadoop/hadoop-common-test

public void testIO() throws Exception {
 DataOutputBuffer out = new DataOutputBuffer();
 DataInputBuffer in = new DataInputBuffer();
 for (int i = 0; i < NUM_ITERATIONS; i++) {
  // generate a random string
  String before;          
  if (i == 0)
   before = getLongString();
  else
   before = getTestString();
   
  // write it
  out.reset();
  Text.writeString(out, before);
   
  // test that it reads correctly
  in.reset(out.getData(), out.getLength());
  String after = Text.readString(in);
  assertTrue(before.equals(after));
   
  // Test compatibility with Java's other decoder 
  int strLenSize = WritableUtils.getVIntSize(Text.utf8Length(before));
  String after2 = new String(out.getData(), strLenSize, 
                out.getLength()-strLenSize, "UTF-8");
  assertTrue(before.equals(after2));
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

public void testIO() throws Exception {
 DataOutputBuffer out = new DataOutputBuffer();
 DataInputBuffer in = new DataInputBuffer();
 for (int i = 0; i < NUM_ITERATIONS; i++) {
  // generate a random string
  String before;          
  if (i == 0)
   before = getLongString();
  else
   before = getTestString();
   
  // write it
  out.reset();
  Text.writeString(out, before);
   
  // test that it reads correctly
  in.reset(out.getData(), out.getLength());
  String after = Text.readString(in);
  assertTrue(before.equals(after));
   
  // Test compatibility with Java's other decoder 
  int strLenSize = WritableUtils.getVIntSize(Text.utf8Length(before));
  String after2 = new String(out.getData(), strLenSize, 
                out.getLength()-strLenSize, "UTF-8");
  assertTrue(before.equals(after2));
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

public void testIO() throws Exception {
 DataOutputBuffer out = new DataOutputBuffer();
 DataInputBuffer in = new DataInputBuffer();
 for (int i = 0; i < NUM_ITERATIONS; i++) {
  // generate a random string
  String before;          
  if (i == 0)
   before = getLongString();
  else
   before = getTestString();
   
  // write it
  out.reset();
  Text.writeString(out, before);
   
  // test that it reads correctly
  in.reset(out.getData(), out.getLength());
  String after = Text.readString(in);
  assertTrue(before.equals(after));
   
  // Test compatibility with Java's other decoder 
  int strLenSize = WritableUtils.getVIntSize(Text.utf8Length(before));
  String after2 = new String(out.getData(), strLenSize, 
                out.getLength()-strLenSize, "UTF-8");
  assertTrue(before.equals(after2));
 }
}

相关文章