/** * Returns the HTTP body content as a simple space-delimited hexadecimal character string. * * <h5 class='section'>Example:</h5> * <p class='bcode w800'> * 01 23 45 67 89 AB CD EF * </p> * * @return The incoming input from the connection as a plain string. * @throws IOException If a problem occurred trying to read from the reader. */ public String asSpacedHex() throws IOException { if (body == null) body = readBytes(getInputStream(), 1024); return toSpacedHex(body); }
/** * Returns the HTTP body content as a simple space-delimited hexadecimal character string. * * <h5 class='section'>Example:</h5> * <p class='bcode w800'> * 01 23 45 67 89 AB CD EF * </p> * * @return The incoming input from the connection as a plain string. * @throws IOException If a problem occurred trying to read from the reader. */ public String asSpacedHex() throws IOException { if (body == null) body = readBytes(getInputStream(), 1024); return toSpacedHex(body); }
@Override /* SerializerSession */ public final String serializeToString(Object o) throws SerializeException { byte[] b = serialize(o); switch(getBinaryFormat()) { case SPACED_HEX: return StringUtils.toSpacedHex(b); case HEX: return isUseWhitespace() ? StringUtils.toSpacedHex(b) : StringUtils.toHex(b); case BASE64: return StringUtils.base64Encode(b); default: return null; } }
/** * Returns the HTTP body content as a simple space-delimited hexadecimal character string. * * <h5 class='section'>Example:</h5> * <p class='bcode w800'> * 01 23 45 67 89 AB CD EF * </p> * * @return The incoming input from the connection as a plain string. * @throws IOException If a problem occurred trying to read from the reader. */ public String asSpacedHex() throws IOException { if (body == null) body = readBytes(getInputStream(), 1024); return toSpacedHex(body); }
@Override /* SerializerSession */ public final String serializeToString(Object o) throws SerializeException { byte[] b = serialize(o); switch(getBinaryFormat()) { case SPACED_HEX: return StringUtils.toSpacedHex(b); case HEX: return isUseWhitespace() ? StringUtils.toSpacedHex(b) : StringUtils.toHex(b); case BASE64: return StringUtils.base64Encode(b); default: return null; } }
@Override /* SerializerSession */ public final String serializeToString(Object o) throws SerializeException { byte[] b = serialize(o); switch(getBinaryFormat()) { case SPACED_HEX: return StringUtils.toSpacedHex(b); case HEX: return isUseWhitespace() ? StringUtils.toSpacedHex(b) : StringUtils.toHex(b); case BASE64: return StringUtils.base64Encode(b); default: return null; } }
s = toHex(b); else if (binaryFormat == BinaryFormat.SPACED_HEX) s = toSpacedHex(b); else s = base64Encode(b);
s = toHex(b); else if (binaryFormat == BinaryFormat.SPACED_HEX) s = toSpacedHex(b); else s = base64Encode(b);
s = toHex(b); else if (binaryFormat == BinaryFormat.SPACED_HEX) s = toSpacedHex(b); else s = base64Encode(b);
@Test public void write2() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); m.write("foo", baos); assertEquals("A3 66 6F 6F", toSpacedHex(baos.toByteArray())); }
private void test(Object input, String expected) throws Exception { byte[] b = MsgPackSerializer.DEFAULT.serialize(input); assertEquals(expected, StringUtils.toSpacedHex(b)); } }
@Test public void write1() throws Exception { assertEquals("A3 66 6F 6F", toSpacedHex(m.write("foo"))); }
@Test public void c05_stringType_binarySpacedFormat() throws Exception { HttpPartSchema ps = schema("string", "binary-spaced").build(); byte[] foob = "foo".getBytes(); String expected = toSpacedHex(foob); assertEquals(expected, s.serialize(ps, foob)); assertEquals(expected, s.serialize(ps, new C1(foob))); assertEquals("null", s.serialize(ps, new C1(null))); assertEquals("null", s.serialize(ps, null)); }
@Test public void c05_stringType_binarySpacedFormat() throws Exception { HttpPartSchema s = schema("string", "binary-spaced").build(); String in = toSpacedHex("foo".getBytes()); assertEquals("foo", p.parse(s, in, String.class)); assertEquals("foo", IOUtils.read(p.parse(s, in, InputStream.class))); assertEquals("foo", IOUtils.read(p.parse(s, in, Reader.class))); assertEquals("C1-foo", p.parse(s, in, C1.class).toString()); }
return toHex(toType(o, CM_ByteArray)); if (f == BINARY_SPACED) return toSpacedHex(toType(o, CM_ByteArray)); if (f == DATE) return toIsoDate(toType(o, CM_Calendar));
return toHex(toType(o, CM_ByteArray)); if (f == BINARY_SPACED) return toSpacedHex(toType(o, CM_ByteArray)); if (f == DATE) return toIsoDate(toType(o, CM_Calendar));
return toHex(toType(o, CM_ByteArray)); if (f == BINARY_SPACED) return toSpacedHex(toType(o, CM_ByteArray)); if (f == DATE) return toIsoDate(toType(o, CM_Calendar));
@Test public void h06_objectType_arrayProperties_pipes() throws Exception { HttpPartSchema s = schema("object") .property("f1", schema("array").collectionFormat("pipes").items(schema("string"))) .property("f2", schema("array").collectionFormat("pipes").items(schema("string", "byte"))) .property("f4", schema("array").collectionFormat("pipes").items(schema("string", "date-time"))) .property("f5", schema("array").collectionFormat("pipes").items(schema("string", "binary"))) .property("f6", schema("array").collectionFormat("pipes").items(schema("string", "binary-spaced"))) .property("f7", schema("array").collectionFormat("pipes").items(schema("string", "uon"))) .property("f8", schema("array").collectionFormat("pipes").items(schema("integer"))) .property("f9", schema("array").collectionFormat("pipes").items(schema("integer", "int64"))) .property("f10", schema("array").collectionFormat("pipes").items(schema("number"))) .property("f11", schema("array").collectionFormat("pipes").items(schema("number", "double"))) .property("f12", schema("array").collectionFormat("pipes").items(schema("boolean"))) .additionalProperties(schema("array").collectionFormat("pipes").items(schema("integer"))) .build(); byte[] foob = "foo".getBytes(), barb = "bar".getBytes(); String in = "(f1=foo|bar,f2="+base64Encode(foob)+"|"+base64Encode(barb)+",f4=2012-12-21T12:34:56Z|2012-12-21T12:34:56Z,f5="+toHex(foob)+"|"+toHex(barb)+",f6='"+toSpacedHex(foob)+"|"+toSpacedHex(barb)+"',f7=foo|bar,f8=1|2,f9=1|2,f10=1|2,f11=1|2,f12=true|true,f99=1|2)"; H2 h2 = p.parse(s, in, H2.class); assertObjectEquals("{f1:['foo','bar'],f2:[[102,111,111],[98,97,114]],f4:['2012-12-21T12:34:56Z','2012-12-21T12:34:56Z'],f5:[[102,111,111],[98,97,114]],f6:[[102,111,111],[98,97,114]],f7:['foo','bar'],f8:[1,2],f9:[1,2],f10:[1.0,2.0],f11:[1.0,2.0],f12:[true,true],f99:[1,2]}", h2); ObjectMap om = p.parse(s, in, ObjectMap.class); assertObjectEquals("{f1:['foo','bar'],f2:[[102,111,111],[98,97,114]],f4:['2012-12-21T12:34:56Z','2012-12-21T12:34:56Z'],f5:[[102,111,111],[98,97,114]],f6:[[102,111,111],[98,97,114]],f7:['foo','bar'],f8:[1,2],f9:[1,2],f10:[1.0,2.0],f11:[1.0,2.0],f12:[true,true],f99:[1,2]}", om); om = (ObjectMap)p.parse(s, in, Object.class); assertObjectEquals("{f1:['foo','bar'],f2:[[102,111,111],[98,97,114]],f4:['2012-12-21T12:34:56Z','2012-12-21T12:34:56Z'],f5:[[102,111,111],[98,97,114]],f6:[[102,111,111],[98,97,114]],f7:['foo','bar'],f8:[1,2],f9:[1,2],f10:[1.0,2.0],f11:[1.0,2.0],f12:[true,true],f99:[1,2]}", om); }
@Test public void h05_objectType_arrayProperties() throws Exception { HttpPartSchema s = schema("object") .property("f1", schema("array").items(schema("string"))) .property("f2", schema("array").items(schema("string", "byte"))) .property("f4", schema("array").items(schema("string", "date-time"))) .property("f5", schema("array").items(schema("string", "binary"))) .property("f6", schema("array").items(schema("string", "binary-spaced"))) .property("f7", schema("array").items(schema("string", "uon"))) .property("f8", schema("array").items(schema("integer"))) .property("f9", schema("array").items(schema("integer", "int64"))) .property("f10", schema("array").items(schema("number"))) .property("f11", schema("array").items(schema("number", "double"))) .property("f12", schema("array").items(schema("boolean"))) .additionalProperties(schema("array").items(schema("integer"))) .build(); byte[] foob = "foo".getBytes(); String in = "(f1=foo,f2="+base64Encode(foob)+",f4=2012-12-21T12:34:56Z,f5="+toHex(foob)+",f6='"+toSpacedHex(foob)+"',f7=foo,f8=1,f9=1,f10=1,f11=1,f12=true,f99=1)"; H2 h2 = p.parse(s, in, H2.class); assertObjectEquals("{f1:['foo'],f2:[[102,111,111]],f4:['2012-12-21T12:34:56Z'],f5:[[102,111,111]],f6:[[102,111,111]],f7:['foo'],f8:[1],f9:[1],f10:[1.0],f11:[1.0],f12:[true],f99:[1]}", h2); ObjectMap om = p.parse(s, in, ObjectMap.class); assertObjectEquals("{f1:['foo'],f2:[[102,111,111]],f4:['2012-12-21T12:34:56Z'],f5:[[102,111,111]],f6:[[102,111,111]],f7:['foo'],f8:[1],f9:[1],f10:[1.0],f11:[1.0],f12:[true],f99:[1]}", om); om = (ObjectMap)p.parse(s, in, Object.class); assertObjectEquals("{f1:['foo'],f2:[[102,111,111]],f4:['2012-12-21T12:34:56Z'],f5:[[102,111,111]],f6:[[102,111,111]],f7:['foo'],f8:[1],f9:[1],f10:[1.0],f11:[1.0],f12:[true],f99:[1]}", om); }
String in = "(f1=foo,f2="+base64Encode(foob)+",f4=2012-12-21T12:34:56Z,f5="+toHex(foob)+",f6='"+toSpacedHex(foob)+"',f7=foo,f8=1,f9=1,f10=1,f11=1,f12=true,f99=1)";