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

org.apache.hadoop.util.StringUtils.byteToHexString()方法的使用及代码示例

本文整理了Java中org.apache.hadoop.util.StringUtils.byteToHexString()方法的一些代码示例,展示了Str

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

StringUtils.byteToHexString介绍

[英]Convert a byte to a hex string.
[中]将字节转换为十六进制字符串。

代码示例

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

/**
* Given an array of bytes it will convert the bytes to a hex string
* representation of the bytes.
* @param bytes Input bytes
* @param start start index, inclusively
* @param end end index, exclusively
* @return hex string representation of the byte array
*/
public static String byteToHexString(byte[] bytes, int start, int end) {
return org.apache.hadoop.util.StringUtils.byteToHexString(bytes, start, end);
}

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

/**
* Convert a byte to a hex string.
* @see #byteToHexString(byte[])
* @see #byteToHexString(byte[], int, int)
* @param b byte
* @return byte's hex value as a String
*/
public static String byteToHexString(byte b) {
return byteToHexString(new byte[] {b});
}

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

/** Same as byteToHexString(bytes, 0, bytes.length). */
public static String byteToHexString(byte bytes[]) {
return byteToHexString(bytes, 0, bytes.length);
}

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

@Override
public String toString() {
return "elector id=" + System.identityHashCode(this) +
" appData=" +
((appData == null) ? "null" : StringUtils.byteToHexString(appData)) +
" cb=" + appClient;
}

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

/** Check the rpc response header. */
void checkResponse(RpcResponseHeaderProto header) throws IOException {
if (header == null) {
throw new EOFException("Response is null.");
}
if (header.hasClientId()) {
// check client IDs
final byte[] id = header.getClientId().toByteArray();
if (!Arrays.equals(id, RpcConstants.DUMMY_CLIENT_ID)) {
if (!Arrays.equals(id, clientId)) {
throw new IOException("Client IDs not matched: local ID="
+ StringUtils.byteToHexString(clientId) + ", ID in respOnse="
+ StringUtils.byteToHexString(header.getClientId().toByteArray()));
}
}
}
}

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

/**
* Try to delete the "ActiveBreadCrumb" node when gracefully giving up
* active status.
* If this fails, it will simply warn, since the graceful release behavior
* is only an optimization.
*/
private void tryDeleteOwnBreadCrumbNode() {
assert state == State.ACTIVE;
LOG.info("Deleting bread-crumb of active node...");

// Sanity check the data. This shouldn't be strictly necessary,
// but better to play it safe.
Stat stat = new Stat();
byte[] data = null;
try {
data = zkClient.getData(zkBreadCrumbPath, false, stat);
if (!Arrays.equals(data, appData)) {
throw new IllegalStateException(
"We thought we were active, but in fact " +
"the active znode had the wrong data: " +
StringUtils.byteToHexString(data) + " (stat=" + stat + ")");
}

deleteWithRetries(zkBreadCrumbPath, stat.getVersion());
} catch (Exception e) {
LOG.warn("Unable to delete our own bread-crumb of being active at {}." +
". Expecting to be fenced by the next active.", zkBreadCrumbPath, e);
}
}

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

if (i >= nBytes) {
throw new UTFDataFormatException("Truncated UTF8 at " +
StringUtils.byteToHexString(bytes, i - 1, 1));
StringUtils.byteToHexString(bytes, i - 1, 2));
if (i + 2 >= nBytes) {
throw new UTFDataFormatException("Truncated UTF8 at " +
StringUtils.byteToHexString(bytes, i - 1, 3));
StringUtils.byteToHexString(bytes, i - 1, endForError));

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

LOG.info("Old node exists: {}", StringUtils.byteToHexString(data));
if (Arrays.equals(data, appData)) {
LOG.info("But old node has our own data, so don't need to fence it.");

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

@Override
protected void processPath(PathData item) throws IOException {
if (item.stat.isDirectory()) {
throw new PathIsDirectoryException(item.toString());
}
FileChecksum checksum = item.fs.getFileChecksum(item.path);
if (checksum == null) {
out.printf("%s\tNONE\t%n", item.toString());
} else {
String checksumString = StringUtils.byteToHexString(
checksum.getBytes(), 0, checksum.getLength());
out.printf("%s\t%s\t%s%n",
item.toString(), checksum.getAlgorithmName(),
checksumString);
}
}
}

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

private static void addInsertNonDirectoryInformation(Path p, FileSystem fileSystem,
InsertEventRequestData insertData) throws IOException {
insertData.addToFilesAdded(p.toString());
FileChecksum cksum = fileSystem.getFileChecksum(p);
String acidDirPath = AcidUtils.getFirstLevelAcidDirPath(p.getParent(), fileSystem);
// File checksum is not implemented for local filesystem (RawLocalFileSystem)
if (cksum != null) {
String checksumString =
StringUtils.byteToHexString(cksum.getBytes(), 0, cksum.getLength());
insertData.addToFilesAddedChecksum(checksumString);
} else {
// Add an empty checksum string for filesystems that don't generate one
insertData.addToFilesAddedChecksum("");
}
// acid dir will be present only for acid write operations.
if (acidDirPath != null) {
insertData.addToSubDirectoryList(acidDirPath);
}
}

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

} catch (ChecksumException ce) {
LOG.info("Found checksum error: b[" + off + ", " + (off+read) + "]="
+ StringUtils.byteToHexString(b, off, off + read), ce);
if (retriesLeft == 0) {
throw ce;

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

StringUtils.byteToHexString(cksum.getBytes(), 0, cksum.getLength());
insertData.addToFilesAddedChecksum(checksumString);
} else {

代码示例来源:origin: KylinOLAP/Kylin

@Override
protected void cleanup(Context context) throws IOException, InterruptedException {
int nRegion = Math.round((float) gbPoints.size() / (float) cut);
nRegion = Math.max(1, nRegion);
nRegion = Math.min(MAX_REGION, nRegion);

int gbPerRegion = gbPoints.size() / nRegion;
gbPerRegion = Math.max(1, gbPerRegion);

System.out.println(nRegion + " regions");
System.out.println(gbPerRegion + " GB per region");

for (int i = gbPerRegion; i Text key = gbPoints.get(i);
outputValue.set(i);
System.out.println(StringUtils.byteToHexString(key.getBytes()) + "\t" + outputValue.get());
context.write(key, outputValue);
}
}
}

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

/** Convert a MD5MD5CRC32FileChecksum to a Json string. */
public static String toJsonString(final MD5MD5CRC32FileChecksum checksum) {
if (checksum == null) {
return null;
}
final Map m = new TreeMap();
m.put("algorithm", checksum.getAlgorithmName());
m.put("length", checksum.getLength());
m.put("bytes", StringUtils.byteToHexString(checksum.getBytes()));
return toJsonString(FileChecksum.class, m);
}

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

/**
* Save the ".md5" file that lists the md5sum of another file.
* @param dataFile the original file whose md5 was computed
* @param digest the computed digest
* @throws IOException
*/
public static void saveMD5File(File dataFile, MD5Hash digest)
throws IOException {
final String digestString = StringUtils.byteToHexString(digest.getDigest());
saveMD5File(dataFile, digestString);
}

代码示例来源:origin: KylinOLAP/Kylin

@SuppressWarnings("deprecation")
public byte[][] getSplits(Configuration conf, Path path) throws Exception {
FileSystem fs = path.getFileSystem(conf);
if (fs.exists(path) == false) {
System.err.println("Path " + path + " not found, no region split, HTable will be one region");
return null;
}
List rowkeyList = new ArrayList();
SequenceFile.Reader reader = null;
try {
reader = new SequenceFile.Reader(fs, path, conf);
Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), conf);
Writable value = (Writable) ReflectionUtils.newInstance(reader.getValueClass(), conf);
while (reader.next(key, value)) {
rowkeyList.add(((Text) key).copyBytes());
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
IOUtils.closeStream(reader);
}
logger.info((rowkeyList.size() + 1) + " regions");
logger.info(rowkeyList.size() + " splits");
for (byte[] split : rowkeyList) {
System.out.println(StringUtils.byteToHexString(split));
}
byte[][] retValue = rowkeyList.toArray(new byte[rowkeyList.size()][]);
return retValue.length == 0 ? null : retValue;
}

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

@Override
protected HAServiceTarget dataToTarget(byte[] data) {
ActiveNodeInfo proto;
try {
proto = ActiveNodeInfo.parseFrom(data);
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException("Invalid data in ZK: " +
StringUtils.byteToHexString(data));
}
NNHAServiceTarget ret = new NNHAServiceTarget(
conf, proto.getNameserviceId(), proto.getNamenodeId());
InetSocketAddress addressFromProtobuf = new InetSocketAddress(
proto.getHostname(), proto.getPort());

if (!addressFromProtobuf.equals(ret.getAddress())) {
throw new RuntimeException("Mismatched address stored in ZK for " +
ret + ": Stored protobuf was " + proto + ", address from our own " +
"configuration for this NameNode was " + ret.getAddress());
}

ret.setZkfcPort(proto.getZkfcPort());
return ret;
}

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

try {
if (LOG.isTraceEnabled()) {
LOG.trace("data:" + StringUtils.byteToHexString(data));

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

public short getPreferredBlockReplication() {
short max = getFileReplication(CURRENT_STATE_ID);
FileWithSnapshotFeature sf = this.getFileWithSnapshotFeature();
if (sf != null) {
short maxInSnapshot = sf.getMaxBlockRepInDiffs(null);
if (sf.isCurrentFileDeleted()) {
return maxInSnapshot;
}
max = maxInSnapshot > max ? maxInSnapshot : max;
}
if(!isStriped()){
return max;
}
ErasureCodingPolicy ecPolicy = ErasureCodingPolicyManager.getInstance()
.getByID(getErasureCodingPolicyID());
Preconditions.checkNotNull(ecPolicy, "Could not find EC policy with ID 0x"
+ StringUtils.byteToHexString(getErasureCodingPolicyID()));
return (short) (ecPolicy.getNumDataUnits() + ecPolicy.getNumParityUnits());
}

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

static private void checkData(byte[] actual, int from, byte[] expected, int len,
String message) {
for (int idx = 0; idx if (expected[from + idx] != actual[idx]) {
Assert.fail(message + " byte " + (from + idx) + " differs. expected "
+ expected[from + idx] + " actual " + actual[idx] +
"\nexpected: " + StringUtils.byteToHexString(expected, from, from + len) +
"\nactual: " + StringUtils.byteToHexString(actual, 0, len));
}
}
}

推荐阅读
author-avatar
huineisuan111184
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有