if (debug) { byte[] b = readBytes((InputStream)input, 1024); inputString = toHex(b); inputStream = new ByteArrayInputStream(b); } else { inputString = toHex((byte[])input); inputStream = new ByteArrayInputStream((byte[])input); doClose = false; if (debug) { byte[] b = readBytes((File)input); inputString = toHex(b); inputStream = new ByteArrayInputStream(b); } else {
if (debug) { byte[] b = readBytes((InputStream)input, 1024); inputString = toHex(b); inputStream = new ByteArrayInputStream(b); } else { inputString = toHex((byte[])input); inputStream = new ByteArrayInputStream((byte[])input); doClose = false; if (debug) { byte[] b = readBytes((File)input); inputString = toHex(b); inputStream = new ByteArrayInputStream(b); } else {
if (debug) { byte[] b = readBytes((InputStream)input, 1024); inputString = toHex(b); inputStream = new ByteArrayInputStream(b); } else { inputString = toHex((byte[])input); inputStream = new ByteArrayInputStream((byte[])input); doClose = false; if (debug) { byte[] b = readBytes((File)input); inputString = toHex(b); inputStream = new ByteArrayInputStream(b); } else {
/** * Returns the HTTP body content as a simple hexadecimal character string. * * <h5 class='section'>Example:</h5> * <p class='bcode w800'> * 0123456789ABCDEF * </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 asHex() throws IOException { if (body == null) body = readBytes(getInputStream(), 1024); return toHex(body); }
/** * Returns the HTTP body content as a simple hexadecimal character string. * * <h5 class='section'>Example:</h5> * <p class='bcode w800'> * 0123456789ABCDEF * </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 asHex() throws IOException { if (body == null) body = readBytes(getInputStream(), 1024); return toHex(body); }
/** * Returns the HTTP body content as a simple hexadecimal character string. * * <h5 class='section'>Example:</h5> * <p class='bcode w800'> * 0123456789ABCDEF * </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 asHex() throws IOException { if (body == null) body = readBytes(getInputStream(), 1024); return toHex(body); }
byte[] b = (byte[])value; if (binaryFormat == BinaryFormat.HEX) s = toHex(b); else if (binaryFormat == BinaryFormat.SPACED_HEX) s = toSpacedHex(b);
byte[] b = (byte[])value; if (binaryFormat == BinaryFormat.HEX) s = toHex(b); else if (binaryFormat == BinaryFormat.SPACED_HEX) s = toSpacedHex(b);
byte[] b = (byte[])value; if (binaryFormat == BinaryFormat.HEX) s = toHex(b); else if (binaryFormat == BinaryFormat.SPACED_HEX) s = toSpacedHex(b);
public static void main(String[] generateParams) throws Exception { File f = new File("src/test/resources/org/apache/juneau/json/jsonTestSuite"); int i = 0; String pattern = "\n\t\t'{' {0}, \"{1}\", {2}, {3} '}',"; StringBuilder sb = new StringBuilder(); for (File fc : f.listFiles()) { String n = fc.getName(); if (n.endsWith(".json")) { n = n.replaceAll("\\.json", ""); String contents = specials.get(n); if (contents == null) { if (n.charAt(1) == 'x') contents = '"' + toHex(readBytes(fc)) + '"' + "/*" + decodeHex(read(fc)).replaceAll("\\\\u", "bu") + "*/"; else contents = '"' + read(fc).replaceAll("\"", "\\\\\"").trim() + '"'; } String errorText = errors.get(n); if (errorText != null) errorText = '"' + errorText + '"'; sb.append(format(pattern, i++, fc.getName().replace(".json", ""), contents, errorText)); } } System.err.println(sb); // NOT DEBUG }
@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; } }
@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; } }
@Test public void c04_stringType_binaryFormat() throws Exception { HttpPartSchema ps = schema("string", "binary").build(); byte[] foob = "foo".getBytes(); String expected = toHex(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 c04_stringType_binaryFormat() throws Exception { HttpPartSchema s = schema("string", "binary").build(); String in = toHex("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 base64Encode(toType(o, CM_ByteArray)); if (f == BINARY) return toHex(toType(o, CM_ByteArray)); if (f == BINARY_SPACED) return toSpacedHex(toType(o, CM_ByteArray));
return base64Encode(toType(o, CM_ByteArray)); if (f == BINARY) return toHex(toType(o, CM_ByteArray)); if (f == BINARY_SPACED) return toSpacedHex(toType(o, CM_ByteArray));
return base64Encode(toType(o, CM_ByteArray)); if (f == BINARY) return toHex(toType(o, CM_ByteArray)); if (f == BINARY_SPACED) return toSpacedHex(toType(o, CM_ByteArray));
@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); }