Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #19366 > unrolled thread

RAM FileDescriptor

Started bybob smith <bob@coolfone.comze.com>
First post2012-10-15 11:08 -0700
Last post2012-10-17 17:55 +0200
Articles 14 — 9 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  RAM FileDescriptor bob smith <bob@coolfone.comze.com> - 2012-10-15 11:08 -0700
    Re: RAM FileDescriptor Lew <lewbloch@gmail.com> - 2012-10-15 11:27 -0700
    Re: RAM FileDescriptor Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-15 14:34 -0400
    Re: RAM FileDescriptor Jeff Higgins <jeff@invalid.invalid> - 2012-10-15 14:41 -0400
      Re: RAM FileDescriptor David Lamb <dalamb@cs.queensu.ca> - 2012-10-15 15:07 -0400
        Re: RAM FileDescriptor Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-10-15 12:59 -0700
          Re: RAM FileDescriptor Arne Vajhoej <arne@vajhoej.dk> - 2012-10-17 11:45 -0400
            Re: RAM FileDescriptor David Lamb <dalamb@cs.queensu.ca> - 2012-10-17 15:08 -0400
      Re: RAM FileDescriptor Jeff Higgins <jeff@invalid.invalid> - 2012-10-15 15:25 -0400
    Re: RAM FileDescriptor Jeff Higgins <jeff@invalid.invalid> - 2012-10-15 16:22 -0400
      Re: RAM FileDescriptor Jeff Higgins <jeff@invalid.invalid> - 2012-10-15 16:26 -0400
    Re: RAM FileDescriptor Jim Janney <jjanney@shell.xmission.com> - 2012-10-16 12:40 -0600
    Re: RAM FileDescriptor Arne Vajhoej <arne@vajhoej.dk> - 2012-10-17 11:43 -0400
    Re: RAM FileDescriptor Jan Burse <janburse@fastmail.fm> - 2012-10-17 17:55 +0200

#19366 — RAM FileDescriptor

Frombob smith <bob@coolfone.comze.com>
Date2012-10-15 11:08 -0700
SubjectRAM FileDescriptor
Message-ID<f6d1d840-9769-447a-893e-f8cce07d2d23@googlegroups.com>
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?

[toc] | [next] | [standalone]


#19369

FromLew <lewbloch@gmail.com>
Date2012-10-15 11:27 -0700
Message-ID<5855dde7-ea94-46fb-a8aa-7012f29a9a88@googlegroups.com>
In reply to#19366
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

[toc] | [prev] | [next] | [standalone]


#19372

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2012-10-15 14:34 -0400
Message-ID<k5hkus$hs6$1@dont-email.me>
In reply to#19366
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

[toc] | [prev] | [next] | [standalone]


#19373

FromJeff Higgins <jeff@invalid.invalid>
Date2012-10-15 14:41 -0400
Message-ID<k5hl0v$i7r$1@dont-email.me>
In reply to#19366
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?

[toc] | [prev] | [next] | [standalone]


#19374

FromDavid Lamb <dalamb@cs.queensu.ca>
Date2012-10-15 15:07 -0400
Message-ID<k5hmue$vae$1@dont-email.me>
In reply to#19373
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?

[toc] | [prev] | [next] | [standalone]


#19378

FromDaniel Pitts <newsgroup.nospam@virtualinfinity.net>
Date2012-10-15 12:59 -0700
Message-ID<cWZes.20253$2h5.2462@newsfe20.iad>
In reply to#19374
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.

[toc] | [prev] | [next] | [standalone]


#19408

FromArne Vajhoej <arne@vajhoej.dk>
Date2012-10-17 11:45 -0400
Message-ID<507ed2b5$0$288$14726298@news.sunsite.dk>
In reply to#19378
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

[toc] | [prev] | [next] | [standalone]


#19411

FromDavid Lamb <dalamb@cs.queensu.ca>
Date2012-10-17 15:08 -0400
Message-ID<k5mvmg$7gb$2@dont-email.me>
In reply to#19408
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"

[toc] | [prev] | [next] | [standalone]


#19375

FromJeff Higgins <jeff@invalid.invalid>
Date2012-10-15 15:25 -0400
Message-ID<k5hnk9$4j7$1@dont-email.me>
In reply to#19373
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()>.

[toc] | [prev] | [next] | [standalone]


#19379

FromJeff Higgins <jeff@invalid.invalid>
Date2012-10-15 16:22 -0400
Message-ID<k5hquq$s6c$1@dont-email.me>
In reply to#19366
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.

[toc] | [prev] | [next] | [standalone]


#19380

FromJeff Higgins <jeff@invalid.invalid>
Date2012-10-15 16:26 -0400
Message-ID<k5hr51$tdu$1@dont-email.me>
In reply to#19379
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.

[toc] | [prev] | [next] | [standalone]


#19395

FromJim Janney <jjanney@shell.xmission.com>
Date2012-10-16 12:40 -0600
Message-ID<ydn626a2rc7.fsf@shell.xmission.com>
In reply to#19366
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

[toc] | [prev] | [next] | [standalone]


#19407

FromArne Vajhoej <arne@vajhoej.dk>
Date2012-10-17 11:43 -0400
Message-ID<507ed23c$0$288$14726298@news.sunsite.dk>
In reply to#19366
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

[toc] | [prev] | [next] | [standalone]


#19410

FromJan Burse <janburse@fastmail.fm>
Date2012-10-17 17:55 +0200
Message-ID<k5mkea$2ks$1@news.albasani.net>
In reply to#19366
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web