×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Super Contributor
    Join Date
    Feb 2004
    Location
    Dallas
    Posts
    605

    Reading MediaContent and converting into B64

    I am reading the file system for media files.
    Now i want to read a particular media file(audio/video or pic) and store it in byte array(B64 converted) .
    When i try doing it using inputStream, i always get outofMemoryException because the media file size is big.

    Is there a mechanism(or code) where in i can give the inputstream on media and it can be done in chunks i.e. some B64 utility which can take inputstream and populate byte[] out of it ..and also take care of big size.

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Reading MediaContent and converting into B64

    Since your media size is too big to be entirely handled in Java memory, you must find some alternative solutions:

    * if you access network media, you could use RTSP streaming (where supported)
    * otherwise, you could split your media in smaller pieces and playback one after the other (for audio/video media).. not optimal, but often used where RTSP is not supported
    * for pics, if they're too big for Java heap memory, the only thing you can do is to resize them

    If your task is only to locally save media, you could instead use a progressive download & save approach, saving chunks of bytes one after the other (so, without the need to handle the whole media all at once).

    Pit

  3. #3
    Super Contributor
    Join Date
    Feb 2004
    Location
    Dallas
    Posts
    605

    Re: Reading MediaContent and converting into B64

    zappit, i dont need to play ..or download..
    i need to upload .and i have to upload in a defined xml format ..so i need the whole mediaContent in byte[].
    I need a mechanism wherein i can convert a media on device(local file system) into a B64 byte[].
    So i need a reading mechanism and converting to B64 mechanism both of which should handle large size( doing magic internally of breaking it and converting ..but interface should be able to take big) .
    If someone has already done it(it is quite common i think) ..so thought of posting it here ..!

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Reading MediaContent and converting into B64

    About the Base64 encoding, you could take a look here:

    http://forum.java.sun.com/thread.jsp...hreadID=665487
    http://www.bouncycastle.org/

    About the large data handling, it's not a matter of interfaces: you should progressively process (load/convert/upload) it, to avoid it to overflow Java heap memory.

    Pit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×