[jdom-interest] Cleaning up EOS marker

Paul Philion philion at acmerocket.com
Tue Jun 26 05:40:42 PDT 2001


Tim -

Here's my "CleanUpInputStream". Nothing fancy, but it works for me. I
recommend wrapping a BufferedInputStream around the input before this...

InputStream in = new CleanUpInputStream(new BufferedInputStream(new
FileInputStream("fileName")));

----

public class CleanUpInputStream extends FilterInputStream {
 public CleanUpInputStream(InputStream in) {
  super(in);
 }

 public int read() throws IOException {
  int ch = in.read();
  if (ch == 10 || ch == 13 || ch == 9 || ch == -1) {
   return ch;
  }
  else if (ch < 32 || ch > 126) {
   return ' ';
  }
  return ch;
 }

 public int read(byte[] data, int offset, int length) throws IOException {
  int result = in.read(data, offset, length);
  for (int i = offset; i < offset + length; i++) {
   int ch = data[i];
   if (ch == 10 || ch == 13 || ch == 9 || ch == -1) {
    // nothing
   }
   else if (ch < 32 || ch > 126) {
    data[i] = (byte)' ';
   }
  }
  return result;
 }
}


----- Original Message -----
From: "Tim Sawyer" <Tim.Sawyer at pancredit.com>
To: "'Paul Philion'" <philion at acmerocket.com>; <jdom-interest at jdom.org>
Sent: Tuesday, June 26, 2001 5:37 AM
Subject: RE: [jdom-interest] Parsing XML with end of stream marker


> I thought that too, but I couldn't think of a nice way of checking for
<EOS>
> without writing loads of buffer code in my filter input stream, and I
> thought that was making things a bit complicated.  It seemed easy to check
> each single character as it came in, but checking for specific strings of
> characters seemed difficult.
>
> Can I subclass BufferedInputStream somehow and use that?  It would be much
> more elegant (and probably performant?) to use streams, methinks...
>
> Tim.
>
> -----Original Message-----
> From: Paul Philion [mailto:philion at acmerocket.com]
> Sent: 25 June 2001 19:12
> To: jdom-interest at jdom.org
> Subject: Re: [jdom-interest] Parsing XML with end of stream marker
>
>
> Tim -
>
> It might make sense to use an FilterInputStream to replace the EOS with a
> space (or nothing). I wrote a little FilterInputStream that will replace
> unprintable chars in the input stream with spaces. Makes JDOM happy,
without
> the overhead to converting the whole file to a string.
>
> - Paul Philion
>
> ----- Original Message -----
> From: "Tim Sawyer" <Tim.Sawyer at pancredit.com>
> To: <jdom-interest at jdom.org>
> Sent: Monday, June 25, 2001 12:11 PM
> Subject: RE: [jdom-interest] Parsing XML with end of stream marker
>
>
> > Cheers, peeps.  I've solved it by converting to a string and cutting the
> > last few chars off.  I was hoping to avoid creating too many new strings
> to
> > keep the speed up, but you can't have everything!
> >
> > I did get a bit confused when build() interpreted my string as a URI
> > though... ;-)
> >
> > Thanks,
> >
> > Tim.
> >
> > -----Original Message-----
> > From: Jon Baer [mailto:jonbaer at digitalanywhere.com]
> > Sent: 25 June 2001 13:21
> > To: jdom-interest at jdom.org
> > Subject: Re: [jdom-interest] Parsing XML with end of stream marker
> >
> >
> > Yeah ur gonna have to trim that bad boy off, Id say extend the Reader
and
> > create your
> > own and either test for </soap-env:envelope> or substring it till
> > indexOf("<EOS>");
> > or something.
> >
> > The builder lets you take a String now so you might wanna filter the
> stream
> > first
> > before you pass it to the builder.
> >
> > - Jon
> >
> >
> > This e-mail and its attachments are for the use of the addressee only.
> > It may contain information that is legally privileged, confidential and
> > exempt from  disclosure.  It is not a contract, and prices, data
> > and other information are not warranted as to completeness or accuracy.
> > Any comments or statements  made herein do not necessarily
> > reflect those of PanCredit Systems Limited. If you are not the intended
> > recipient you must not copy, distribute or disseminate this e-mail
> > or attachments to anyone other than the addressee.
> > If you receive this communication in error please advise us by telephone
> > at once.
> > PanCredit Systems Limited
> > Tel: +44 113 250 0260
> > Fax: +44 113 250 0621
> >
> > _______________________________________________
> > To control your jdom-interest membership:
> >
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
> t.com
> >
>
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
> t.com
>
>
> This e-mail and its attachments are for the use of the addressee only.
> It may contain information that is legally privileged, confidential and
> exempt from  disclosure.  It is not a contract, and prices, data
> and other information are not warranted as to completeness or accuracy.
> Any comments or statements  made herein do not necessarily
> reflect those of PanCredit Systems Limited. If you are not the intended
> recipient you must not copy, distribute or disseminate this e-mail
> or attachments to anyone other than the addressee.
> If you receive this communication in error please advise us by telephone
> at once.
> PanCredit Systems Limited
> Tel: +44 113 250 0260
> Fax: +44 113 250 0621
>
>




More information about the jdom-interest mailing list