• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Jtidy (Re: Script for finding XML errors)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Jtidy (Re: Script for finding XML errors)


  • Subject: Re: Jtidy (Re: Script for finding XML errors)
  • From: Mike Schrag <email@hidden>
  • Date: Fri, 2 Nov 2007 15:16:41 -0400

ByteArrayInputStream in = new ByteArrayInputStream( response.contentString().getBytes( "UTF-8" ) );
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
tidy().parseDOM( in, byteStream );
response.setContent( new NSData( byteStream.toByteArray() ) );
Pretty neat little cleanup trick ... Incidentally, if you use Project Wonder, switching to:

      ByteArrayInputStream in = response.content().stream();
      ERXRefByteArrayOutputStream out = new ERXRefByteArrayOutputStream();
      tidy().parseDOM(in, out);
      response.setContent(out.toNSData());

should give you better memory/performance ... the comparison is:

1) response.contentString() (copy if NSData-backed)
2) .getBytes() = copy
3) new ByteArrayInputStream(byte[]) = copy
4) writing to ByteArrayOutputStream = copy
5) byteStream.toByteArray() = copy
6) new NSData(byte[]) = copy

the Wonder variant one is:
1) response.content() (copy if String-backed)
2) writing to ByteArrayOutputStream = copy
 
there might be one more copy in the Wonder variation (I didn't spend too much time digging into .content()), but still at least cut in half on the copies.  If you don't use wonder, you can just steal ERXRefByteArrayOutputStream -- it's basically BAOS, but modified to give direct access to the byte buffer. BAOS normally only hands back a copy, which sort of sucks most of the time.

ms
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Jtidy (Re: Script for finding XML errors)
      • From: Hugi Thordarson <email@hidden>
References: 
 >Script for finding XML errors (From: Nathan Hadfield <email@hidden>)
 >Jtidy (Re: Script for finding XML errors) (From: Hugi Thordarson <email@hidden>)

  • Prev by Date: Re: What a bunch of characters
  • Next by Date: Re: wo framework with the jar in WebServerResources
  • Previous by thread: Jtidy (Re: Script for finding XML errors)
  • Next by thread: Re: Jtidy (Re: Script for finding XML errors)
  • Index(es):
    • Date
    • Thread