Methods Summary |
---|
private synchronized void | close()Closes the URL connection if:
- it is opened (i.e. the field conn is not null)
- this type of URLConnection supports some sort of close mechanism
This method ensures the field conn will be null after the call.
if (conn != null) {
try {
if (conn instanceof JarURLConnection) {
JarURLConnection juc = (JarURLConnection) conn;
JarFile jf = juc.getJarFile();
jf.close();
jf = null;
} else if (conn instanceof HttpURLConnection) {
((HttpURLConnection) conn).disconnect();
}
} catch (IOException exc) {
//ignore
} finally {
conn = null;
}
}
|
protected synchronized void | connect()Ensure that we have a connection.
URL u = getURL();
if (u == null) {
throw new BuildException("URL not set");
}
if (conn == null) {
try {
conn = u.openConnection();
conn.connect();
} catch (IOException e) {
log(e.toString(), Project.MSG_ERR);
conn = null;
throw e;
}
}
|
public synchronized boolean | equals(java.lang.Object another)Test whether an Object equals this URLResource.
if (this == another) {
return true;
}
if (isReference()) {
return getCheckedRef().equals(another);
}
if (!(another.getClass().equals(getClass()))) {
return false;
}
URLResource otheru = (URLResource) another;
return getURL() == null
? otheru.getURL() == null
: getURL().equals(otheru.getURL());
|
public synchronized java.io.InputStream | getInputStream()Get an InputStream for the Resource.
if (isReference()) {
return ((Resource) getCheckedRef()).getInputStream();
}
connect();
try {
return conn.getInputStream();
} finally {
conn = null;
}
|
public synchronized long | getLastModified()Tells the modification time in milliseconds since 01.01.1970 .
if (isReference()) {
return ((Resource) getCheckedRef()).getLastModified();
}
if (!isExists(false)) {
return 0L;
}
return conn.getLastModified();
|
public synchronized java.lang.String | getName()Get the name of this URLResource
(its file component minus the leading separator).
return isReference() ? ((Resource) getCheckedRef()).getName()
: getURL().getFile().substring(1);
|
public synchronized java.io.OutputStream | getOutputStream()Get an OutputStream for the Resource.
if (isReference()) {
return ((Resource) getCheckedRef()).getOutputStream();
}
connect();
try {
return conn.getOutputStream();
} finally {
conn = null;
}
|
public synchronized long | getSize()Get the size of this Resource.
if (isReference()) {
return ((Resource) getCheckedRef()).getSize();
}
if (!isExists(false)) {
return 0L;
}
try {
connect();
long contentlength = conn.getContentLength();
close();
return contentlength;
} catch (IOException e) {
return UNKNOWN_SIZE;
}
|
public synchronized java.net.URL | getURL()Get the URL used by this URLResource.
if (isReference()) {
return ((URLResource) getCheckedRef()).getURL();
}
return url;
|
public synchronized int | hashCode()Get the hash code for this Resource.
if (isReference()) {
return getCheckedRef().hashCode();
}
return MAGIC * ((getURL() == null) ? NULL_URL : getURL().hashCode());
|
public synchronized boolean | isDirectory()Tells if the resource is a directory.
return isReference()
? ((Resource) getCheckedRef()).isDirectory()
: getName().endsWith("/");
|
public synchronized boolean | isExists()Find out whether the URL exists .
if (isReference()) {
return ((Resource) getCheckedRef()).isExists();
}
return isExists(false);
|
private synchronized boolean | isExists(boolean closeConnection)Find out whether the URL exists, and close the connection
opened to the URL if closeConnection is true.
Note that this method does ensure that if:
- the resource exists (if it returns true)
- and if the current object is not a reference
(isReference() returns false)
- and if it was called with closeConnection to false,
then the connection to the URL (stored in the conn
private field) will be opened, and require to be closed
by the caller.
if (getURL() == null) {
return false;
}
try {
connect();
return true;
} catch (IOException e) {
return false;
} finally {
if (closeConnection) {
close();
}
}
|
private static java.net.URL | newURL(java.lang.String u)
try {
return new URL(u);
} catch (MalformedURLException e) {
throw new BuildException(e);
}
|
public synchronized void | setFile(java.io.File f)Set the URL from a File.
try {
setURL(FILE_UTILS.getFileURL(f));
} catch (MalformedURLException e) {
throw new BuildException(e);
}
|
public synchronized void | setRefid(org.apache.tools.ant.types.Reference r)Overrides the super version.
//not using the accessor in this case to avoid side effects
if (url != null) {
throw tooManyAttributes();
}
super.setRefid(r);
|
public synchronized void | setURL(java.net.URL u)Set the URL for this URLResource.
checkAttributesAllowed();
url = u;
|
public synchronized java.lang.String | toString()Return this URLResource formatted as a String.
return isReference()
? getCheckedRef().toString() : String.valueOf(getURL());
|