Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   RAM FileDescriptor (http://www.velocityreviews.com/forums/t953395-ram-filedescriptor.html)

bob smith 10-15-2012 06:08 PM

RAM FileDescriptor
 
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?

Lew 10-15-2012 06:27 PM

Re: RAM FileDescriptor
 
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

Eric Sosman 10-15-2012 06:34 PM

Re: RAM FileDescriptor
 
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
esosman@comcast-dot-net.invalid

Jeff Higgins 10-15-2012 06:41 PM

Re: RAM FileDescriptor
 
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?

David Lamb 10-15-2012 07:07 PM

Re: RAM FileDescriptor
 
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?

Jeff Higgins 10-15-2012 07:25 PM

Re: RAM FileDescriptor
 
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()>.

Daniel Pitts 10-15-2012 07:59 PM

Re: RAM FileDescriptor
 
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.

Jeff Higgins 10-15-2012 08:22 PM

Re: RAM FileDescriptor
 
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 10-15-2012 08:26 PM

Re: RAM FileDescriptor
 
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.


Jim Janney 10-16-2012 06:40 PM

Re: RAM FileDescriptor
 
bob smith <bob@coolfone.comze.com> 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


All times are GMT. The time now is 12:17 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.