org.apache.hadoop.fs.XAttrCodec.encodeValue()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(115)

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

XAttrCodec.encodeValue介绍

[英]Encode byte[] value to string representation with encoding. Values encoded as text strings are enclosed in double quotes ("), while strings encoded as hexadecimal and base64 are prefixed with 0x and 0s, respectively.
[中]用编码将字节[]值编码为字符串表示形式。编码为文本字符串的值用双引号(\)括起来,而编码为十六进制和base64的字符串则分别以0x和0s作为前缀。

代码示例

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

private void printXAttr(String name, byte[] value) throws IOException{
  if (value != null) {
   if (value.length != 0) {
    out.println(name + "=" + XAttrCodec.encodeValue(value, encoding));
   } else {
    out.println(name);
   }
  }
 }
}

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

private static Map<String, Object> toJsonMap(final XAttr xAttr,
  final XAttrCodec encoding) throws IOException {
 if (xAttr == null) {
  return null;
 }
 final Map<String, Object> m = new TreeMap<String, Object>();
 m.put("name", XAttrHelper.getPrefixedName(xAttr));
 m.put("value", xAttr.getValue() != null ?
   XAttrCodec.encodeValue(xAttr.getValue(), encoding) : null);
 return m;
}

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

private static void appendXAttrsToXml(ContentHandler contentHandler,
  List<XAttr> xAttrs) throws SAXException {
 for (XAttr xAttr: xAttrs) {
  contentHandler.startElement("", "", "XATTR", new AttributesImpl());
  XMLUtils.addSaxString(contentHandler, "NAMESPACE",
    xAttr.getNameSpace().toString());
  XMLUtils.addSaxString(contentHandler, "NAME", xAttr.getName());
  if (xAttr.getValue() != null) {
   try {
    XMLUtils.addSaxString(contentHandler, "VALUE",
      XAttrCodec.encodeValue(xAttr.getValue(), XAttrCodec.HEX));
   } catch (IOException e) {
    throw new SAXException(e);
   }
  }
  contentHandler.endElement("", "", "XATTR");
 }
}

代码示例来源:origin: io.hops/hadoop-common

private void printXAttr(String name, byte[] value) throws IOException{
  if (value != null) {
   if (value.length != 0) {
    out.println(name + "=" + XAttrCodec.encodeValue(value, encoding));
   } else {
    out.println(name);
   }
  }
 }
}

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

private void printXAttr(String name, byte[] value) throws IOException{
  if (value != null) {
   if (value.length != 0) {
    out.println(name + "=" + XAttrCodec.encodeValue(value, encoding));
   } else {
    out.println(name);
   }
  }
 }
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

private void printXAttr(String name, byte[] value) throws IOException{
  if (value != null) {
   if (value.length != 0) {
    out.println(name + "=" + XAttrCodec.encodeValue(value, encoding));
   } else {
    out.println(name);
   }
  }
 }
}

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

private void printXAttr(String name, byte[] value) throws IOException{
  if (value != null) {
   if (value.length != 0) {
    out.println(name + "=" + XAttrCodec.encodeValue(value, encoding));
   } else {
    out.println(name);
   }
  }
 }
}

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

private static Map<String, Object> toJsonMap(final XAttr xAttr,
  final XAttrCodec encoding) throws IOException {
 if (xAttr == null) {
  return null;
 }
 final Map<String, Object> m = new TreeMap<String, Object>();
 m.put("name", XAttrHelper.getPrefixName(xAttr));
 m.put("value", xAttr.getValue() != null ? 
   XAttrCodec.encodeValue(xAttr.getValue(), encoding) : null);
 return m;
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

private static Map<String, Object> toJsonMap(final XAttr xAttr,
  final XAttrCodec encoding) throws IOException {
 if (xAttr == null) {
  return null;
 }
 final Map<String, Object> m = new TreeMap<String, Object>();
 m.put("name", XAttrHelper.getPrefixName(xAttr));
 m.put("value", xAttr.getValue() != null ? 
   XAttrCodec.encodeValue(xAttr.getValue(), encoding) : null);
 return m;
}

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

/**
 * Converts xAttrs to a JSON object.
 *
 * @param xAttrs file xAttrs.
 * @param encoding format of xattr values.
 *
 * @return The JSON representation of the xAttrs.
 * @throws IOException 
 */
@SuppressWarnings({"unchecked", "rawtypes"})
private static Map xAttrsToJSON(Map<String, byte[]> xAttrs, 
  XAttrCodec encoding) throws IOException {
 Map jsonMap = new LinkedHashMap();
 JSONArray jsonArray = new JSONArray();
 if (xAttrs != null) {
  for (Entry<String, byte[]> e : xAttrs.entrySet()) {
   Map json = new LinkedHashMap();
   json.put(HttpFSFileSystem.XATTR_NAME_JSON, e.getKey());
   if (e.getValue() != null) {
    json.put(HttpFSFileSystem.XATTR_VALUE_JSON, 
      XAttrCodec.encodeValue(e.getValue(), encoding));
   }
   jsonArray.add(json);
  }
 }
 jsonMap.put(HttpFSFileSystem.XATTRS_JSON, jsonArray);
 return jsonMap;
}

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

@Override
public void setXAttr(Path f, String name, byte[] value,
  EnumSet<XAttrSetFlag> flag) throws IOException {
 Map<String, String> params = new HashMap<String, String>();
 params.put(OP_PARAM, Operation.SETXATTR.toString());
 params.put(XATTR_NAME_PARAM, name);
 if (value != null) {
  params.put(XATTR_VALUE_PARAM, 
    XAttrCodec.encodeValue(value, XAttrCodec.HEX));
 }
 params.put(XATTR_SET_FLAG_PARAM, EnumSetParam.toString(flag));
 HttpURLConnection conn = getConnection(Operation.SETXATTR.getMethod(),
   params, f, true);
 HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
}

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

private static void appendXAttrsToXml(ContentHandler contentHandler,
  List<XAttr> xAttrs) throws SAXException {
 for (XAttr xAttr: xAttrs) {
  contentHandler.startElement("", "", "XATTR", new AttributesImpl());
  XMLUtils.addSaxString(contentHandler, "NAMESPACE",
    xAttr.getNameSpace().toString());
  XMLUtils.addSaxString(contentHandler, "NAME", xAttr.getName());
  if (xAttr.getValue() != null) {
   try {
    XMLUtils.addSaxString(contentHandler, "VALUE",
      XAttrCodec.encodeValue(xAttr.getValue(), XAttrCodec.HEX));
   } catch (IOException e) {
    throw new SAXException(e);
   }
  }
  contentHandler.endElement("", "", "XATTR");
 }
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

private static void appendXAttrsToXml(ContentHandler contentHandler,
  List<XAttr> xAttrs) throws SAXException {
 for (XAttr xAttr: xAttrs) {
  contentHandler.startElement("", "", "XATTR", new AttributesImpl());
  XMLUtils.addSaxString(contentHandler, "NAMESPACE",
    xAttr.getNameSpace().toString());
  XMLUtils.addSaxString(contentHandler, "NAME", xAttr.getName());
  if (xAttr.getValue() != null) {
   try {
    XMLUtils.addSaxString(contentHandler, "VALUE",
      XAttrCodec.encodeValue(xAttr.getValue(), XAttrCodec.HEX));
   } catch (IOException e) {
    throw new SAXException(e);
   }
  }
  contentHandler.endElement("", "", "XATTR");
 }
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

@Override
public void setXAttr(Path p, String name, byte[] value, 
  EnumSet<XAttrSetFlag> flag) throws IOException {
 statistics.incrementWriteOps(1);
 final HttpOpParam.Op op = PutOpParam.Op.SETXATTR;
 if (value != null) {
  new FsPathRunner(op, p, new XAttrNameParam(name), new XAttrValueParam(
    XAttrCodec.encodeValue(value, XAttrCodec.HEX)), 
    new XAttrSetFlagParam(flag)).run();
 } else {
  new FsPathRunner(op, p, new XAttrNameParam(name), 
    new XAttrSetFlagParam(flag)).run();
 }
}

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

@Override
public void setXAttr(Path p, String name, byte[] value, 
  EnumSet<XAttrSetFlag> flag) throws IOException {
 statistics.incrementWriteOps(1);
 final HttpOpParam.Op op = PutOpParam.Op.SETXATTR;
 if (value != null) {
  new FsPathRunner(op, p, new XAttrNameParam(name), new XAttrValueParam(
    XAttrCodec.encodeValue(value, XAttrCodec.HEX)), 
    new XAttrSetFlagParam(flag)).run();
 } else {
  new FsPathRunner(op, p, new XAttrNameParam(name), 
    new XAttrSetFlagParam(flag)).run();
 }
}

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

@Override
public void setXAttr(Path p, String name, byte[] value,
  EnumSet<XAttrSetFlag> flag) throws IOException {
 statistics.incrementWriteOps(1);
 storageStatistics.incrementOpCounter(OpType.SET_XATTR);
 final HttpOpParam.Op op = PutOpParam.Op.SETXATTR;
 if (value != null) {
  new FsPathRunner(op, p, new XAttrNameParam(name), new XAttrValueParam(
    XAttrCodec.encodeValue(value, XAttrCodec.HEX)),
    new XAttrSetFlagParam(flag)).run();
 } else {
  new FsPathRunner(op, p, new XAttrNameParam(name),
    new XAttrSetFlagParam(flag)).run();
 }
}

相关文章