/** * Configuration property: Binary input format. * * @see InputStreamParser#ISPARSER_binaryFormat * @return * The format to use when converting strings to byte arrays. */ protected final BinaryFormat getBinaryFormat() { return ctx.getBinaryFormat(); }
/** * Constructor. * * @param ps The property store containing all the settings for this object. * @param consumes The list of media types that this parser consumes (e.g. <js>"application/json"</js>). */ protected InputStreamParser(PropertyStore ps, String...consumes) { super(ps, consumes); binaryFormat = getProperty(ISPARSER_binaryFormat, BinaryFormat.class, BinaryFormat.HEX); }
/** * Wraps the specified input object into a {@link ParserPipe} object so that it can be easily converted into * a stream or reader. * * @param input * The input. * <br>This can be any of the following types: * <ul> * <li><jk>null</jk> * <li>{@link InputStream} * <li><code><jk>byte</jk>[]</code> * <li>{@link File} * <li>{@link CharSequence} containing encoded bytes according to the {@link InputStreamParser#ISPARSER_binaryFormat} setting. * </ul> * @return * A new {@link ParserPipe} wrapper around the specified input object. */ @SuppressWarnings("resource") @Override /* ParserSession */ public final ParserPipe createPipe(Object input) { return setPipe(new ParserPipe(input, isDebug(), ctx.isAutoCloseStreams(), ctx.isUnbuffered(), ctx.getBinaryFormat())); }
@Override /* MessageBodyReader */ public Object readFrom(Class<Object> type, Type gType, Annotation[] a, MediaType mediaType, MultivaluedMap<String,String> headers, InputStream in) throws IOException, WebApplicationException { try { String mt = parsers.findMatch(mediaType.toString()); if (mt == null) throw new WebApplicationException(SC_UNSUPPORTED_MEDIA_TYPE); Parser p = parsers.getParser(mt); BeanContext bc = p.getBeanContext(); ClassMeta<?> cm = bc.getClassMeta(gType); ObjectMap mp = getMethodProperties(a); mp.put("mediaType", mediaType.toString()); if (p.isReaderParser()) { ReaderParser p2 = (ReaderParser)p; InputStreamReader r = new InputStreamReader(in, IOUtils.UTF8); ParserSession session = p2.createSession(r, mp, null, null); return p2.parse(session, cm); } InputStreamParser p2 = (InputStreamParser)p; ParserSession session = p2.createSession(in, mp, null, null); return p2.parse(session, cm); } catch (ParseException e) { throw new IOException(e); } } }
@Override /* Context */ public ObjectMap asMap() { return super.asMap() .append("MsgPackParser", new ObjectMap()); } }
@Test public void testStreamsAutoClose() throws Exception { InputStreamParser p = MsgPackParser.DEFAULT.builder().autoCloseStreams().build(); Object r; InputStream is; is = is("00 01"); r = p.parse(is, Object.class); assertObjectEquals("0", r); try { r = p.parse(is, Object.class); fail("Exception expected"); } catch (Exception e) { assertTrue(e.getMessage().contains("Stream is closed")); } }
/** * Wraps the specified input object into a {@link ParserPipe} object so that it can be easily converted into * a stream or reader. * * @param input * The input. * <br>This can be any of the following types: * <ul> * <li><jk>null</jk> * <li>{@link InputStream} * <li><code><jk>byte</jk>[]</code> * <li>{@link File} * <li>{@link CharSequence} containing encoded bytes according to the {@link InputStreamParser#ISPARSER_binaryFormat} setting. * </ul> * @return * A new {@link ParserPipe} wrapper around the specified input object. */ @SuppressWarnings("resource") @Override /* ParserSession */ public final ParserPipe createPipe(Object input) { return setPipe(new ParserPipe(input, isDebug(), ctx.isAutoCloseStreams(), ctx.isUnbuffered(), ctx.getBinaryFormat())); }
if (! p.isReaderParser()) { InputStreamParser p2 = (InputStreamParser)p; ParserSession session = p2.createSession(getInputStream(), properties, getJavaMethod(), getServlet()); return p2.parse(session, type);
@Override /* Context */ public ObjectMap asMap() { return super.asMap() .append("MsgPackParser", new ObjectMap()); } }
r = p.parse(is, Object.class); assertObjectEquals("0", r); r = p.parse(is, Object.class); assertObjectEquals("1", r); r = p.parse(is, Object.class); assertObjectEquals("128", r); r = p.parse(is, Object.class); assertObjectEquals("129", r); r = p.parse(is, Object.class); assertObjectEquals("32768", r); r = p.parse(is, Object.class); assertObjectEquals("32769", r); r = p.parse(is, Object.class); assertObjectEquals("0.0", r); r = p.parse(is, Object.class); assertObjectEquals("1.0", r); r = p.parse(is, Object.class); assertObjectEquals("1.0", r); r = p.parse(is, Object.class); assertObjectEquals("-1.0", r); r = p.parse(is, Object.class); assertObjectEquals("''", r); r = p.parse(is, Object.class); assertObjectEquals("''", r);
/** * Wraps the specified input object into a {@link ParserPipe} object so that it can be easily converted into * a stream or reader. * * @param input * The input. * <br>This can be any of the following types: * <ul> * <li><jk>null</jk> * <li>{@link InputStream} * <li><code><jk>byte</jk>[]</code> * <li>{@link File} * <li>{@link CharSequence} containing encoded bytes according to the {@link InputStreamParser#ISPARSER_binaryFormat} setting. * </ul> * @return * A new {@link ParserPipe} wrapper around the specified input object. */ @SuppressWarnings("resource") @Override /* ParserSession */ public final ParserPipe createPipe(Object input) { return setPipe(new ParserPipe(input, isDebug(), ctx.isAutoCloseStreams(), ctx.isUnbuffered(), ctx.getBinaryFormat())); }
@Override /* Context */ public ObjectMap asMap() { return super.asMap() .append("MsgPackParser", new ObjectMap()); } }
/** * Configuration property: Binary input format. * * @see InputStreamParser#ISPARSER_binaryFormat * @return * The format to use when converting strings to byte arrays. */ protected final BinaryFormat getBinaryFormat() { return ctx.getBinaryFormat(); }
/** * Constructor. * * @param ps The property store containing all the settings for this object. * @param consumes The list of media types that this parser consumes (e.g. <js>"application/json"</js>). */ protected InputStreamParser(PropertyStore ps, String...consumes) { super(ps, consumes); binaryFormat = getProperty(ISPARSER_binaryFormat, BinaryFormat.class, BinaryFormat.HEX); }
private void testParseJsonEquivalency(String testName, OutputStreamSerializer s, InputStreamParser p, String expected) throws Exception { try { s = (OutputStreamSerializer)getSerializer(s); p = (InputStreamParser)getParser(p); WriterSerializer sJson = (WriterSerializer)getSerializer(this.sJson); String r = s.serializeToString(comboInput.getInput()); Object o = p.parse(r, comboInput.type); r = sJson.serialize(o); assertEquals(comboInput.label + "/" + testName + " parse-normal failed on JSON equivalency", expected, r); } catch (AssertionError e) { throw e; } catch (Exception e) { throw new Exception(comboInput.label + "/" + testName + " failed.", e); } }
/** * Configuration property: Binary input format. * * @see InputStreamParser#ISPARSER_binaryFormat * @return * The format to use when converting strings to byte arrays. */ protected final BinaryFormat getBinaryFormat() { return ctx.getBinaryFormat(); }
/** * Constructor. * * @param ps The property store containing all the settings for this object. * @param consumes The list of media types that this parser consumes (e.g. <js>"application/json"</js>). */ protected InputStreamParser(PropertyStore ps, String...consumes) { super(ps, consumes); binaryFormat = getProperty(ISPARSER_binaryFormat, BinaryFormat.class, BinaryFormat.HEX); }