FileURLConnection
Code IndexAdd Codota to your IDE (free)

Best Java code snippets using libcore.net.url.FileURLConnection (Showing top 20 results out of 315)

origin: robovm/robovm

/**
 * 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);
}
origin: robovm/robovm

try {
  if (!connected) {
    connect();
  return "text/plain";
String result = guessContentTypeFromName(url.getFile());
if (result != null) {
  return result;
  result = guessContentTypeFromStream(is);
} catch (IOException e) {
origin: robovm/robovm

/**
 * 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;
}
origin: robovm/robovm

/**
 * 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;
}
origin: robovm/robovm

/**
 * 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;
}
origin: MobiVM/robovm

try {
  if (!connected) {
    connect();
  return "text/plain";
String result = guessContentTypeFromName(url.getFile());
if (result != null) {
  return result;
  result = guessContentTypeFromStream(is);
} catch (IOException e) {
origin: MobiVM/robovm

/**
 * 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;
}
origin: MobiVM/robovm

/**
 * 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;
}
origin: com.gluonhq/robovm-rt

/**
 * 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);
}
origin: com.bugvm/bugvm-rt

try {
  if (!connected) {
    connect();
  return "text/plain";
String result = guessContentTypeFromName(url.getFile());
if (result != null) {
  return result;
  result = guessContentTypeFromStream(is);
} catch (IOException e) {
origin: com.gluonhq/robovm-rt

/**
 * 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;
}
origin: ibinti/bugvm

/**
 * 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;
}
origin: MobiVM/robovm

/**
 * 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);
}
origin: ibinti/bugvm

try {
  if (!connected) {
    connect();
  return "text/plain";
String result = guessContentTypeFromName(url.getFile());
if (result != null) {
  return result;
  result = guessContentTypeFromStream(is);
} catch (IOException e) {
origin: com.mobidevelop.robovm/robovm-rt

/**
 * 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;
}
origin: com.mobidevelop.robovm/robovm-rt

/**
 * 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;
}
origin: FlexoVM/flexovm

/**
 * 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);
}
origin: com.mobidevelop.robovm/robovm-rt

try {
  if (!connected) {
    connect();
  return "text/plain";
String result = guessContentTypeFromName(url.getFile());
if (result != null) {
  return result;
  result = guessContentTypeFromStream(is);
} catch (IOException e) {
origin: com.bugvm/bugvm-rt

/**
 * 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;
}
origin: com.bugvm/bugvm-rt

/**
 * 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;
}
libcore.net.urlFileURLConnection

Javadoc

This subclass extends URLConnection.

This class is responsible for connecting, getting content and input stream of the file.

Most used methods

  • <init>
    Creates an instance of FileURLConnection for establishing a connection to the file pointed by this U
  • connect
    This methods will attempt to obtain the input stream of the file pointed by this URL. If the file i
  • getDirectoryListing
    Returns the directory listing of the file component as an input stream.
  • guessContentTypeFromName
  • guessContentTypeFromStream

Popular in Java

  • Reactive rest calls using spring rest template
  • setRequestProperty (URLConnection)
  • getApplicationContext (Context)
  • getContentResolver (Context)
  • Kernel (java.awt.image)
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.

For IntelliJ IDEA,
Android Studio or Eclipse

  • Search for JavaScript code betaCodota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutBlogContact Us
  • Plugin user guideTerms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)