home *** CD-ROM | disk | FTP | other *** search
- package sun.net.www.protocol.file;
-
- import java.io.BufferedInputStream;
- import java.io.ByteArrayInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FilePermission;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.FileNameMap;
- import java.net.URL;
- import java.security.AccessController;
- import java.security.Permission;
- import java.text.Collator;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.List;
- import sun.net.www.MessageHeader;
- import sun.net.www.MimeEntry;
- import sun.net.www.MimeTable;
- import sun.net.www.ParseUtil;
- import sun.net.www.URLConnection;
- import sun.security.action.GetBooleanAction;
- import sun.security.action.GetIntegerAction;
- import sun.security.action.GetPropertyAction;
-
- public class FileURLConnection extends URLConnection {
- static String CONTENT_LENGTH = "content-length";
- static String CONTENT_TYPE = "content-type";
- static String TEXT_HTML = "text/html";
- String contentType;
- // $FF: renamed from: is java.io.InputStream
- InputStream field_0;
- File file;
- String filename;
- boolean isDirectory = false;
- boolean exists = false;
- List files;
- long length = 0L;
- private boolean initializedHeaders = false;
- Permission permission;
-
- FileURLConnection(URL var1) {
- super(var1);
- }
-
- public void connect() throws IOException {
- if (!super.connected) {
- try {
- String var1 = ParseUtil.decode(super.url.getPath());
- this.file = new File(var1.replace('/', File.separatorChar));
- this.filename = this.file.toString();
- this.isDirectory = this.file.isDirectory();
- if (this.isDirectory) {
- this.files = Arrays.asList(this.file.list());
- } else {
- this.field_0 = new BufferedInputStream(new FileInputStream(this.filename));
- }
- } catch (IOException var2) {
- throw var2;
- }
-
- super.connected = true;
- }
-
- }
-
- private void initializeHeaders() {
- try {
- this.connect();
- this.exists = this.file.exists();
- } catch (IOException var2) {
- }
-
- if (!this.initializedHeaders || !this.exists) {
- this.length = this.file.length();
- if (!this.isDirectory) {
- FileNameMap var1 = java.net.URLConnection.getFileNameMap();
- this.contentType = var1.getContentTypeFor(this.filename);
- if (this.contentType != null) {
- super.properties.add(CONTENT_TYPE, this.contentType);
- }
-
- super.properties.add(CONTENT_LENGTH, String.valueOf(this.length));
- } else {
- super.properties.add(CONTENT_LENGTH, TEXT_HTML);
- }
-
- this.initializedHeaders = true;
- }
-
- }
-
- public String getHeaderField(String var1) {
- this.initializeHeaders();
- return super.getHeaderField(var1);
- }
-
- public String getHeaderField(int var1) {
- this.initializeHeaders();
- return super.getHeaderField(var1);
- }
-
- public int getContentLength() {
- this.initializeHeaders();
- return super.getContentLength();
- }
-
- public String getHeaderFieldKey(int var1) {
- this.initializeHeaders();
- return super.getHeaderFieldKey(var1);
- }
-
- public MessageHeader getProperties() {
- this.initializeHeaders();
- return super.getProperties();
- }
-
- public synchronized InputStream getInputStream() throws IOException {
- this.connect();
- if (this.field_0 == null) {
- int var1 = (Integer)AccessController.doPrivileged(new GetIntegerAction("hotjava.file.iconheight", 32));
- int var2 = (Integer)AccessController.doPrivileged(new GetIntegerAction("hotjava.file.iconwidth", 32));
- if (!this.isDirectory) {
- throw new FileNotFoundException(this.filename);
- }
-
- FileNameMap var3 = java.net.URLConnection.getFileNameMap();
- StringBuffer var4 = new StringBuffer();
- if (this.files == null) {
- throw new FileNotFoundException(this.filename);
- }
-
- Collections.sort(this.files, Collator.getInstance());
- var4.append("<title>");
- var4.append((String)AccessController.doPrivileged(new GetPropertyAction("file.dir.title", "Directory Listing")));
- var4.append("</title>\n");
- var4.append("<base href=\"file://localhost/");
- var4.append(this.filename.substring(this.filename.charAt(0) == '/' ? 1 : 0));
- if (this.filename.endsWith("/")) {
- var4.append("\">");
- } else {
- var4.append("/\">");
- }
-
- var4.append("<h1>");
- var4.append(this.filename);
- var4.append("</h1>\n");
- var4.append("<hr>\n");
- Boolean var5 = (Boolean)AccessController.doPrivileged(new GetBooleanAction("file.hidedotfiles"));
- boolean var6 = var5;
-
- for(int var7 = 0; var7 < this.files.size(); ++var7) {
- String var8 = (String)this.files.get(var7);
- if (!var6 || var8.indexOf(46) != 0) {
- var4.append("<img align=middle src=\"");
- if ((new File(this.filename + "/" + var8)).isDirectory()) {
- var4.append("doc:/lib/images/ftp/directory.gif\" width=" + var2 + " height=" + var1 + ">\n");
- } else {
- String var9 = "doc:/lib/images/ftp/file.gif";
- if (var3 instanceof MimeTable) {
- MimeEntry var10 = ((MimeTable)var3).findByFileName(var8);
- if (var10 != null) {
- String var11 = var10.getImageFileName();
- if (var11 != null) {
- var9 = var11;
- }
- }
- }
-
- var4.append(var9);
- var4.append("\" width=" + var2 + " height=" + var1 + ">\n");
- }
-
- var4.append("<a href=\"");
- var4.append(var8);
- var4.append("\">");
- var4.append(var8);
- var4.append("</a><br>");
- }
- }
-
- this.field_0 = new ByteArrayInputStream(var4.toString().getBytes());
- }
-
- return this.field_0;
- }
-
- public Permission getPermission() throws IOException {
- if (this.permission == null) {
- String var1 = ParseUtil.decode(super.url.getPath());
- if (File.separatorChar == '/') {
- this.permission = new FilePermission(var1, "read");
- } else {
- this.permission = new FilePermission(var1.replace('/', File.separatorChar), "read");
- }
- }
-
- return this.permission;
- }
- }
-