热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

本文整理了Java中org.apache.hadoop.io.Text.getLength()方法的一些代码示例,展示了Text.getLength()

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

Text.getLength介绍

[英]Returns the number of bytes in the byte array
[中]返回字节数组中的字节数

代码示例

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

/** copy a text. */
public void set(Text other) {
set(other.getBytes(), 0, other.getLength());
}

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

/**
* Convert a string to Text format and write its bytes in the same way TextOutputFormat would do.
* This is needed to properly encode non-ascii characters.
*/
private static void writeAsText(String text, FSDataOutputStream out) throws IOException {
Text to = new Text(text);
out.write(to.getBytes(), 0, to.getLength());
}

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

private static boolean find(Text s, Text sub, int startS, int endS) {
byte[] byteS = s.getBytes();
byte[] byteSub = sub.getBytes();
int lenSub = sub.getLength();
boolean match = false;
for (int i = startS; (i match = true;
for (int j = 0; j if (byteS[j + i] != byteSub[j]) {
match = false;
break;
}
}
}
return match;
}

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

public static Text transformTextToUTF8(Text text, Charset previousCharset) {
return new Text(new String(text.getBytes(), 0, text.getLength(), previousCharset));
}

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

public BytesWritable evaluate(Text value){
if (value == null) {
return null;
}
byte[] bytes = new byte[value.getLength()];
System.arraycopy(value.getBytes(), 0, bytes, 0, value.getLength());
byte[] decoded = Base64.decodeBase64(bytes);
result.set(decoded, 0, decoded.length);
return result;
}
}

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

public static Text transformTextFromUTF8(Text text, Charset targetCharset) {
return new Text(new String(text.getBytes(), 0, text.getLength()).getBytes(targetCharset));
}

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

public Text evaluate(Text s, IntWritable n) {
if (n == null || s == null) {
return null;
}
int len = n.get() * s.getLength();
if (len <0) {
len = 0;
}
byte[] data = result.getBytes();
if (data.length data = new byte[len];
}
for (int i = 0; i for (int j = 0; j data[i + j] = s.getBytes()[j];
}
}
result.set(data, 0, len);
return result;
}
}

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

/**
* Write a String as a VInt n, followed by n Bytes as in Text format.
*
* @param out
* @param s
* @throws IOException
*/
public static void writeString(DataOutput out, String s) throws IOException {
if (s != null) {
Text text = new Text(s);
byte[] buffer = text.getBytes();
int len = text.getLength();
writeVInt(out, len);
out.write(buffer, 0, len);
} else {
writeVInt(out, -1);
}
}

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

/**
* Convert String to SHA-1
*/
public Text evaluate(Text n) {
if (n == null) {
return null;
}
digest.reset();
digest.update(n.getBytes(), 0, n.getLength());
byte[] shaBytes = digest.digest();
String shaHex = Hex.encodeHexString(shaBytes);
result.set(shaHex);
return result;
}

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

private void testWriterText(TypeInfo type) throws HiveException {
Text t1 = new Text("alpha");
Text t2 = new Text("beta");
BytesColumnVector bcv = new BytesColumnVector(vectorSize);
bcv.nOnulls= false;
bcv.initBuffer();
bcv.setVal(0, t1.getBytes(), 0, t1.getLength());
bcv.isNull[1] = true;
bcv.setVal(2, t2.getBytes(), 0, t2.getLength());
bcv.isNull[3] = true;
bcv.setVal(4, t1.getBytes(), 0, t1.getLength());
VectorExpressionWriter vew = getWriter(type);
for (int i = 0; i Writable w = (Writable) vew.writeValue(bcv, i);
if (w != null) {
byte [] val = new byte[bcv.length[i]];
System.arraycopy(bcv.vector[i], bcv.start[i], val, 0, bcv.length[i]);
Writable expected = getWritableValue(type, val);
Assert.assertEquals(expected, w);
} else {
Assert.assertTrue(bcv.isNull[i]);
}
}
}

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

/**
* Convert String to md5
*/
public Text evaluate(Text n) {
if (n == null) {
return null;
}
digest.reset();
digest.update(n.getBytes(), 0, n.getLength());
byte[] md5Bytes = digest.digest();
String md5Hex = Hex.encodeHexString(md5Bytes);
result.set(md5Hex);
return result;
}

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

private void testSetterText(TypeInfo type) throws HiveException {
Text t1 = new Text("alpha");
Text t2 = new Text("beta");
BytesColumnVector bcv = new BytesColumnVector(vectorSize);
bcv.nOnulls= false;
bcv.initBuffer();
bcv.setVal(0, t1.getBytes(), 0, t1.getLength());
bcv.isNull[1] = true;
bcv.setVal(2, t2.getBytes(), 0, t2.getLength());
bcv.isNull[3] = true;
bcv.setVal(4, t1.getBytes(), 0, t1.getLength());

Object[] values = new Object[this.vectorSize];
VectorExpressionWriter vew = getWriter(type);
for (int i = 0; i values[i] = null; // setValue() should be able to handle null input
Writable w = (Writable) vew.setValue(values[i], bcv, i);
if (w != null) {
byte [] val = new byte[bcv.length[i]];
System.arraycopy(bcv.vector[i], bcv.start[i], val, 0, bcv.length[i]);
Writable expected = getWritableValue(type, val);
Assert.assertEquals(expected, w);
} else {
Assert.assertTrue(bcv.isNull[i]);
}
}
}

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

private static boolean find(Text s, Text sub, int startS, int endS) {
byte[] byteS = s.getBytes();
byte[] byteSub = sub.getBytes();
int lenSub = sub.getLength();
boolean match = false;
for (int i = startS; (i match = true;
for (int j = 0; j if (byteS[j + i] != byteSub[j]) {
match = false;
break;
}
}
}
return match;
}

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

@Test
public void testBasic() throws Exception {
Configuration hcOnf= HadoopUtil.getCurrentConfiguration();
Context cOntext= MockupMapContext.create(hconf, cubeName, outKV);
CubeHFileMapper mapper = new CubeHFileMapper();
mapper.doSetup(context);
Text key = new Text("not important");
Text value = new Text(new byte[] { 2, 2, 51, -79, 1 });
mapper.map(key, value, context);
KeyValue outValue = (KeyValue) outKV[1];
assertTrue(Bytes.compareTo(value.getBytes(), 0, value.getLength(), outValue.getValueArray(), outValue.getValueOffset(), outValue.getValueLength()) == 0);
}

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

public static BytesWritable getBinaryFromText(Text text) {
BytesWritable bw = new BytesWritable();
bw.set(text.getBytes(), 0, text.getLength());
return bw;
}

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

@Override public byte[] getBytes(Text writable) {
//@TODO There is no reason to decode then encode the string to bytes really
//@FIXME this issue with CTRL-CHAR ^0 added by Text at the end of string and Json serd does not like that.
try {
return Text.decode(writable.getBytes(), 0, writable.getLength()).getBytes(Charset.forName("UTF-8"));
} catch (CharacterCodingException e) {
throw new RuntimeException(e);
}
}

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

public static int getTextUtfLength(Text t) {
byte[] data = t.getBytes();
int len = 0;
for (int i = 0; i if (isUtfStartByte(data[i])) {
len++;
}
}
return len;
}

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

/**
* CRC32 for string
*/
public LongWritable evaluate(Text n) {
if (n == null) {
return null;
}
crc32.reset();
crc32.update(n.getBytes(), 0, n.getLength());
result.set(crc32.getValue());
return result;
}

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

public void internalWriteString(String str) throws TException {
if (str != null) {
tmpText.set(str);
trans_.write(tmpText.getBytes(), 0, tmpText.getLength());
} else {
trans_.write(nullText.getBytes(), 0, nullText.getLength());
}
}

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

/**
* Convert every character in s to two hex digits.
*
*/
public Text evaluate(Text s) {
if (s == null) {
return null;
}
byte[] str = s.getBytes();
return evaluate(str, s.getLength());
}

推荐阅读
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • PHP图片截取方法及应用实例
    本文介绍了使用PHP动态切割JPEG图片的方法,并提供了应用实例,包括截取视频图、提取文章内容中的图片地址、裁切图片等问题。详细介绍了相关的PHP函数和参数的使用,以及图片切割的具体步骤。同时,还提供了一些注意事项和优化建议。通过本文的学习,读者可以掌握PHP图片截取的技巧,实现自己的需求。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • 标题: ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • 本文详细介绍了如何使用MySQL来显示SQL语句的执行时间,并通过MySQL Query Profiler获取CPU和内存使用量以及系统锁和表锁的时间。同时介绍了效能分析的三种方法:瓶颈分析、工作负载分析和基于比率的分析。 ... [详细]
  • 本文介绍了深入浅出Linux设备驱动编程的重要性,以及两种加载和删除Linux内核模块的方法。通过一个内核模块的例子,展示了模块的编译和加载过程,并讨论了模块对内核大小的控制。深入理解Linux设备驱动编程对于开发者来说非常重要。 ... [详细]
  • 本文介绍了在处理不规则数据时如何使用Python自动提取文本中的时间日期,包括使用dateutil.parser模块统一日期字符串格式和使用datefinder模块提取日期。同时,还介绍了一段使用正则表达式的代码,可以支持中文日期和一些特殊的时间识别,例如'2012年12月12日'、'3小时前'、'在2012/12/13哈哈'等。 ... [详细]
  • 本文介绍了Swing组件的用法,重点讲解了图标接口的定义和创建方法。图标接口用来将图标与各种组件相关联,可以是简单的绘画或使用磁盘上的GIF格式图像。文章详细介绍了图标接口的属性和绘制方法,并给出了一个菱形图标的实现示例。该示例可以配置图标的尺寸、颜色和填充状态。 ... [详细]
  • 纠正网上的错误:自定义一个类叫java.lang.System/String的方法
    本文纠正了网上关于自定义一个类叫java.lang.System/String的错误答案,并详细解释了为什么这种方法是错误的。作者指出,虽然双亲委托机制确实可以阻止自定义的System类被加载,但通过自定义一个特殊的类加载器,可以绕过双亲委托机制,达到自定义System类的目的。作者呼吁读者对网上的内容持怀疑态度,并带着问题来阅读文章。 ... [详细]
author-avatar
手机用户2502873837
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有