本文整理汇总了Java中org.apache.hadoop.util.UTF8ByteArrayUtils类的典型用法代码示例。如果您正苦于以下问题:Java UTF8ByteArrayUtils类的具体用法?Java UTF8ByteArrayUtils怎么用?Java UTF8ByteArrayUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UTF8ByteArrayUtils类属于org.apache.hadoop.util包,在下文中一共展示了UTF8ByteArrayUtils类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: splitKeyVal
import org.apache.hadoop.util.UTF8ByteArrayUtils; //导入依赖的package包/类
private void splitKeyVal(byte[] line, int length, Text key, Text val)
throws IOException {
// Need to find numKeyFields separators
int pos = UTF8ByteArrayUtils.findBytes(line, 0, length, separator);
for(int k=1; k<numKeyFields && pos!=-1; k++) {
pos = UTF8ByteArrayUtils.findBytes(line, pos + separator.length,
length, separator);
}
try {
if (pos == -1) {
key.set(line, 0, length);
val.set("");
} else {
StreamKeyValUtil.splitKeyVal(line, 0, length, key, val, pos,
separator.length);
}
} catch (CharacterCodingException e) {
throw new IOException(StringUtils.stringifyException(e));
}
}
示例2: splitKeyVal
import org.apache.hadoop.util.UTF8ByteArrayUtils; //导入依赖的package包/类
/**
* Split a line into key and value.
* @param line: a byte array of line containing UTF-8 bytes
* @param key: key of a record
* @param val: value of a record
* @throws IOException
*/
void splitKeyVal(byte[] line, int length, Text key, Text val)
throws IOException {
int numKeyFields = getNumOfKeyFields();
byte[] separator = getFieldSeparator();
// Need to find numKeyFields separators
int pos = UTF8ByteArrayUtils.findBytes(line, 0, length, separator);
for(int k=1; k<numKeyFields && pos!=-1; k++) {
pos = UTF8ByteArrayUtils.findBytes(line, pos + separator.length,
length, separator);
}
try {
if (pos == -1) {
key.set(line, 0, length);
val.set("");
} else {
StreamKeyValUtil.splitKeyVal(line, 0, length, key, val, pos, separator.length);
}
} catch (CharacterCodingException e) {
LOG.warn(StringUtils.stringifyException(e));
}
}
示例3: getWordLengths
import org.apache.hadoop.util.UTF8ByteArrayUtils; //导入依赖的package包/类
public int[] getWordLengths(byte []b, int start, int end) {
//Given a string like "hello how are you", it returns an array
//like [4 5, 3, 3, 3], where the first element is the number of
//fields
if (!keySpecSeen) {
//if there were no key specs, then the whole key is one word
return new int[] {1};
}
int[] lengths = new int[10];
int currLenLengths = lengths.length;
int idx = 1;
int pos;
while ((pos = UTF8ByteArrayUtils.findBytes(b, start, end,
keyFieldSeparator)) != -1) {
if (++idx == currLenLengths) {
int[] temp = lengths;
lengths = new int[(currLenLengths = currLenLengths*2)];
System.arraycopy(temp, 0, lengths, 0, temp.length);
}
lengths[idx - 1] = pos - start;
start = pos + 1;
}
if (start != end) {
lengths[idx] = end - start;
}
lengths[0] = idx; //number of words is the first element
return lengths;
}