Skip to main content

Freeing locked files

2 replies [Last post]
paulch
Offline
Joined: 2005-03-24
Points: 0

Hi,

I am using JAI to convert a TIFF image to a PNG image. The following code works fine:

RenderedOp img = JAI.create("fileload", "my-tiff-file");
JAI.create("filestore", img, "my-png-file", "PNG");

However, after the image creation I find the source and destination files are locked in some manner (possibly open). After processing I want to move the files with File.renameTo(File) but the operation fails. If I try to move the files in Windows Explorer I get a sharing violation message which usually indicates the file is open. The files are freed once the program terminates.

I can't see anything in the API that allows me to free whatever resource is holding on to the files. Any ideas?

Thanks,
Paul

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Brian Burkhalter

Paul,

You may either:

A) deference the objects returned by JAI.create() and force garbage
collection, or
B) use the "Stream" and "Encode" operations instead and manage the closing of
the streams yourself.

I would recommend option B.

Brian

On Wed, 30 Mar 2005 jai-interest@javadesktop.org wrote:

> Hi,
>
> I am using JAI to convert a TIFF image to a PNG image. The following code works fine:
>
> RenderedOp img = JAI.create("fileload", "my-tiff-file");
> JAI.create("filestore", img, "my-png-file", "PNG");
>
> However, after the image creation I find the source and destination files are locked in some manner (possibly open). After processing I want to move the files with File.renameTo(File) but the operation fails. If I try to move the files in Windows Explorer I get a sharing violation message which usually indicates the file is open. The files are freed once the program terminates.
>
> I can't see anything in the API that allows me to free whatever resource is holding on to the files. Any ideas?
>
> Thanks,
> Paul
> ---
> [Message sent by forum member 'paulch' (Paul Chisholm)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=68458&#68458
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Advanced Development, Graphics and Media
Software Chief Technology Office
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

paulch
Offline
Joined: 2005-03-24
Points: 0

Brian,

thanks for that. I tried option A as a quick fix and it worked fine. In the longer term I will pursue option B.

Paul