RAM FileDescriptor

Discussion in 'Java' started by bob smith, Oct 15, 2012.

  1. bob smith

    bob smith Guest

    Let's say you have a function that plays a movie that is passed in as a FileDescriptor. Is there any way to load the movie into RAM and get a FileDescriptor for the RAM?
     
    bob smith, Oct 15, 2012
    #1
    1. Advertising

  2. bob smith

    Lew Guest

    bob smith wrote:
    > Let's say you have a function that plays a movie that is passed in as a FileDescriptor.


    That seems like a really bad way to pass in such a thing.

    > Is there any way to load the movie into RAM and get a FileDescriptor for the RAM?


    You really shouldn't use 'FileDescriptor'. Haven't others commented on this to you before?

    "The main practical use for a file descriptor is to create a FileInputStream or FileOutputStream to contain it.
    Applications should not create their own file descriptors."

    So you want to ignore that advice why?

    Anyway, to answer your question, you load it into RAM the same way you would any
    'FileInputStream'.

    Create one around your 'FileDescriptor' and continue as you should have in the first place
    from the stream.

    To put it another way, create the stream first, then pass it into your file handler routine.

    process( new FileInputStream( fileDescriptorIShouldNotHaveUsed ));

    and thus

    public void process( InputStream input ) throws IOException { ... }

    --
    Lew
     
    Lew, Oct 15, 2012
    #2
    1. Advertising

  3. bob smith

    Eric Sosman Guest

    On 10/15/2012 2:08 PM, bob smith wrote:
    > Let's say you have a function that plays a movie that
    > is passed in as a FileDescriptor.


    Okay: "You have a function that ..."

    Why would you want to write such a method? As I understand
    the Javadoc, the method could only get at the bytes behind the
    FileDescriptor by constructing a FileInputStream from it, then
    reading the FileInputStream. Why not have the method take a
    FileInputStream in the first place? Better yet, why not have
    it take an InputStream, and not insist on the "file" part?

    > Is there any way to load the movie into RAM and get a
    > FileDescriptor for the RAM?


    Probably not. A method that took an InputStream could,
    of course, be given a ByteArrayInputStream -- but if you're
    dead-set on using FileDescriptor, I think you're out of luck.

    --
    Eric Sosman
    d
     
    Eric Sosman, Oct 15, 2012
    #3
  4. bob smith

    Jeff Higgins Guest

    On 10/15/2012 02:08 PM, bob smith wrote:
    > Let's say you have a function that plays a movie that is passed in as a FileDescriptor. Is there any way to load the movie into RAM and get a FileDescriptor for the RAM?

    Looking here:
    <http://docs.oracle.com/javase/7/docs/api/java/io/class-use/FileDescriptor.html>
    the most likely route seems to be java.io.RandomAccessFile.getFD(). But
    I don't know what "a FileDescriptor for the RAM" means. Will you clarify?
     
    Jeff Higgins, Oct 15, 2012
    #4
  5. bob smith

    David Lamb Guest

    On 15/10/2012 2:41 PM, Jeff Higgins wrote:
    > On 10/15/2012 02:08 PM, bob smith wrote:
    >> Let's say you have a function that plays a movie that is passed in as
    >> a FileDescriptor. Is there any way to load the movie into RAM and get
    >> a FileDescriptor for the RAM?

    > Looking here:
    > <http://docs.oracle.com/javase/7/docs/api/java/io/class-use/FileDescriptor.html>
    > the most likely route seems to be java.io.RandomAccessFile.getFD(). But
    > I don't know what "a FileDescriptor for the RAM" means. Will you clarify?


    I doubt it exists as a general concept and thus probably doesn't exist
    in Java. I seem to recall that some operating systems from many years
    ago let you map a file into RAM and operate on it from there, but I'm
    moderately sure that feature either went through the standard file
    system stuff and was (nearly) invisible, or you accessed a massive byte
    array directly. The former corresponds to people's advice to use a
    FileInputStream amd the latter to a ByteInputStream as appropriate.

    Wouldn't your movie exceed the capacity of RAM? or are you limiting
    yourself to short ones?
     
    David Lamb, Oct 15, 2012
    #5
  6. bob smith

    Jeff Higgins Guest

    On 10/15/2012 02:41 PM, Jeff Higgins wrote:
    > On 10/15/2012 02:08 PM, bob smith wrote:
    >> Let's say you have a function that plays a movie that is passed in as
    >> a FileDescriptor. Is there any way to load the movie into RAM and get
    >> a FileDescriptor for the RAM?

    > Looking here:
    > <http://docs.oracle.com/javase/7/docs/api/java/io/class-use/FileDescriptor.html>
    > the most likely route seems to be java.io.RandomAccessFile.getFD(). But
    > I don't know what "a FileDescriptor for the RAM" means. Will you clarify?

    I'm also not sure what "load the movie into RAM" means to you or for
    that matter to the standard Java libraries. For instance, see the class
    description for MappedByteBuffer:
    <http://docs.oracle.com/javase/7/docs/api/java/nio/MappedByteBuffer.html>,
    and its isLoaded() method
    <http://docs.oracle.com/javase/7/docs/api/java/nio/MappedByteBuffer.html#isLoaded()>.
     
    Jeff Higgins, Oct 15, 2012
    #6
  7. bob smith

    Daniel Pitts Guest

    On 10/15/12 12:07 PM, David Lamb wrote:
    > On 15/10/2012 2:41 PM, Jeff Higgins wrote:
    >> On 10/15/2012 02:08 PM, bob smith wrote:
    >>> Let's say you have a function that plays a movie that is passed in as
    >>> a FileDescriptor. Is there any way to load the movie into RAM and get
    >>> a FileDescriptor for the RAM?

    >> Looking here:
    >> <http://docs.oracle.com/javase/7/docs/api/java/io/class-use/FileDescriptor.html>
    >>
    >> the most likely route seems to be java.io.RandomAccessFile.getFD(). But
    >> I don't know what "a FileDescriptor for the RAM" means. Will you clarify?

    >
    > I doubt it exists as a general concept and thus probably doesn't exist
    > in Java. I seem to recall that some operating systems from many years
    > ago let you map a file into RAM and operate on it from there, but I'm
    > moderately sure that feature either went through the standard file
    > system stuff and was (nearly) invisible, or you accessed a massive byte
    > array directly.

    Java's NIO does actually have this capability (for example, in
    MappedByteBuffer)

    <http://docs.oracle.com/javase/7/docs/api/java/nio/MappedByteBuffer.html>


    > The former corresponds to people's advice to use a
    > FileInputStream amd the latter to a ByteInputStream as appropriate.
    >
    > Wouldn't your movie exceed the capacity of RAM? or are you limiting
    > yourself to short ones?



    I would say that the method shouldn't require a specific subclass of
    InputStream, but *all* of them. *or* it should take a class which
    supports random-access to the data (abstracted from whether it does so
    by reading the entire data set into memory, or uses a file, or as
    YouTube and other plays do, buffers the network data as it comes in).

    FWIW, modern systems don't need to load video data into memory to get a
    reliable output. The compressed data is "small enough" compared to the
    expected throughput that buffering (other than some base level, such as
    OS) the uncompressed data in memory makes little sense.
     
    Daniel Pitts, Oct 15, 2012
    #7
  8. bob smith

    Jeff Higgins Guest

    On 10/15/2012 02:08 PM, bob smith wrote:
    > Let's say you have a function that plays a movie that is passed in as a FileDescriptor. Is there any way to load the movie into RAM and get a FileDescriptor for the RAM?

    Another idea might be might be to use the JavaFX MediaPlayer, although I
    haven't tried it yet so I don't know how it works.
     
    Jeff Higgins, Oct 15, 2012
    #8
  9. bob smith

    Jeff Higgins Guest

    On 10/15/2012 04:22 PM, Jeff Higgins wrote:
    > On 10/15/2012 02:08 PM, bob smith wrote:
    >> Let's say you have a function that plays a movie that is passed in as
    >> a FileDescriptor. Is there any way to load the movie into RAM and get
    >> a FileDescriptor for the RAM?

    > Another idea might be might be to use the JavaFX MediaPlayer, although I
    > haven't tried it yet so I don't know how it works.

    That is, to escape all of the RAM/FileDescriptor stuff.
     
    Jeff Higgins, Oct 15, 2012
    #9
  10. bob smith

    Jim Janney Guest

    bob smith <> writes:

    > Let's say you have a function that plays a movie that is passed in as a FileDescriptor. Is there any way to load the movie into RAM and get a FileDescriptor for the RAM?


    Let's assume it's a short movie and only takes 30 minutes to play. How
    much time do you save by loading it into RAM?

    --
    Jim Janney
     
    Jim Janney, Oct 16, 2012
    #10
  11. bob smith

    Arne Vajhoej Guest

    On 10/15/2012 2:08 PM, bob smith wrote:
    > Let's say you have a function that plays a movie that is passed in as
    > a FileDescriptor. Is there any way to load the movie into RAM and
    > get a FileDescriptor for the RAM?


    FileDescriptor is a file thingy.

    File systems are really out of scope for Java.

    So use your operating systems ways of creating and mounting
    a file system in memory, copy the movie to that and let Java
    read it as any other file.

    Arne
     
    Arne Vajhoej, Oct 17, 2012
    #11
  12. bob smith

    Arne Vajhoej Guest

    On 10/15/2012 3:59 PM, Daniel Pitts wrote:
    > On 10/15/12 12:07 PM, David Lamb wrote:
    >> I doubt it exists as a general concept and thus probably doesn't exist
    >> in Java. I seem to recall that some operating systems from many years
    >> ago let you map a file into RAM and operate on it from there, but I'm
    >> moderately sure that feature either went through the standard file
    >> system stuff and was (nearly) invisible, or you accessed a massive byte
    >> array directly.

    > Java's NIO does actually have this capability (for example, in
    > MappedByteBuffer)
    >
    > <http://docs.oracle.com/javase/7/docs/api/java/nio/MappedByteBuffer.html>


    At least it maps files into virtual address space.

    Which is probably what David was talking about.

    But strictly speaking it is not mapping into RAM.

    Arne
     
    Arne Vajhoej, Oct 17, 2012
    #12
  13. bob smith

    Jan Burse Guest

    bob smith schrieb:
    > Let's say you have a function that plays a movie that is passed in as a FileDescriptor. Is there any way to load the movie into RAM and get a FileDescriptor for the RAM?
    >


    Hi,

    I asked a similar question once here. Some troll-o-mat
    answers and also some answers that were later replicated
    here were flowing in:

    http://stackoverflow.com/questions/8436688/memory-stream-in-java

    The ideal solution for me has yet not been found, and I
    was to lazy to implement some so far, but maybe some of
    the solutions in the above link suite you.

    Bye
     
    Jan Burse, Oct 17, 2012
    #13
  14. bob smith

    David Lamb Guest

    On 17/10/2012 11:45 AM, Arne Vajhoej wrote:
    > On 10/15/2012 3:59 PM, Daniel Pitts wrote:
    >> On 10/15/12 12:07 PM, David Lamb wrote:
    >>> I doubt it exists as a general concept and thus probably doesn't exist
    >>> in Java. I seem to recall that some operating systems from many years
    >>> ago let you map a file into RAM and operate on it from there, but I'm
    >>> moderately sure that feature either went through the standard file
    >>> system stuff and was (nearly) invisible, or you accessed a massive byte
    >>> array directly.

    >> Java's NIO does actually have this capability (for example, in
    >> MappedByteBuffer)
    >>
    >> <http://docs.oracle.com/javase/7/docs/api/java/nio/MappedByteBuffer.html>

    >
    > At least it maps files into virtual address space.
    >
    > Which is probably what David was talking about.


    Yes; I unfortunately often leave out necessary context.

    > But strictly speaking it is not mapping into RAM.


    You're right, and I did mistakenly reuse the OP's 'RAM' instead of the
    correct "virtual memory"
     
    David Lamb, Oct 17, 2012
    #14
    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. Robert Posey
    Replies:
    0
    Views:
    696
    Robert Posey
    Nov 26, 2003
  2. Paolo Invernizzi

    filedescriptor out of range in select()

    Paolo Invernizzi, Jun 26, 2003, in forum: Python
    Replies:
    0
    Views:
    927
    Paolo Invernizzi
    Jun 26, 2003
  3. ashu
    Replies:
    1
    Views:
    483
  4. ashu
    Replies:
    2
    Views:
    641
    mysticlol
    Nov 6, 2006
  5. Xin Xiao

    Block RAM Distributed RAM

    Xin Xiao, Jan 7, 2008, in forum: VHDL
    Replies:
    8
    Views:
    1,510
    Duane Clark
    Jan 7, 2008
Loading...

Share This Page