Help with copying objects please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • D

    Help with copying objects please

    Hi,
    I have some old code that uses the deprecated copy command as :

    ByteArrayOutput Stream bout = new ByteArrayOutput Stream();
    StringReader sr = new StringReader(st rString);
    copy(sr,bout);

    how could I achieve the same result without the now redundant copy command?

    Thanks



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.530 / Virus Database: 325 - Release Date: 22/10/2003


  • SPG

    #2
    Re: Help with copying objects please

    Try:

    ByteArrayOutput Stream bout = new ByteArrayOutput Stream();
    StringReader sr = new StringReader(st rString);

    int val=0;
    byte[] bytes = new byte[32*1024] //32K byte array
    while ((val=sr.read(b ytes))!= -1) {
    bout.write(byte s,0,val);
    }

    But, I would be weary of mixing readers with outputstreams. I would make
    sure you use a Reader with a Writer or and InputStream with an OutputStream.
    Mainly due to conversion protocols but can cause some probs...

    HTH

    Steve



    "D" <noone@nowhere. COM> wrote in message
    news:3f9c2a30$0 $9467$cc9e4d1f@ news.dial.pipex .com...[color=blue]
    > Hi,
    > I have some old code that uses the deprecated copy command as :
    >
    > ByteArrayOutput Stream bout = new ByteArrayOutput Stream();
    > StringReader sr = new StringReader(st rString);
    > copy(sr,bout);
    >
    > how could I achieve the same result without the now redundant copy[/color]
    command?[color=blue]
    >
    > Thanks
    >
    >
    >
    > ---
    > Outgoing mail is certified Virus Free.
    > Checked by AVG anti-virus system (http://www.grisoft.com).
    > Version: 6.0.530 / Virus Database: 325 - Release Date: 22/10/2003
    >
    >[/color]


    Comment

    • D

      #3
      Re: Help with copying objects please


      "SPG" <steve.goodsell @nopoo.blueyond er.co.uk> wrote in message
      news:PYVmb.2367 $lF6.23507984@n ews-text.cableinet. net...[color=blue]
      > Try:
      >
      > ByteArrayOutput Stream bout = new ByteArrayOutput Stream();
      > StringReader sr = new StringReader(st rString);
      >
      > int val=0;
      > byte[] bytes = new byte[32*1024] //32K byte array
      > while ((val=sr.read(b ytes))!= -1) {
      > bout.write(byte s,0,val);
      > }
      >
      > But, I would be weary of mixing readers with outputstreams. I would make
      > sure you use a Reader with a Writer or and InputStream with an[/color]
      OutputStream.[color=blue]
      > Mainly due to conversion protocols but can cause some probs...
      >
      > HTH
      >
      > Steve
      >[/color]

      Hi Steve. Many thanks for that help. I'm just getting up to speed with
      Java, hopefully I'll be able to rewrite it once I get the time and a bit
      more familiar with it.

      Cheers

      Dave


      ---
      Outgoing mail is certified Virus Free.
      Checked by AVG anti-virus system (http://www.grisoft.com).
      Version: 6.0.530 / Virus Database: 325 - Release Date: 22/10/2003


      Comment

      Working...