OutputStream from a URLConnection produces an OutOfMemory OutputStream from a URLConnection produc

Discussion in 'Java' started by WinstonSmith_101@hotmail.com, Oct 25, 2006.

  1. Guest

    OutputStream from a URLConnection produces an OutOfMemory Exception on
    large files

    I need to upload large files (up to 2 gigabytes) to an Apache
    webserver. This works fine with smaller files, however as soon as they
    go over a certain size, java dumps with a: java.lang.OutOfMemoryError:
    Java heap space.

    Apparently this is a feature. The error results from HttpURLConnection
    returning a ByteArrayOutputStream, so the file is stored in memory
    before being send to the webserver - and no amount of flushing is
    going to alter that. See e.g.
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4212479
    - this bug/feature is fairly old and here is suggested a more recent
    workaround: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5026745
    .. But this too produces an out-of-memory exception with me (and I'm not
    sure the users will have the absolutely latest Java version installed)

    Is there a way for to get this to work so I can upload larger files
    without running out of memory?

    Else I'd start experiment with this package: HTTPClient :
    http://www.innovation.ch/java/HTTPClient/

    Perhaps this can handle larger files. but I already have everything
    else working, so I'd be loathe to start to replace it all with a new
    library if there was an acceptable way to implement uploads of larger
    files just with the standard Java libraries.
    , Oct 25, 2006
    #1
    1. Advertising

  2. Thomas Weidenfeller, Oct 25, 2006
    #2
    1. Advertising

  3. Guest

    Re: OutputStream from a URLConnection produces an OutOfMemory OutputStream from a URLConnection produces an OutOfMemory

    Winston,

    My guess is that one way of solving this would be to throw memory at
    your machine;
    at least a few gigs. Then you need to modify the initial an maximum
    heap
    size when you launch your application:

    java -Xms3000m -Xmx3000m -classpath rt.jar:someclasspath
    YourApplication

    If you don't have memory, then I would think about redesigning your
    code
    to see if you could do it with some object like a BufferedOutputStream
    with
    a FileWriter.

    Morris
    Generatormart, LLC.
    http://www.generatormart.com
    Diesel generator classified ads.



    wrote:
    > OutputStream from a URLConnection produces an OutOfMemory Exception on
    > large files
    >
    > I need to upload large files (up to 2 gigabytes) to an Apache
    > webserver. This works fine with smaller files, however as soon as they
    > go over a certain size, java dumps with a: java.lang.OutOfMemoryError:
    > Java heap space.
    >
    > Apparently this is a feature. The error results from HttpURLConnection
    > returning a ByteArrayOutputStream, so the file is stored in memory
    > before being send to the webserver - and no amount of flushing is
    > going to alter that. See e.g.
    > http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4212479
    > - this bug/feature is fairly old and here is suggested a more recent
    > workaround: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5026745
    > . But this too produces an out-of-memory exception with me (and I'm not
    > sure the users will have the absolutely latest Java version installed)
    >
    > Is there a way for to get this to work so I can upload larger files
    > without running out of memory?
    >
    > Else I'd start experiment with this package: HTTPClient :
    > http://www.innovation.ch/java/HTTPClient/
    >
    > Perhaps this can handle larger files. but I already have everything
    > else working, so I'd be loathe to start to replace it all with a new
    > library if there was an acceptable way to implement uploads of larger
    > files just with the standard Java libraries.
    , Oct 25, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. LP

    System.OutOfMemory Exception

    LP, Jan 21, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    12,149
    Tad Marshall
    Apr 9, 2005
  2. vMike

    system.outofmemory exception

    vMike, Oct 30, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,126
    vMike
    Oct 30, 2003
  3. =?Utf-8?B?Umlja3kgQ2hhbg==?=

    OutofMemory Exception Throw

    =?Utf-8?B?Umlja3kgQ2hhbg==?=, Jul 6, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    522
    JIMCO Software
    Sep 9, 2005
  4. =?Utf-8?B?Umlja3kgQ2hhbg==?=

    How to force outofmemory exception throw

    =?Utf-8?B?Umlja3kgQ2hhbg==?=, Jul 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,218
    Mike Labosh
    Jul 8, 2005
  5. Joe Ross
    Replies:
    0
    Views:
    591
    Joe Ross
    Aug 30, 2005
Loading...

Share This Page