Methods Summary |
---|
public void | connect()This methods will attempt to obtain the input stream of the file pointed
by this URL . If the file is a directory, it will return
that directory listing as an input stream.
File f = new File(fileName);
if (f.isDirectory()) {
isDir = true;
is = getDirectoryListing(f);
// use -1 for the contentLength
} else {
// BEGIN android-modified
is = new BufferedInputStream(new FileInputStream(f), 8192);
// END android-modified
length = is.available();
}
connected = true;
|
public int | getContentLength()Returns the length of the file in bytes.
try {
if (!connected) {
connect();
}
} catch (IOException e) {
// default is -1
}
return length;
|
public java.lang.String | getContentType()Returns the content type of the resource. Just takes a guess based on the
name.
try {
if (!connected) {
connect();
}
} catch (IOException e) {
return MimeTable.UNKNOWN;
}
if (isDir) {
return "text/html"; //$NON-NLS-1$
}
String result = guessContentTypeFromName(url.getFile());
if (result == null) {
return MimeTable.UNKNOWN;
}
return result;
|
private java.io.InputStream | getDirectoryListing(java.io.File f)Returns the directory listing of the file component as an input stream.
String fileList[] = f.list();
ByteArrayOutputStream bytes = new java.io.ByteArrayOutputStream();
PrintStream out = new PrintStream(bytes);
out.print("<title>Directory Listing</title>\n"); //$NON-NLS-1$
out.print("<base href=\"file:"); //$NON-NLS-1$
out.print(f.getPath().replace('\\", '/") + "/\"><h1>" + f.getPath() //$NON-NLS-1$
+ "</h1>\n<hr>\n"); //$NON-NLS-1$
int i;
for (i = 0; i < fileList.length; i++) {
out.print(fileList[i] + "<br>\n"); //$NON-NLS-1$
}
out.close();
return new ByteArrayInputStream(bytes.toByteArray());
|
public java.io.InputStream | getInputStream()Returns the input stream of the object referred to by this
URLConnection
File Sample : "/ZIP211/+/harmony/tools/javac/resources/javac.properties"
Invalid File Sample:
"/ZIP/+/harmony/tools/javac/resources/javac.properties"
"ZIP211/+/harmony/tools/javac/resources/javac.properties"
if (!connected) {
connect();
}
return is;
|
public java.security.Permission | getPermission()Returns the permission, in this case the subclass, FilePermission object
which represents the permission necessary for this URLConnection to
establish the connection.
if (permission == null) {
String path = fileName;
if (File.separatorChar != '/") {
path = path.replace('/", File.separatorChar);
}
permission = new FilePermission(path, "read"); //$NON-NLS-1$
}
return permission;
|