streaming large strings

From: Stephen Ramsay (sramsay_at_uga.edu)
Date: 02/07/05

  • Next message: Raymond DeCampo: "Re: streaming large strings"
    Date: Sun, 06 Feb 2005 23:44:37 GMT
    
    

    I'm working on an application that needs to move very large strings
    around (XML files, several megabytes in length). I can't do anything
    about the fact they're available to my program as Strings. It's just
    the way the API I'm using works.

    There are a couple of things I need to do with those strings: pass them
    to a SAXParser (which expects an InputStream), and write them to files.
    Problem is, no matter what I to do, the file ends up truncated (pretty
    much always in the same location, toward the end of the file).

    I've tried lots of things, including passing the string to a
    StringReader and buffering it. I've also tried things like:

    byte[] bytes = xmlDoc.getBytes();
    InputStream bytestream = new ByteArrayInputStream(bytes);

    and then writing it out to a Buffered writer with:

    while ((nextChar = xmlDoc.read()) != -1)

    Pretty much everything I do results in a truncated file.

    Can anyone suggest a good general approach to dealing with large strings
    (that need to turn into streams for writing or other reasons)?

    Thanks,

    Steve

    -- 
    Stephen Ramsay
    

  • Next message: Raymond DeCampo: "Re: streaming large strings"

    Relevant Pages

    • What I want in an editor/IDE
      ... I started writing this list because I wanted to have definite points ... start writing yet another IDE and so am now thinking in terms of new ... See the code outliner below. ... strings, normal strings and triple ...
      (comp.lang.python)
    • Re: Standard Read and Write FILE functions to refer to memory
      ... Those are the sort of things you want if you're trying ... specifically to read/write from/to strings. ... > pointers to functions that implement reading, writing, seeking, ... Since this is an extension, you have to define the macro ...
      (comp.lang.c)
    • Re: MATRIX PROBLEMS (AGAIN!)
      ... Start off writing a program that works on a small amount of data, ... don't have any idea whether you want integers in your matrix or strings. ... State what you intend to do with the result, ...
      (comp.lang.ruby)
    • Re: string?
      ... Marcel wrote: ... > Strings look very easy to use to me so that's why i started to put all ... percent runtime penalty or a program that is 1 or 2 percent faster ... you mentioned you are *writing* HTML pages. ...
      (alt.comp.lang.learn.c-cpp)
    • Re: Chords on String Instruments
      ... >> If you know how string instruments work, ... the hand can't stretch forever, you can use open strings, avoid open ... >> You can't be a serious composer and not know how the violin is tuned. ... your writing will betray your lack of knowledge of the ...
      (rec.music.compose)