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

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

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

XAttrCodec.decodeValue介绍

[英]Decode string representation of a value and check whether it's encoded. If the given string begins with 0x or 0X, it expresses a hexadecimal number. If the given string begins with 0s or 0S, base64 encoding is expected. If the given string is enclosed in double quotes, the inner string is treated as text. Otherwise the given string is treated as text.
[中]解码值的字符串表示形式,并检查其是否已编码。如果给定字符串以0x或0x开头,则表示十六进制数。如果给定字符串以0或0开头,则应使用base64编码。如果给定字符串用双引号括起来,则内部字符串将被视为文本。否则,给定的字符串将被视为文本。

代码示例

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

@Override
protected void processOptions(LinkedList<String> args) throws IOException {
 name = StringUtils.popOptionWithArgument("-n", args);
 String v = StringUtils.popOptionWithArgument("-v", args);
 if (v != null) {
  value = XAttrCodec.decodeValue(v);
 }
 xname = StringUtils.popOptionWithArgument("-x", args);
 if (name != null && xname != null) {
  throw new HadoopIllegalArgumentException(
    "Can not specify both '-n name' and '-x name' option.");
 }
 if (name == null && xname == null) {
  throw new HadoopIllegalArgumentException(
    "Must specify '-n name' or '-x name' option.");
 }
 if (args.isEmpty()) {
  throw new HadoopIllegalArgumentException("<path> is missing.");
 }
 if (args.size() > 1) {
  throw new HadoopIllegalArgumentException("Too many arguments.");
 }
}

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

private static List<XAttr> readXAttrsFromXml(Stanza st)
   throws InvalidXmlException {
  if (!st.hasChildren("XATTR")) {
   return null;
  }

  List<Stanza> stanzas = st.getChildren("XATTR");
  List<XAttr> xattrs = Lists.newArrayListWithCapacity(stanzas.size());
  for (Stanza a: stanzas) {
   XAttr.Builder builder = new XAttr.Builder();
   builder.setNameSpace(XAttr.NameSpace.valueOf(a.getValue("NAMESPACE"))).
     setName(a.getValue("NAME"));
   String v = a.getValueOrNull("VALUE");
   if (v != null) {
    try {
     builder.setValue(XAttrCodec.decodeValue(v));
    } catch (IOException e) {
     throw new InvalidXmlException(e.toString());
    }
   }
   xattrs.add(builder.build());
  }
  return xattrs;
 }
}

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

static byte[] decodeXAttrValue(String value) throws IOException {
 if (value != null) {
  return XAttrCodec.decodeValue(value);
 } else {
  return new byte[0];
 }
}

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

private static byte[] decodeXAttrValue(String value) throws IOException {
  if (value != null) {
   return XAttrCodec.decodeValue(value);
  } else {
   return new byte[0];
  }
 }
}

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

private static byte[] decodeXAttrValue(String value) throws IOException {
  if (value != null) {
   return XAttrCodec.decodeValue(value);
  } else {
   return new byte[0];
  }
 }
}

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

public FSSetXAttr(String path, String name, String encodedValue, 
  EnumSet<XAttrSetFlag> flag) throws IOException {
 this.path = new Path(path);
 this.name = name;
 this.value = XAttrCodec.decodeValue(encodedValue);
 this.flag = flag;
}

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

/** Convert xAttrs json to xAttrs map */
private Map<String, byte[]> createXAttrMap(JSONArray jsonArray) 
  throws IOException {
 Map<String, byte[]> xAttrs = Maps.newHashMap();
 for (Object obj : jsonArray) {
  JSONObject jsonObj = (JSONObject) obj;
  final String name = (String)jsonObj.get(XATTR_NAME_JSON);
  final byte[] value = XAttrCodec.decodeValue(
    (String)jsonObj.get(XATTR_VALUE_JSON));
  xAttrs.put(name, value);
 }
 return xAttrs;
}

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

public byte[] getXAttrValue() throws IOException {
  final String v = getValue();
  return XAttrCodec.decodeValue(v);
 }
}

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

public byte[] getXAttrValue() throws IOException {
  final String v = getValue();
  return XAttrCodec.decodeValue(v);
 }
}

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

public byte[] getXAttrValue() throws IOException {
  final String v = getValue();
  return XAttrCodec.decodeValue(v);
 }
}

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

@Override
protected void processOptions(LinkedList<String> args) throws IOException {
 name = StringUtils.popOptionWithArgument("-n", args);
 String v = StringUtils.popOptionWithArgument("-v", args);
 if (v != null) {
  value = XAttrCodec.decodeValue(v);
 }
 xname = StringUtils.popOptionWithArgument("-x", args);
 if (name != null && xname != null) {
  throw new HadoopIllegalArgumentException(
    "Can not specify both '-n name' and '-x name' option.");
 }
 if (name == null && xname == null) {
  throw new HadoopIllegalArgumentException(
    "Must specify '-n name' or '-x name' option.");
 }
 if (args.isEmpty()) {
  throw new HadoopIllegalArgumentException("<path> is missing.");
 }
 if (args.size() > 1) {
  throw new HadoopIllegalArgumentException("Too many arguments.");
 }
}

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

@Override
protected void processOptions(LinkedList<String> args) throws IOException {
 name = StringUtils.popOptionWithArgument("-n", args);
 String v = StringUtils.popOptionWithArgument("-v", args);
 if (v != null) {
  value = XAttrCodec.decodeValue(v);
 }
 xname = StringUtils.popOptionWithArgument("-x", args);
 if (name != null && xname != null) {
  throw new HadoopIllegalArgumentException(
    "Can not specify both '-n name' and '-x name' option.");
 }
 if (name == null && xname == null) {
  throw new HadoopIllegalArgumentException(
    "Must specify '-n name' or '-x name' option.");
 }
 if (args.isEmpty()) {
  throw new HadoopIllegalArgumentException("<path> is missing.");
 }
 if (args.size() > 1) {
  throw new HadoopIllegalArgumentException("Too many arguments.");
 }
}

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

@Override
protected void processOptions(LinkedList<String> args) throws IOException {
 name = StringUtils.popOptionWithArgument("-n", args);
 String v = StringUtils.popOptionWithArgument("-v", args);
 if (v != null) {
  value = XAttrCodec.decodeValue(v);
 }
 xname = StringUtils.popOptionWithArgument("-x", args);
 if (name != null && xname != null) {
  throw new HadoopIllegalArgumentException(
    "Can not specify both '-n name' and '-x name' option.");
 }
 if (name == null && xname == null) {
  throw new HadoopIllegalArgumentException(
    "Must specify '-n name' or '-x name' option.");
 }
 if (args.isEmpty()) {
  throw new HadoopIllegalArgumentException("<path> is missing.");
 }
 if (args.size() > 1) {
  throw new HadoopIllegalArgumentException("Too many arguments.");
 }
}

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

@Override
protected void processOptions(LinkedList<String> args) throws IOException {
 name = StringUtils.popOptionWithArgument("-n", args);
 String v = StringUtils.popOptionWithArgument("-v", args);
 if (v != null) {
  value = XAttrCodec.decodeValue(v);
 }
 xname = StringUtils.popOptionWithArgument("-x", args);
 if (name != null && xname != null) {
  throw new HadoopIllegalArgumentException(
    "Can not specify both '-n name' and '-x name' option.");
 }
 if (name == null && xname == null) {
  throw new HadoopIllegalArgumentException(
    "Must specify '-n name' or '-x name' option.");
 }
 if (args.isEmpty()) {
  throw new HadoopIllegalArgumentException("<path> is missing.");
 }
 if (args.size() > 1) {
  throw new HadoopIllegalArgumentException("Too many arguments.");
 }
}

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

private static List<XAttr> readXAttrsFromXml(Stanza st)
   throws InvalidXmlException {
  if (!st.hasChildren("XATTR")) {
   return null;
  }

  List<Stanza> stanzas = st.getChildren("XATTR");
  List<XAttr> xattrs = Lists.newArrayListWithCapacity(stanzas.size());
  for (Stanza a: stanzas) {
   XAttr.Builder builder = new XAttr.Builder();
   builder.setNameSpace(XAttr.NameSpace.valueOf(a.getValue("NAMESPACE"))).
     setName(a.getValue("NAME"));
   String v = a.getValueOrNull("VALUE");
   if (v != null) {
    try {
     builder.setValue(XAttrCodec.decodeValue(v));
    } catch (IOException e) {
     throw new InvalidXmlException(e.toString());
    }
   }
   xattrs.add(builder.build());
  }
  return xattrs;
 }
}

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

private static List<XAttr> readXAttrsFromXml(Stanza st)
   throws InvalidXmlException {
  if (!st.hasChildren("XATTR")) {
   return null;
  }

  List<Stanza> stanzas = st.getChildren("XATTR");
  List<XAttr> xattrs = Lists.newArrayListWithCapacity(stanzas.size());
  for (Stanza a: stanzas) {
   XAttr.Builder builder = new XAttr.Builder();
   builder.setNameSpace(XAttr.NameSpace.valueOf(a.getValue("NAMESPACE"))).
     setName(a.getValue("NAME"));
   String v = a.getValueOrNull("VALUE");
   if (v != null) {
    try {
     builder.setValue(XAttrCodec.decodeValue(v));
    } catch (IOException e) {
     throw new InvalidXmlException(e.toString());
    }
   }
   xattrs.add(builder.build());
  }
  return xattrs;
 }
}

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

@Test
public void testGetXAttrFromJson() throws IOException {
 String jsonString = 
   "{\"XAttrs\":[{\"name\":\"user.a1\",\"value\":\"0x313233\"}," +
   "{\"name\":\"user.a2\",\"value\":\"0x313131\"}]}";
 ObjectReader reader = new ObjectMapper().reader(Map.class);
 Map<?, ?> json = reader.readValue(jsonString);
 // Get xattr: user.a2
 byte[] value = JsonUtil.getXAttr(json, "user.a2");
 Assert.assertArrayEquals(XAttrCodec.decodeValue("0x313131"), value);
}

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

@Test
public void testXAttrValueParam() throws IOException {
 final XAttrValueParam p = new XAttrValueParam("0x313233");
 Assert.assertArrayEquals(p.getXAttrValue(), 
   XAttrCodec.decodeValue("0x313233"));
}

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

@Test
public void testToXAttrMap() throws IOException {
 String jsonString = 
   "{\"XAttrs\":[{\"name\":\"user.a1\",\"value\":\"0x313233\"}," +
   "{\"name\":\"user.a2\",\"value\":\"0x313131\"}]}";
 ObjectReader reader = new ObjectMapper().reader(Map.class);
 Map<?, ?> json = reader.readValue(jsonString);
 XAttr xAttr1 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER).
   setName("a1").setValue(XAttrCodec.decodeValue("0x313233")).build();
 XAttr xAttr2 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER).
   setName("a2").setValue(XAttrCodec.decodeValue("0x313131")).build();
 List<XAttr> xAttrs = Lists.newArrayList();
 xAttrs.add(xAttr1);
 xAttrs.add(xAttr2);
 Map<String, byte[]> xAttrMap = XAttrHelper.buildXAttrMap(xAttrs);
 Map<String, byte[]> parsedXAttrMap = JsonUtil.toXAttrs(json);
 
 Assert.assertEquals(xAttrMap.size(), parsedXAttrMap.size());
 Iterator<Entry<String, byte[]>> iter = xAttrMap.entrySet().iterator();
 while(iter.hasNext()) {
  Entry<String, byte[]> entry = iter.next();
  Assert.assertArrayEquals(entry.getValue(), 
    parsedXAttrMap.get(entry.getKey()));
 }
}

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

@Test
public void testToJsonFromXAttrs() throws IOException {
 String jsonString = 
   "{\"XAttrs\":[{\"name\":\"user.a1\",\"value\":\"0x313233\"}," +
   "{\"name\":\"user.a2\",\"value\":\"0x313131\"}]}";
 XAttr xAttr1 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER).
   setName("a1").setValue(XAttrCodec.decodeValue("0x313233")).build();
 XAttr xAttr2 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER).
   setName("a2").setValue(XAttrCodec.decodeValue("0x313131")).build();
 List<XAttr> xAttrs = Lists.newArrayList();
 xAttrs.add(xAttr1);
 xAttrs.add(xAttr2);
 
 Assert.assertEquals(jsonString, JsonUtil.toJsonString(xAttrs, 
   XAttrCodec.HEX));
}

相关文章