• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Piped Input to Output

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
im using jdom to construct an xml document. once im done building it i need to output the stream and pipe it to an input stream...right now it just hangs my server....any help would be greatly appreciated..
org.jdom.output.XMLOutputter xmlOut = new org.jdom.output.XMLOutputter();

//import it into domino ahhh yeahh....
PipedOutputStream ps = null;
PipedInputStream is = null;

try {
ps = new PipedOutputStream();
is = new PipedInputStream(ps);
//output the xml doc to the
pipedoutputstream
xmlOut.output(transformedDoc,ps);
//import xml into domino
dxlIn.importDXL(is);
//flush and close
ps.flush();
is.close();
ps.close();
} catch (DXLException ex) {
System.out.println(ex.toString());

}
what am i doing wrong?
thanks!
Brian
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The piped streams that come with Java require a connect() call at some point to relate the two. I find them hard to work with and they are limited by the hard coded buffer size that they use (1024k). In cases like this when you are not using threads, the buffer will fill up and everything will stop. To make piped streams work, you need to constantly have a consumer emptying the buffer or keep the input to the buffer under the buffer size.
I wrote alternative circular buffer libraries that you can use. Simply create a circular buffer and get the input and output streams from it. You can even set the buffer it uses to grow without bound.
http://ostermiller.org/utils/CircularByteBuffer.html
 
Brian Holmes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
steve-
thanks for the reply! i really appreciate it. i am actually using the ostermiller utils already for parsing comma delimited files.. im pretty new to java and i was wondering if you may be so kind as to show me some example code for the circularbyte buffer? maybe using the code i posted? how would i re-write it to use your utils?
im going to start trying to figure it out..and it will probably take me all day so it would be great if you could show me more literally how to use it instead of piped streams...since i spent all day yesterday on those to no avail
thanks much for the reply!
 
Steve Deadsea
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't actually compiled this, but it should be close.
 
Brian Holmes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
steve-
thanks for the help! i really appredciate it! i actually brute forced my way through it yesterday and got it working
i've been using your utils package to write an importer that reads csv files, converts them to xml, transforms them to ibm's dtd for lotus domino (DXL) and then imports them into domino. i'm somewhat of a newbie and i was wondering if there was a way i could actually put only the classes of yours that i am using into my own package? right now im using the CSV classes and the CircularBuffer....very helpful by the way!!
is that a standard practice or should i just include your package as well?
-brian
 
Steve Deadsea
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You just need to include the contents of the utils.jar in your jar file. You can prune a bit of it out. You'll need the CSVParse.class CSVPaser.class CSVLexer.class CircularByteBuffer.class and BufferOverflowException.class at the very minimum.
 
Here. Have a potato. I grew it in my armpit. And from my other armpit, this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic