java.net.URL#getContent ( )源码实例Demo

下面列出了java.net.URL#getContent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk1.8-source-analysis   文件: Beans.java
public synchronized Image getImage(URL url) {
    Object o = imageCache.get(url);
    if (o != null) {
        return (Image)o;
    }
    try {
        o = url.getContent();
        if (o == null) {
            return null;
        }
        if (o instanceof Image) {
            imageCache.put(url, o);
            return (Image) o;
        }
        // Otherwise it must be an ImageProducer.
        Image img = target.createImage((java.awt.image.ImageProducer)o);
        imageCache.put(url, img);
        return img;

    } catch (Exception ex) {
        return null;
    }
}
 
源代码2 项目: jdk8u60   文件: Beans.java
public synchronized Image getImage(URL url) {
    Object o = imageCache.get(url);
    if (o != null) {
        return (Image)o;
    }
    try {
        o = url.getContent();
        if (o == null) {
            return null;
        }
        if (o instanceof Image) {
            imageCache.put(url, o);
            return (Image) o;
        }
        // Otherwise it must be an ImageProducer.
        Image img = target.createImage((java.awt.image.ImageProducer)o);
        imageCache.put(url, img);
        return img;

    } catch (Exception ex) {
        return null;
    }
}
 
源代码3 项目: birt   文件: MarkerIconDialog.java
/**
 * Preview the image when it is a local image file.
 * 
 * @param uri
 *            Image absolute path without "file:///"
 */
private ImageStatus preview( String uri )
{
	
	hasUriImagePreviewed=true;	
	try
	{
		URL url = new URL( uri );
		// there's no need to enable the ok button when processing
		url.getContent( );
		if ( previewCanvas.loadImage( url ) != null )
		{
			emptyExceptionText();
		}
		return ImageStatus.IMAGE_CAN_DISPLAY;
	}
	catch (MalformedURLException malEx){
		showMessage(Messages.getString( "MarkerIconDialog.Exception.InvalidURL" ));//$NON-NLS-1$
		return ImageStatus.IMAGE_URL_INVALID;
	}	
	catch ( Exception ex )
	{				
		showMessage(Messages.getString("MarkerIconDialog.Exception.ImageNotAvailable"));  //$NON-NLS-1$
		return ImageStatus.IMAGE_CANNOT_DISPLAY;
	}		
}
 
@Override
public File loadDataFromNetwork() throws IOException {
    int bytesRead;
    URL url = new URL(source);

    File destFile = new File(destinationFolder, Uri.parse(source).getLastPathSegment());
    FileOutputStream fileOutput = new FileOutputStream(destFile);

    InputStream inputStream = (InputStream) url.getContent();
    byte[] buffer = new byte[MAX_BUFFER_SIZE];
    while ((bytesRead = inputStream.read(buffer)) > 0) {
        fileOutput.write(buffer, 0, bytesRead);
    }
    fileOutput.close();

    return destFile;
}
 
源代码5 项目: jdk1.8-source-analysis   文件: Beans.java
public AudioClip getAudioClip(URL url) {
    // We don't currently support audio clips in the Beans.instantiate
    // applet context, unless by some luck there exists a URL content
    // class that can generate an AudioClip from the audio URL.
    try {
        return (AudioClip) url.getContent();
    } catch (Exception ex) {
        return null;
    }
}
 
源代码6 项目: Bytecoder   文件: Beans.java
public AudioClip getAudioClip(URL url) {
    // We don't currently support audio clips in the Beans.instantiate
    // applet context, unless by some luck there exists a URL content
    // class that can generate an AudioClip from the audio URL.
    try {
        return (AudioClip) url.getContent();
    } catch (Exception ex) {
        return null;
    }
}
 
源代码7 项目: Java8CN   文件: SimpleBeanInfo.java
/**
 * This is a utility method to help in loading icon images.
 * It takes the name of a resource file associated with the
 * current object's class file and loads an image object
 * from that file.  Typically images will be GIFs.
 * <p>
 * @param resourceName  A pathname relative to the directory
 *          holding the class file of the current class.  For example,
 *          "wombat.gif".
 * @return  an image object.  May be null if the load failed.
 */
public Image loadImage(final String resourceName) {
    try {
        final URL url = getClass().getResource(resourceName);
        if (url != null) {
            final ImageProducer ip = (ImageProducer) url.getContent();
            if (ip != null) {
                return Toolkit.getDefaultToolkit().createImage(ip);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
源代码8 项目: jdk8u-jdk   文件: Beans.java
public AudioClip getAudioClip(URL url) {
    // We don't currently support audio clips in the Beans.instantiate
    // applet context, unless by some luck there exists a URL content
    // class that can generate an AudioClip from the audio URL.
    try {
        return (AudioClip) url.getContent();
    } catch (Exception ex) {
        return null;
    }
}
 
源代码9 项目: dragonwell8_jdk   文件: SimpleBeanInfo.java
/**
 * This is a utility method to help in loading icon images.
 * It takes the name of a resource file associated with the
 * current object's class file and loads an image object
 * from that file.  Typically images will be GIFs.
 * <p>
 * @param resourceName  A pathname relative to the directory
 *          holding the class file of the current class.  For example,
 *          "wombat.gif".
 * @return  an image object.  May be null if the load failed.
 */
public Image loadImage(final String resourceName) {
    try {
        final URL url = getClass().getResource(resourceName);
        if (url != null) {
            final ImageProducer ip = (ImageProducer) url.getContent();
            if (ip != null) {
                return Toolkit.getDefaultToolkit().createImage(ip);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
源代码10 项目: openjdk-jdk9   文件: Basic.java
@Test(dataProvider = "urls")
public void testGetContent(String urlString, boolean exists) throws Exception {
    URL url = new URL(urlString);
    try {
        Object obj = url.getContent();
        assertTrue(obj != null);
        if (!exists) fail("IOException expected");
    } catch (IOException ioe) {
        if (exists) fail("IOException not expected");
    }
}
 
源代码11 项目: openjdk-jdk8u-backup   文件: SimpleBeanInfo.java
/**
 * This is a utility method to help in loading icon images.
 * It takes the name of a resource file associated with the
 * current object's class file and loads an image object
 * from that file.  Typically images will be GIFs.
 * <p>
 * @param resourceName  A pathname relative to the directory
 *          holding the class file of the current class.  For example,
 *          "wombat.gif".
 * @return  an image object.  May be null if the load failed.
 */
public Image loadImage(final String resourceName) {
    try {
        final URL url = getClass().getResource(resourceName);
        if (url != null) {
            final ImageProducer ip = (ImageProducer) url.getContent();
            if (ip != null) {
                return Toolkit.getDefaultToolkit().createImage(ip);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
源代码12 项目: TencentKona-8   文件: Beans.java
public AudioClip getAudioClip(URL url) {
    // We don't currently support audio clips in the Beans.instantiate
    // applet context, unless by some luck there exists a URL content
    // class that can generate an AudioClip from the audio URL.
    try {
        return (AudioClip) url.getContent();
    } catch (Exception ex) {
        return null;
    }
}
 
源代码13 项目: openjdk-jdk9   文件: Beans.java
public AudioClip getAudioClip(URL url) {
    // We don't currently support audio clips in the Beans.instantiate
    // applet context, unless by some luck there exists a URL content
    // class that can generate an AudioClip from the audio URL.
    try {
        return (AudioClip) url.getContent();
    } catch (Exception ex) {
        return null;
    }
}
 
源代码14 项目: jdk8u_jdk   文件: Beans.java
public AudioClip getAudioClip(URL url) {
    // We don't currently support audio clips in the Beans.instantiate
    // applet context, unless by some luck there exists a URL content
    // class that can generate an AudioClip from the audio URL.
    try {
        return (AudioClip) url.getContent();
    } catch (Exception ex) {
        return null;
    }
}
 
源代码15 项目: hottub   文件: SimpleBeanInfo.java
/**
 * This is a utility method to help in loading icon images.
 * It takes the name of a resource file associated with the
 * current object's class file and loads an image object
 * from that file.  Typically images will be GIFs.
 * <p>
 * @param resourceName  A pathname relative to the directory
 *          holding the class file of the current class.  For example,
 *          "wombat.gif".
 * @return  an image object.  May be null if the load failed.
 */
public Image loadImage(final String resourceName) {
    try {
        final URL url = getClass().getResource(resourceName);
        if (url != null) {
            final ImageProducer ip = (ImageProducer) url.getContent();
            if (ip != null) {
                return Toolkit.getDefaultToolkit().createImage(ip);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
源代码16 项目: Bytecoder   文件: SimpleBeanInfo.java
/**
 * This is a utility method to help in loading icon images. It takes the
 * name of a resource file associated with the current object's class file
 * and loads an image object from that file. Typically images will be GIFs.
 *
 * @param  resourceName A pathname relative to the directory holding the
 *         class file of the current class. For example, "wombat.gif".
 * @return an image object or null if the resource is not found or the
 *         resource could not be loaded as an Image
 */
public Image loadImage(final String resourceName) {
    try {
        final URL url = getClass().getResource(resourceName);
        if (url != null) {
            final ImageProducer ip = (ImageProducer) url.getContent();
            if (ip != null) {
                return Toolkit.getDefaultToolkit().createImage(ip);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
源代码17 项目: jdk8u60   文件: SimpleBeanInfo.java
/**
 * This is a utility method to help in loading icon images.
 * It takes the name of a resource file associated with the
 * current object's class file and loads an image object
 * from that file.  Typically images will be GIFs.
 * <p>
 * @param resourceName  A pathname relative to the directory
 *          holding the class file of the current class.  For example,
 *          "wombat.gif".
 * @return  an image object.  May be null if the load failed.
 */
public Image loadImage(final String resourceName) {
    try {
        final URL url = getClass().getResource(resourceName);
        if (url != null) {
            final ImageProducer ip = (ImageProducer) url.getContent();
            if (ip != null) {
                return Toolkit.getDefaultToolkit().createImage(ip);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
源代码18 项目: jdk8u-dev-jdk   文件: Beans.java
public AudioClip getAudioClip(URL url) {
    // We don't currently support audio clips in the Beans.instantiate
    // applet context, unless by some luck there exists a URL content
    // class that can generate an AudioClip from the audio URL.
    try {
        return (AudioClip) url.getContent();
    } catch (Exception ex) {
        return null;
    }
}
 
源代码19 项目: JDKSourceCode1.8   文件: SimpleBeanInfo.java
/**
 * This is a utility method to help in loading icon images.
 * It takes the name of a resource file associated with the
 * current object's class file and loads an image object
 * from that file.  Typically images will be GIFs.
 * <p>
 * @param resourceName  A pathname relative to the directory
 *          holding the class file of the current class.  For example,
 *          "wombat.gif".
 * @return  an image object.  May be null if the load failed.
 */
public Image loadImage(final String resourceName) {
    try {
        final URL url = getClass().getResource(resourceName);
        if (url != null) {
            final ImageProducer ip = (ImageProducer) url.getContent();
            if (ip != null) {
                return Toolkit.getDefaultToolkit().createImage(ip);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
源代码20 项目: openjdk-8   文件: GetContentType.java
public static void main(String args[]) throws Exception {
    URL url = ClassLoader.getSystemResource("foo/bar");
    InputStream is = (InputStream) url.getContent();
    if (is == null)
        throw new Exception("Failed to get content.");
}