Examples of StreamWriter


Examples of co.cask.cdap.test.StreamWriter

    // Start WhoFlow
    FlowManager flowManager = appManager.startFlow("WhoFlow");

    // Send stream events to the "who" Stream
    StreamWriter streamWriter = appManager.getStreamWriter("who");
    streamWriter.send("1");
    streamWriter.send("2");
    streamWriter.send("3");
    streamWriter.send("4");
    streamWriter.send("5");

    try {
      // Wait for the last Flowlet processing 5 events, or at most 5 seconds
      RuntimeMetrics metrics = RuntimeStats.getFlowletMetrics("HelloWorld", "WhoFlow", "saver");
      metrics.waitForProcessed(5, 5, TimeUnit.SECONDS);
View Full Code Here

Examples of net.buffalo.protocal.io.StreamWriter

    interests.add("Cook");
    user.setInterests(interests);
    user.setRoles(new String[]{"SA", "Architect"});
   
    StringWriter stringWriter = new StringWriter();
    StreamWriter streamWriter = new FastStreamWriter(stringWriter);
    MarshallingContext context = new DefaultMarshallingContext(new DefaultConverterLookup(), streamWriter);
    converter.marshal(user, context, streamWriter);
    assertEquals("<map><type>net.buffalo.protocal.User</type><string>username</string><string>Michael</string>" +
        "<string>password</string><string>password</string><string>gendor</string><string>girl</string>" +
        "<string>interests</string><list><type>java.util.ArrayList</type><length>3</length>" +
View Full Code Here

Examples of net.buffalo.protocal.io.StreamWriter

   
    assertTrue(converter.canConvert(sdate.getClass()));
    assertFalse(converter.canConvert(java.util.Date.class));
   
    StringWriter stringWriter = new StringWriter();
    StreamWriter streamWriter = new FastStreamWriter(stringWriter);
   
    DefaultConverterLookup defaultConverterLookup = new DefaultConverterLookup();
    MarshallingContext context = new DefaultMarshallingContext(defaultConverterLookup, streamWriter);
    converter.marshal(sdate, context, streamWriter);
   
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

   
    if (response.isCommitted()) {
        log.error("Could not write an error message as the headers & HTTP status were already committed!");
    } else {
      response.setStatus(500);
      StreamWriter sw =
        getAbdera().newStreamWriter()
                   .setOutputStream(
                     response.getOutputStream(),
                     "UTF-8");
      Error.create(sw, 500, message,t);
      sw.close();
    }
  }
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

   
    if (response.isCommitted()) {
        log.error("Could not write an error message as the headers & HTTP status were already committed!");
    } else {
      response.setStatus(500);
      StreamWriter sw =
        getAbdera().newStreamWriter()
                   .setOutputStream(
                     response.getOutputStream(),
                     "UTF-8");
      Error.create(sw, 500, message,t);
      sw.close();
    }
  }
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

            type = _text != null ? _text.type() : type;
            contentValue = source;
            valueContext = objectContext;
        }
        QName qname = this.qname != null ? this.qname : getQName(objectContext.getAccessor());
        StreamWriter sw = context.getStreamWriter();
        sw.startText(qname, type);
        writeAttributes(source, objectContext, context, conventions);

        switch (type) {
            case TEXT:
            case HTML:
                sw.writeElementText(toString(contentValue));
                break;
            case XHTML:
                Div div = null;
                if (contentValue instanceof Div)
                    div = (Div)contentValue;
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

    protected void process(Object source,
                           ObjectContext objectContext,
                           SerializationContext context,
                           Conventions conventions) {

        StreamWriter sw = context.getStreamWriter();
        Category _category = objectContext.getAnnotation(Category.class);

        String scheme = null;
        AccessibleObject accessor = objectContext.getAccessor(Scheme.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value != null)
                scheme = toString(value);
        }
        if (scheme == null) {
            Scheme _scheme = objectContext.getAnnotation(Scheme.class);
            if (_scheme != null && !_scheme.value().equals(DEFAULT)) {
                scheme = _scheme.value();
            }
        }
        if (scheme == null && _category != null && !_category.scheme().equals(DEFAULT)) {
            scheme = _category.scheme();
        }
        if (scheme != null)
            sw.writeAttribute("scheme", scheme);

        String label = null;
        accessor = objectContext.getAccessor(Label.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value != null)
                label = toString(value);
        }
        if (label == null) {
            Label _label = objectContext.getAnnotation(Label.class);
            if (_label != null && !_label.value().equals(DEFAULT)) {
                label = _label.value();
            }
        }
        if (label == null && _category != null && !_category.label().equals(DEFAULT)) {
            label = _category.label();
        }
        if (label != null)
            sw.writeAttribute("label", label);

        String term = null;
        accessor = objectContext.getAccessor(Value.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value != null)
                term = toString(value);
        }
        if (term == null)
            term = toString(source);
        if (term != null)
            sw.writeAttribute("term", term);

        writeAttributes(source, objectContext, context, conventions);
        writeExtensions(source, objectContext, context, conventions);
    }
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

    protected void init(Object source,
                        ObjectContext objectContext,
                        SerializationContext context,
                        Conventions conventions) {
        QName qname = this.qname != null ? this.qname : getQName(objectContext.getAccessor());
        StreamWriter sw = context.getStreamWriter();
        sw.startElement(qname);
    }
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

            type = _content != null ? _content.type() : type;
            contentValue = source;
            valueContext = objectContext;
        }

        StreamWriter sw = context.getStreamWriter();
        sw.startContent(type);
        writeAttributes(source, objectContext, context, conventions);

        if (type == Type.MEDIA || type == Type.XML) {
            String mediatype = null;
            AccessibleObject mtaccessor = valueContext.getAccessor(MediaType.class, conventions);
            if (mtaccessor != null) {
                Object mtvalue = eval(mtaccessor, contentValue);
                mediatype = mtvalue != null ? toString(mtvalue) : null;
            }
            if (mediatype == null) {
                MediaType mt = valueContext.getAnnotation(MediaType.class);
                mediatype = mt != null && !mt.value().equals(DEFAULT) ? mt.value() : null;
            }
            if (mediatype != null)
                sw.writeAttribute("type", mediatype);
        }

        switch (type) {
            case TEXT:
            case HTML:
                sw.writeElementText(toString(contentValue));
                break;
            case XHTML:
                Div div = null;
                if (contentValue instanceof Div)
                    div = (Div)contentValue;
                else {
                    div = context.getAbdera().getFactory().newDiv();
                    div.setValue(toString(contentValue));
                }
                context.serialize(div, new ObjectContext(div));
                break;
            case XML:
                Element el = null;
                if (contentValue instanceof Element)
                    el = (Element)contentValue;
                else {
                    StringReader sr = new StringReader(toString(contentValue));
                    Document<Element> doc = context.getAbdera().getParser().parse(sr);
                    el = doc.getRoot();
                }
                context.serialize(el, new ObjectContext(el));
                break;
            case MEDIA:
                try {
                    if (contentValue instanceof DataHandler)
                        sw.writeElementText((DataHandler)contentValue);
                    else if (contentValue instanceof InputStream)
                        sw.writeElementText((InputStream)contentValue);
                    else
                        sw.writeElementText(toString(contentValue));
                } catch (IOException e) {
                    throw new SerializationException(e);
                }
        }
    }
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

    protected void writeAttributes(Object source,
                                   ObjectContext objectContext,
                                   SerializationContext context,
                                   Conventions conventions) {
        writeCommon(source, objectContext, context, conventions);
        StreamWriter sw = context.getStreamWriter();
        AccessibleObject[] accessors = objectContext.getAccessors(Attribute.class, conventions);
        for (AccessibleObject accessor : accessors) {
            QName qname = getQName(accessor);
            Object value = eval(accessor, source);
            if (value != null)
                sw.writeAttribute(qname, toString(value));
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.