Examples of StreamWriter


Examples of org.apache.abdera.writer.StreamWriter

    Object source,
    ObjectContext objectContext,
    SerializationContext context,
    Conventions conventions) {
      writeAttributes(source, objectContext, context, conventions);
      StreamWriter sw = context.getStreamWriter();
      Generator _generator = objectContext.getAnnotation(Generator.class);

      String uri = null;
      AccessibleObject accessor = objectContext.getAccessor(URI.class, conventions);
      if (accessor != null) {
        Object value = eval(accessor, source);
        if (value != null)
          uri = toString(value);
      }
      if (uri == null) {
        URI _uri = objectContext.getAnnotation(URI.class);
        if (_uri != null && !_uri.value().equals(DEFAULT)) {
          uri = _uri.value();
        }
      }
      if (uri == null && _generator != null && !_generator.uri().equals(DEFAULT)) {
        uri = _generator.uri();
      }
      if (uri != null)
        sw.writeAttribute("uri", uri);
     
      String version = null;
      accessor = objectContext.getAccessor(URI.class, conventions);
      if (accessor != null) {
        Object value = eval(accessor, source);
        if (value != null)
          version = toString(value);
      }
      if (version == null) {
        URI _version = objectContext.getAnnotation(URI.class);
        if (_version != null && !_version.value().equals(DEFAULT)) {
          version = _version.value();
        }
      }
      if (version == null && _generator != null && !_generator.version().equals(DEFAULT)) {
        version = _generator.version();
      }
      if (version != null)
        sw.writeAttribute("version", version);
     
      writeTextValue(source, objectContext, context, conventions);
  }
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

  static Calendar cal_now = Calendar.getInstance();
 
  @Test
  public void testSimple() throws Exception {
    Abdera abdera = Abdera.getInstance();
    StreamWriter sw = abdera.newStreamWriter();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    sw.setOutputStream(out)
      .setAutoIndent(true);
    ConventionSerializationContext c =
      new ConventionSerializationContext(sw);
    c.setSerializer(MyEntry.class, new EntrySerializer());
    sw.startDocument();
    c.serialize(new MyEntry());
    sw.endDocument();
   
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    Document<Entry> doc = abdera.getParser().parse(in);
    Entry entry = doc.getRoot();
    assertEquals("tag:example.org,2008:foo", entry.getId().toString());
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

  }
 
  @Test
  public void testAnnotated() throws Exception {
    Abdera abdera = Abdera.getInstance();
    StreamWriter sw = abdera.newStreamWriter();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    sw.setOutputStream(out)
      .setAutoIndent(true);
    ConventionSerializationContext c =
      new ConventionSerializationContext(sw);
    sw.startDocument();
    c.serialize(new MyAnnotatedEntry());
    sw.endDocument();
   
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    Document<Entry> doc = abdera.getParser().parse(in);
    Entry entry = doc.getRoot();
    assertEquals("tag:example.org,2008:foo", entry.getId().toString());
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

  public static void main(String... args) {
   
    Abdera abdera = Abdera.getInstance();
   
    StreamWriter out =
      abdera.newStreamWriter()
        .setOutputStream(System.out,"UTF-8")
        .setAutoflush(false)
        .setAutoIndent(true)
        .startDocument()
          .startFeed()
            .writeBase("http://example.org")
            .writeLanguage("en-US")
            .writeId("http://example.org")
            .writeTitle("<Testing 123>")
            .writeSubtitle("Foo")
            .writeAuthor("James", null, null)
            .writeUpdated(new Date())
            .writeLink("http://example.org/foo")
            .writeLink("http://example.org/bar","self")
            .writeCategory("foo")
            .writeCategory("bar")
            .writeLogo("logo")
            .writeIcon("icon")
            .writeGenerator("1.0", "http://example.org", "foo")
            .flush();
     
    for (int n = 0; n < 100; n++) {
      out.startEntry()     
        .writeId("http://example.org/" + n)
        .writeTitle("Entry #" + n)
        .writeUpdated(new Date())
        .writePublished(new Date())
        .writeEdited(new Date())
        .writeSummary("This is text summary")
        .writeAuthor("James", null, null)
        .writeContributor("Joe", null, null)
        .startContent("application/xml")
          .startElement("a","b","c")
            .startElement("x","y","z")
              .writeElementText("This is a test")
              .startElement("a")
                .writeElementText("foo")
              .endElement()
              .startElement("b","bar")
                .writeAttribute("foo", new Date())
                .writeAttribute("bar", 123L)
                .writeElementText(123.123)
              .endElement()
            .endElement()
          .endElement()
        .endContent()
        .endEntry()
        .flush();
    }
     
    out.endFeed()
      .endDocument()
      .flush();
   
  }
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

  public static void main(
    String... args)
      throws Exception {   
    Abdera abdera = Abdera.getInstance();
    StreamWriter sw =
      abdera.newStreamWriter()
            .setOutputStream(System.out)
            .setAutoIndent(true);
    Foo foo = new Foo();
    foo.writeTo(sw);
    sw.close();
  }
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

    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

Examples of org.apache.abdera.writer.StreamWriter

  protected void writeCommon(
    Object source,
    ObjectContext objectContext,
    SerializationContext context,
    Conventions conventions) {
      StreamWriter sw = context.getStreamWriter();
      String lang = null;
      AccessibleObject accessor = objectContext.getAccessor(Language.class, conventions);
      if (accessor != null) {
        Object value = eval(accessor, source);
        if (value != null) {
          if (value instanceof Lang ||
              value instanceof org.apache.abdera.i18n.lang.Lang) {
            lang = value.toString();
          } else {
            lang = toString(value);
          }
        }
      }
      if (lang == null) {
        Language _lang = objectContext.getAnnotation(Language.class);
        if (_lang != null && !_lang.value().equals(DEFAULT)) {
          lang = _lang.value();
        }
      }
      if (lang != null)
        sw.writeLanguage(lang);
     
 
      String base = null;
      accessor = objectContext.getAccessor(BaseURI.class, conventions);
      if (accessor != null) {
        Object value = eval(accessor, source);
        if (value != null)
          base = toString(value);
      }
      if (base != null)
        sw.writeBase(base);
  }
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.goldenorb.util.StreamWriter

      process = builder.start();
     
//      Runtime runtime = Runtime.getRuntime();
//      process = runtime.exec(args.toArray(new String[args.size()]), new String[0]);
     
      new StreamWriter(process.getErrorStream(), errStream);
      new StreamWriter(process.getInputStream(), outStream);
     
    } catch (IOException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      e.printStackTrace();
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.