RAM FileDescriptor

B

bob smith

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?
 
L

Lew

bob said:
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 { ... }
 
E

Eric Sosman

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.
 
D

David Lamb

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?
 
J

Jeff Higgins

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()>.
 
D

Daniel Pitts

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)

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.
 
J

Jeff Higgins

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.
 
J

Jeff Higgins

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.
 
J

Jim Janney

bob smith said:
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?
 
A

Arne Vajhoej

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
 
J

Jan Burse

bob said:
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
 
D

David Lamb

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"
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top