public final class URLTempFile
extends java.lang.Object
URLTempFile
class is to provide a
local File
reference to a document whose location is
specified by some URL
.
If the URL
does not already point to a local file, the
URLTempFile
instance will copy the document at the
URL
to a local temporary file and provide a File
instance corresponding to that temporary file. Then when the
URLTempFile
object is garbage colected or when the
Java VM exits, the temporary file is deleted automatically.
However, if the specified URL
already points to a local
file, then URLTempFile
will provide a File
instance that points directly to the existing file without
performing any copying. In this case, the underlying file will
not be deleted by URLTempFile
, even when the
URLTempFile
object is garbage collected or the Java VM
exits.
To obtain a File
reference to the URL
content,
call the getFile()
method. Subsequent calls to
getFile
will update the locally cached content if
necessary. The returned File
may be null
if
there was a problem with getting the content.
Constructor and Description |
---|
URLTempFile(java.net.URL url)
Creates a new
URLTempFile . |
Modifier and Type | Method and Description |
---|---|
protected void |
finalize()
When the
URLTempFile is garbage collected, any
temporary file that was created needs to be cleaned up. |
java.io.File |
getFile()
Returns a
File instance pointing to the document in the
local file system that has the same content as the document at
the URL specified in the constructor. |
boolean |
tempWasCreated()
Returns
true if a temporary file was acutally created
in the process of providing the File object. |
public URLTempFile(java.net.URL url)
URLTempFile
.url
- The URL
of the document for which a local
File
reference is required. If the URL is null, then the
File object will also be null.public java.io.File getFile()
File
instance pointing to the document in the
local file system that has the same content as the document at
the URL
specified in the constructor. This may return
null
if a temporary file could not be created for
some reason.public boolean tempWasCreated()
true
if a temporary file was acutally created
in the process of providing the File
object. Returns
false
if the File
points to the exact same
document as the URL
.protected void finalize()
URLTempFile
is garbage collected, any
temporary file that was created needs to be cleaned up.finalize
in class java.lang.Object