home *** CD-ROM | disk | FTP | other *** search
- package java.net;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.Date;
- import java.util.Hashtable;
-
- public abstract class URLConnection {
- protected URL url;
- protected boolean doInput = true;
- protected boolean doOutput = false;
- private static boolean defaultAllowUserInteraction;
- protected boolean allowUserInteraction;
- private static boolean defaultUseCaches = true;
- protected boolean useCaches;
- protected long ifModifiedSince;
- protected boolean connected;
- static ContentHandlerFactory factory;
- private static Hashtable handlers = new Hashtable();
- private static ContentHandler UnknownContentHandlerP = new UnknownContentHandler();
- private static String content_class_prefix = "sun.net.www.content.";
- static Hashtable extension_map = new Hashtable();
-
- public abstract void connect() throws IOException;
-
- protected URLConnection(URL url) {
- this.allowUserInteraction = defaultAllowUserInteraction;
- this.useCaches = defaultUseCaches;
- this.connected = false;
- this.url = url;
- }
-
- public URL getURL() {
- return this.url;
- }
-
- public int getContentLength() {
- return this.getHeaderFieldInt("content-length", -1);
- }
-
- public String getContentType() {
- return this.getHeaderField("content-type");
- }
-
- public String getContentEncoding() {
- return this.getHeaderField("content-encoding");
- }
-
- public long getExpiration() {
- return this.getHeaderFieldDate("expires", 0L);
- }
-
- public long getDate() {
- return this.getHeaderFieldDate("date", 0L);
- }
-
- public long getLastModified() {
- return this.getHeaderFieldDate("last-modified", 0L);
- }
-
- public String getHeaderField(String name) {
- return null;
- }
-
- public int getHeaderFieldInt(String name, int Default) {
- try {
- return Integer.parseInt(this.getHeaderField(name));
- } catch (Throwable var3) {
- return Default;
- }
- }
-
- public long getHeaderFieldDate(String name, long Default) {
- try {
- return Date.parse(this.getHeaderField(name));
- } catch (Throwable var4) {
- return Default;
- }
- }
-
- public String getHeaderFieldKey(int n) {
- return null;
- }
-
- public String getHeaderField(int n) {
- return null;
- }
-
- public Object getContent() throws IOException {
- return this.getContentHandler().getContent(this);
- }
-
- public InputStream getInputStream() throws IOException {
- throw new UnknownServiceException("protocol doesn't support input");
- }
-
- public OutputStream getOutputStream() throws IOException {
- throw new UnknownServiceException("protocol doesn't support output");
- }
-
- public String toString() {
- return this.getClass().getName() + ":" + this.url;
- }
-
- public void setDoInput(boolean doinput) {
- if (this.connected) {
- throw new IllegalAccessError("Already connected");
- } else {
- this.doInput = doinput;
- }
- }
-
- public boolean getDoInput() {
- return this.doInput;
- }
-
- public void setDoOutput(boolean dooutput) {
- if (this.connected) {
- throw new IllegalAccessError("Already connected");
- } else {
- this.doOutput = dooutput;
- }
- }
-
- public boolean getDoOutput() {
- return this.doOutput;
- }
-
- public void setAllowUserInteraction(boolean allowuserinteraction) {
- if (this.connected) {
- throw new IllegalAccessError("Already connected");
- } else {
- this.allowUserInteraction = allowuserinteraction;
- }
- }
-
- public boolean getAllowUserInteraction() {
- return this.allowUserInteraction;
- }
-
- public static void setDefaultAllowUserInteraction(boolean defaultallowuserinteraction) {
- defaultAllowUserInteraction = defaultallowuserinteraction;
- }
-
- public static boolean getDefaultAllowUserInteraction() {
- return defaultAllowUserInteraction;
- }
-
- public void setUseCaches(boolean usecaches) {
- if (this.connected) {
- throw new IllegalAccessError("Already connected");
- } else {
- this.useCaches = usecaches;
- }
- }
-
- public boolean getUseCaches() {
- return this.useCaches;
- }
-
- public void setIfModifiedSince(long ifmodifiedsince) {
- if (this.connected) {
- throw new IllegalAccessError("Already connected");
- } else {
- this.ifModifiedSince = ifmodifiedsince;
- }
- }
-
- public long getIfModifiedSince() {
- return this.ifModifiedSince;
- }
-
- public boolean getDefaultUseCaches() {
- return defaultUseCaches;
- }
-
- public void setDefaultUseCaches(boolean defaultusecaches) {
- defaultUseCaches = defaultusecaches;
- }
-
- public void setRequestProperty(String key, String value) {
- if (this.connected) {
- throw new IllegalAccessError("Already connected");
- }
- }
-
- public String getRequestProperty(String key) {
- if (this.connected) {
- throw new IllegalAccessError("Already connected");
- } else {
- return null;
- }
- }
-
- public static void setDefaultRequestProperty(String key, String value) {
- }
-
- public static String getDefaultRequestProperty(String key) {
- return null;
- }
-
- public static synchronized void setContentHandlerFactory(ContentHandlerFactory fac) {
- if (factory != null) {
- throw new Error("factory already defined");
- } else {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkSetFactory();
- }
-
- factory = fac;
- }
- }
-
- synchronized ContentHandler getContentHandler() throws UnknownServiceException {
- String contentType = this.getContentType();
- ContentHandler handler = null;
- if (contentType == null) {
- throw new UnknownServiceException("no content-type");
- } else {
- try {
- handler = (ContentHandler)handlers.get(contentType);
- if (handler != null) {
- return handler;
- }
- } catch (Exception var9) {
- }
-
- if (factory != null) {
- handler = factory.createContentHandler(contentType);
- }
-
- if (handler == null) {
- try {
- int i = content_class_prefix.length();
- int j = contentType.length();
- char[] nm = new char[i + j];
- content_class_prefix.getChars(0, i, nm, 0);
- contentType.getChars(0, j, nm, i);
-
- while(true) {
- --j;
- if (j < 0) {
- String name = new String(nm);
-
- try {
- handler = (ContentHandler)Class.forName(name).newInstance();
- } catch (Exception e) {
- ((Throwable)e).printStackTrace();
- handler = UnknownContentHandlerP;
- }
- break;
- }
-
- char c = nm[i];
- if (c == '/') {
- nm[i] = '.';
- } else if ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9')) {
- nm[i] = '_';
- }
-
- ++i;
- }
- } catch (Exception e) {
- ((Throwable)e).printStackTrace();
- handler = UnknownContentHandlerP;
- }
-
- handlers.put(contentType, handler);
- }
-
- return handler;
- }
- }
-
- protected static String guessContentTypeFromName(String fname) {
- String ext = "";
- int i = fname.lastIndexOf(35);
- if (i != -1) {
- fname = fname.substring(0, i - 1);
- }
-
- i = fname.lastIndexOf(46);
- i = Math.max(i, fname.lastIndexOf(47));
- i = Math.max(i, fname.lastIndexOf(63));
- if (i != -1 && fname.charAt(i) == '.') {
- ext = fname.substring(i).toLowerCase();
- }
-
- return (String)extension_map.get(ext);
- }
-
- private static void setSuffix(String ext, String ct) {
- extension_map.put(ext, ct);
- }
-
- protected static String guessContentTypeFromStream(InputStream is) throws IOException {
- is.mark(10);
- int c1 = is.read();
- int c2 = is.read();
- int c3 = is.read();
- int c4 = is.read();
- int c5 = is.read();
- int c6 = is.read();
- is.reset();
- if (c1 == 71 && c2 == 73 && c3 == 70 && c4 == 56) {
- return "image/gif";
- } else if (c1 == 35 && c2 == 100 && c3 == 101 && c4 == 102) {
- return "image/x-bitmap";
- } else if (c1 == 33 && c2 == 32 && c3 == 88 && c4 == 80 && c5 == 77 && c6 == 50) {
- return "image/x-pixmap";
- } else {
- return c1 != 60 || c2 != 33 && (c6 != 62 || (c2 != 104 || (c3 != 116 || c4 != 109 || c5 != 108) && (c3 != 101 || c4 != 97 || c5 != 100)) && (c2 != 98 || c3 != 111 || c4 != 100 || c5 != 121)) ? null : "text/html";
- }
- }
-
- static {
- setSuffix("", "content/unknown");
- setSuffix(".uu", "application/octet-stream");
- setSuffix(".saveme", "application/octet-stream");
- setSuffix(".dump", "application/octet-stream");
- setSuffix(".hqx", "application/octet-stream");
- setSuffix(".arc", "application/octet-stream");
- setSuffix(".o", "application/octet-stream");
- setSuffix(".a", "application/octet-stream");
- setSuffix(".bin", "application/octet-stream");
- setSuffix(".exe", "application/octet-stream");
- setSuffix(".z", "application/octet-stream");
- setSuffix(".gz", "application/octet-stream");
- setSuffix(".oda", "application/oda");
- setSuffix(".pdf", "application/pdf");
- setSuffix(".eps", "application/postscript");
- setSuffix(".ai", "application/postscript");
- setSuffix(".ps", "application/postscript");
- setSuffix(".rtf", "application/rtf");
- setSuffix(".dvi", "application/x-dvi");
- setSuffix(".hdf", "application/x-hdf");
- setSuffix(".latex", "application/x-latex");
- setSuffix(".cdf", "application/x-netcdf");
- setSuffix(".nc", "application/x-netcdf");
- setSuffix(".tex", "application/x-tex");
- setSuffix(".texinfo", "application/x-texinfo");
- setSuffix(".texi", "application/x-texinfo");
- setSuffix(".t", "application/x-troff");
- setSuffix(".tr", "application/x-troff");
- setSuffix(".roff", "application/x-troff");
- setSuffix(".man", "application/x-troff-man");
- setSuffix(".me", "application/x-troff-me");
- setSuffix(".ms", "application/x-troff-ms");
- setSuffix(".src", "application/x-wais-source");
- setSuffix(".wsrc", "application/x-wais-source");
- setSuffix(".zip", "application/zip");
- setSuffix(".bcpio", "application/x-bcpio");
- setSuffix(".cpio", "application/x-cpio");
- setSuffix(".gtar", "application/x-gtar");
- setSuffix(".shar", "application/x-shar");
- setSuffix(".sh", "application/x-shar");
- setSuffix(".sv4cpio", "application/x-sv4cpio");
- setSuffix(".sv4crc", "application/x-sv4crc");
- setSuffix(".tar", "application/x-tar");
- setSuffix(".ustar", "application/x-ustar");
- setSuffix(".snd", "audio/basic");
- setSuffix(".au", "audio/basic");
- setSuffix(".aifc", "audio/x-aiff");
- setSuffix(".aif", "audio/x-aiff");
- setSuffix(".aiff", "audio/x-aiff");
- setSuffix(".wav", "audio/x-wav");
- setSuffix(".gif", "image/gif");
- setSuffix(".ief", "image/ief");
- setSuffix(".jfif", "image/jpeg");
- setSuffix(".jfif-tbnl", "image/jpeg");
- setSuffix(".jpe", "image/jpeg");
- setSuffix(".jpg", "image/jpeg");
- setSuffix(".jpeg", "image/jpeg");
- setSuffix(".tif", "image/tiff");
- setSuffix(".tiff", "image/tiff");
- setSuffix(".ras", "image/x-cmu-rast");
- setSuffix(".pnm", "image/x-portable-anymap");
- setSuffix(".pbm", "image/x-portable-bitmap");
- setSuffix(".pgm", "image/x-portable-graymap");
- setSuffix(".ppm", "image/x-portable-pixmap");
- setSuffix(".rgb", "image/x-rgb");
- setSuffix(".xbm", "image/x-xbitmap");
- setSuffix(".xpm", "image/x-xpixmap");
- setSuffix(".xwd", "image/x-xwindowdump");
- setSuffix(".htm", "text/html");
- setSuffix(".html", "text/html");
- setSuffix(".text", "text/plain");
- setSuffix(".c", "text/plain");
- setSuffix(".cc", "text/plain");
- setSuffix(".c++", "text/plain");
- setSuffix(".h", "text/plain");
- setSuffix(".pl", "text/plain");
- setSuffix(".txt", "text/plain");
- setSuffix(".java", "text/plain");
- setSuffix(".rtx", "application/rtf");
- setSuffix(".tsv", "text/tab-separated-values");
- setSuffix(".etx", "text/x-setext");
- setSuffix(".mpg", "video/mpeg");
- setSuffix(".mpe", "video/mpeg");
- setSuffix(".mpeg", "video/mpeg");
- setSuffix(".mov", "video/quicktime");
- setSuffix(".qt", "video/quicktime");
- setSuffix(".avi", "application/x-troff-msvideo");
- setSuffix(".movie", "video/x-sgi-movie");
- setSuffix(".mv", "video/x-sgi-movie");
- setSuffix(".mime", "message/rfc822");
- }
- }
-