/** * The behavior of this method is the same as openConnection(URL). * <code>proxy</code> is not used in FileURLConnection. * * @param url * the URL which the connection is pointing to * @param proxy * Proxy * @return a connection to the resource pointed by this url. * * @throws IOException * if this handler fails to establish a connection. * @throws IllegalArgumentException * if the url argument is null. * @throws UnsupportedOperationException * if the protocol handler doesn't support this method. */ @Override public URLConnection openConnection(URL url, Proxy proxy) throws IOException { if (url == null) { throw new IllegalArgumentException("url == null"); } String host = url.getHost(); if (host == null || host.isEmpty() || host.equalsIgnoreCase("localhost")) { return new FileURLConnection(url); } // If a hostname is specified try to get the resource using FTP URL ftpURL = new URL("ftp", host, url.getFile()); return (proxy == null) ? ftpURL.openConnection() : ftpURL.openConnection(proxy); }
try { if (!connected) { connect(); return "text/plain"; String result = guessContentTypeFromName(url.getFile()); if (result != null) { return result; result = guessContentTypeFromStream(is); } catch (IOException e) {
/** * This methods will attempt to obtain the input stream of the file pointed * by this <code>URL</code>. If the file is a directory, it will return * that directory listing as an input stream. * * @throws IOException * if an IO error occurs while connecting */ @Override public void connect() throws IOException { File f = new File(filename); if (f.isDirectory()) { isDir = true; is = getDirectoryListing(f); // use -1 for the contentLength } else { is = new BufferedInputStream(new FileInputStream(f)); long lengthAsLong = f.length(); length = lengthAsLong <= Integer.MAX_VALUE ? (int) lengthAsLong : Integer.MAX_VALUE; } connected = true; }
/** * Returns the length of the file in bytes. * * @return the length of the file * * @see #getContentType() */ @Override public int getContentLength() { try { if (!connected) { connect(); } } catch (IOException e) { // default is -1 } return length; }
/** * Returns the input stream of the object referred to by this * <code>URLConnection</code> * * 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" * * @return input stream of the object * * @throws IOException * if an IO error occurs */ @Override public InputStream getInputStream() throws IOException { if (!connected) { connect(); } return is; }
try { if (!connected) { connect(); return "text/plain"; String result = guessContentTypeFromName(url.getFile()); if (result != null) { return result; result = guessContentTypeFromStream(is); } catch (IOException e) {
/** * Returns the length of the file in bytes. * * @return the length of the file * * @see #getContentType() */ @Override public int getContentLength() { try { if (!connected) { connect(); } } catch (IOException e) { // default is -1 } return length; }
/** * This methods will attempt to obtain the input stream of the file pointed * by this <code>URL</code>. If the file is a directory, it will return * that directory listing as an input stream. * * @throws IOException * if an IO error occurs while connecting */ @Override public void connect() throws IOException { File f = new File(filename); if (f.isDirectory()) { isDir = true; is = getDirectoryListing(f); // use -1 for the contentLength } else { is = new BufferedInputStream(new FileInputStream(f)); long lengthAsLong = f.length(); length = lengthAsLong <= Integer.MAX_VALUE ? (int) lengthAsLong : Integer.MAX_VALUE; } connected = true; }
/** * The behavior of this method is the same as openConnection(URL). * <code>proxy</code> is not used in FileURLConnection. * * @param url * the URL which the connection is pointing to * @param proxy * Proxy * @return a connection to the resource pointed by this url. * * @throws IOException * if this handler fails to establish a connection. * @throws IllegalArgumentException * if the url argument is null. * @throws UnsupportedOperationException * if the protocol handler doesn't support this method. */ @Override public URLConnection openConnection(URL url, Proxy proxy) throws IOException { if (url == null) { throw new IllegalArgumentException("url == null"); } String host = url.getHost(); if (host == null || host.isEmpty() || host.equalsIgnoreCase("localhost")) { return new FileURLConnection(url); } // If a hostname is specified try to get the resource using FTP URL ftpURL = new URL("ftp", host, url.getFile()); return (proxy == null) ? ftpURL.openConnection() : ftpURL.openConnection(proxy); }
try { if (!connected) { connect(); return "text/plain"; String result = guessContentTypeFromName(url.getFile()); if (result != null) { return result; result = guessContentTypeFromStream(is); } catch (IOException e) {
/** * Returns the length of the file in bytes. * * @return the length of the file * * @see #getContentType() */ @Override public int getContentLength() { try { if (!connected) { connect(); } } catch (IOException e) { // default is -1 } return length; }
/** * This methods will attempt to obtain the input stream of the file pointed * by this <code>URL</code>. If the file is a directory, it will return * that directory listing as an input stream. * * @throws IOException * if an IO error occurs while connecting */ @Override public void connect() throws IOException { File f = new File(filename); if (f.isDirectory()) { isDir = true; is = getDirectoryListing(f); // use -1 for the contentLength } else { is = new BufferedInputStream(new FileInputStream(f)); long lengthAsLong = f.length(); length = lengthAsLong <= Integer.MAX_VALUE ? (int) lengthAsLong : Integer.MAX_VALUE; } connected = true; }
/** * The behavior of this method is the same as openConnection(URL). * <code>proxy</code> is not used in FileURLConnection. * * @param url * the URL which the connection is pointing to * @param proxy * Proxy * @return a connection to the resource pointed by this url. * * @throws IOException * if this handler fails to establish a connection. * @throws IllegalArgumentException * if the url argument is null. * @throws UnsupportedOperationException * if the protocol handler doesn't support this method. */ @Override public URLConnection openConnection(URL url, Proxy proxy) throws IOException { if (url == null) { throw new IllegalArgumentException("url == null"); } String host = url.getHost(); if (host == null || host.isEmpty() || host.equalsIgnoreCase("localhost")) { return new FileURLConnection(url); } // If a hostname is specified try to get the resource using FTP URL ftpURL = new URL("ftp", host, url.getFile()); return (proxy == null) ? ftpURL.openConnection() : ftpURL.openConnection(proxy); }
try { if (!connected) { connect(); return "text/plain"; String result = guessContentTypeFromName(url.getFile()); if (result != null) { return result; result = guessContentTypeFromStream(is); } catch (IOException e) {
/** * Returns the length of the file in bytes. * * @return the length of the file * * @see #getContentType() */ @Override public int getContentLength() { try { if (!connected) { connect(); } } catch (IOException e) { // default is -1 } return length; }
/** * This methods will attempt to obtain the input stream of the file pointed * by this <code>URL</code>. If the file is a directory, it will return * that directory listing as an input stream. * * @throws IOException * if an IO error occurs while connecting */ @Override public void connect() throws IOException { File f = new File(filename); if (f.isDirectory()) { isDir = true; is = getDirectoryListing(f); // use -1 for the contentLength } else { is = new BufferedInputStream(new FileInputStream(f)); long lengthAsLong = f.length(); length = lengthAsLong <= Integer.MAX_VALUE ? (int) lengthAsLong : Integer.MAX_VALUE; } connected = true; }
/** * The behavior of this method is the same as openConnection(URL). * <code>proxy</code> is not used in FileURLConnection. * * @param url * the URL which the connection is pointing to * @param proxy * Proxy * @return a connection to the resource pointed by this url. * * @throws IOException * if this handler fails to establish a connection. * @throws IllegalArgumentException * if the url argument is null. * @throws UnsupportedOperationException * if the protocol handler doesn't support this method. */ @Override public URLConnection openConnection(URL url, Proxy proxy) throws IOException { if (url == null) { throw new IllegalArgumentException("url == null"); } String host = url.getHost(); if (host == null || host.isEmpty() || host.equalsIgnoreCase("localhost")) { return new FileURLConnection(url); } // If a hostname is specified try to get the resource using FTP URL ftpURL = new URL("ftp", host, url.getFile()); return (proxy == null) ? ftpURL.openConnection() : ftpURL.openConnection(proxy); }
try { if (!connected) { connect(); return "text/plain"; String result = guessContentTypeFromName(url.getFile()); if (result != null) { return result; result = guessContentTypeFromStream(is); } catch (IOException e) {
/** * Returns the length of the file in bytes. * * @return the length of the file * * @see #getContentType() */ @Override public int getContentLength() { try { if (!connected) { connect(); } } catch (IOException e) { // default is -1 } return length; }
/** * This methods will attempt to obtain the input stream of the file pointed * by this <code>URL</code>. If the file is a directory, it will return * that directory listing as an input stream. * * @throws IOException * if an IO error occurs while connecting */ @Override public void connect() throws IOException { File f = new File(filename); if (f.isDirectory()) { isDir = true; is = getDirectoryListing(f); // use -1 for the contentLength } else { is = new BufferedInputStream(new FileInputStream(f)); long lengthAsLong = f.length(); length = lengthAsLong <= Integer.MAX_VALUE ? (int) lengthAsLong : Integer.MAX_VALUE; } connected = true; }