热门标签 | 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());
}

推荐阅读
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社区 版权所有