@Test public void reverse() throws IOException { ValueFilterHexDump filter = Configs.decodeObject(ValueFilterHexDump.class, "reverse: true"); for (Map.Entry<String, String> entry : PANGRAMS.entrySet()) { assertEquals(entry.getKey(), filter.filter(entry.getValue())); } }
@Override public String filter(String value) { if (reverse) { value = SPACE_SEP.matcher(value).replaceAll(""); byte[] bytes = DatatypeConverter.parseHexBinary(value); return new String(bytes, charset); } else { StringBuilder sb = new StringBuilder(); byte[] bytes = value.getBytes(charset); for (int i = 0; i < bytes.length; i++) { if (i > 0) { sb.append(' '); } sb.append(String.format("%02x", bytes[i])); } return sb.toString(); } }
ValueFilterHexDump extends StringFilter { @Override public String filter(String value) { if (reverse) { value = SPACE_SEP.matcher(value).replaceAll(""); byte[] bytes = DatatypeConverter.parseHexBinary(value); return new String(bytes, charset); } else { StringBuilder sb = new StringBuilder(); byte[] bytes = value.getBytes(charset); for (int i = 0; i < bytes.length; i++) { if (i > 0) { sb.append(' '); } sb.append(String.format("%02x", bytes[i])); } return sb.toString(); } } }
ValueFilterHexDump extends StringFilter { @Override public String filter(String value) { if (reverse) { value = SPACE_SEP.matcher(value).replaceAll(""); byte[] bytes = DatatypeConverter.parseHexBinary(value); return new String(bytes, charset); } else { StringBuilder sb = new StringBuilder(); byte[] bytes = value.getBytes(charset); for (int i = 0; i < bytes.length; i++) { if (i > 0) { sb.append(' '); } sb.append(String.format("%02x", bytes[i])); } return sb.toString(); } } @JsonCreator  ValueFilterHexDump(@JsonProperty(value = "charset", required = true) Charset charset,
                              @JsonProperty(value = "reverse", required = true) boolean reverse); }
ValueFilterHexDump extends StringFilter { @Override public String filter(String value) { if (reverse) { value = SPACE_SEP.matcher(value).replaceAll(""); byte[] bytes = DatatypeConverter.parseHexBinary(value); return new String(bytes, charset); } else { StringBuilder sb = new StringBuilder(); byte[] bytes = value.getBytes(charset); for (int i = 0; i < bytes.length; i++) { if (i > 0) { sb.append(' '); } sb.append(String.format("%02x", bytes[i])); } return sb.toString(); } } @JsonCreator  ValueFilterHexDump(@JsonProperty(value = "charset", required = true) Charset charset,
                              @JsonProperty(value = "reverse", required = true) boolean reverse); @Override String filter(String value); }
ValueFilterHexDump extends StringFilter { @Override public String filter(String value) { if (reverse) { value = SPACE_SEP.matcher(value).replaceAll(""); byte[] bytes = DatatypeConverter.parseHexBinary(value); return new String(bytes, charset); } else { StringBuilder sb = new StringBuilder(); byte[] bytes = value.getBytes(charset); for (int i = 0; i < bytes.length; i++) { if (i > 0) { sb.append(' '); } sb.append(String.format("%02x", bytes[i])); } return sb.toString(); } } @JsonCreator  ValueFilterHexDump(@JsonProperty(value = "charset", required = true) Charset charset,
                              @JsonProperty(value = "reverse", required = true) boolean reverse); @Override String filter(String value);  }