當前位置: 首頁>>代碼示例>>Java>>正文


Java URL.getContent方法代碼示例

本文整理匯總了Java中java.net.URL.getContent方法的典型用法代碼示例。如果您正苦於以下問題:Java URL.getContent方法的具體用法?Java URL.getContent怎麽用?Java URL.getContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.URL的用法示例。


在下文中一共展示了URL.getContent方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getImage

import java.net.URL; //導入方法依賴的package包/類
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;
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:Beans.java

示例2: fetchContent

import java.net.URL; //導入方法依賴的package包/類
static String fetchContent(URL url) {
    java.io.Reader reader = null;
    try {
        reader = new java.io.InputStreamReader((java.io.InputStream) url.getContent());
        StringBuilder content = new StringBuilder();
        char[] buf = new char[1024];
        for (int n = reader.read(buf); n > -1; n = reader.read(buf))
            content.append(buf, 0, n);
        return content.toString();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        if (reader != null) try {
            reader.close();
        } catch (Throwable t) {
        }
    }
}
 
開發者ID:junicorn,項目名稱:NiuBi,代碼行數:19,代碼來源:Json.java

示例3: addVersionInfo

import java.net.URL; //導入方法依賴的package包/類
public void addVersionInfo() {
    Properties props = new Properties();
    // when running from webstart  we are not allowed to open a file on the local file system, but we can
    // get a the contents of a resource, which in this case is the echo'ed date stamp written by ant on the last build
    ClassLoader cl = this.getClass().getClassLoader(); // get this class'es class loader
    addLogInfo("\nLoading version info from resource " + AEViewerAboutDialog.VERSION_FILE);
    URL versionURL = cl.getResource(AEViewerAboutDialog.VERSION_FILE); // get a URL to the time stamp file
    addLogInfo("\nVersion URL=" + versionURL + "\n");

    if (versionURL != null) {
        try {
            Object urlContents = versionURL.getContent();
            BufferedReader in = null;
            if (urlContents instanceof InputStream) {
                props.load((InputStream) urlContents);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
        PrintWriter ps = new PrintWriter(baos);
        props.list(ps);
        ps.flush();
        try {
            addLogInfo("\n" + baos.toString("UTF-8"));
        } catch (UnsupportedEncodingException ex) {
            System.err.println("cannot encode version information in LoggingWindow.addVersionInfo: " + ex.toString());
        }
    } else {
        props.setProperty("version", "missing file " + AEViewerAboutDialog.VERSION_FILE + " in jAER.jar");
    }

}
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:34,代碼來源:LoggingWindow.java

示例4: doInBackground

import java.net.URL; //導入方法依賴的package包/類
@Override
protected ArrayList<Bitmap> doInBackground(URL... params) {
	URL[] urls = new URL[] {params[0], params[1], params[2]};
	ArrayList<Bitmap> bitmaps = new ArrayList<>();

	for(URL url : urls) {
		Bitmap bitmap = null;
		if(url != null) {
			try {
				InputStream is = (InputStream) url.getContent();
				bitmap = BitmapFactory.decodeStream(is);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		bitmaps.add(bitmap);
	}

	return bitmaps;

}
 
開發者ID:SebastianRask,項目名稱:Pocket-Plays-for-Twitch,代碼行數:23,代碼來源:ChannelInfo.java

示例5: getClassMetadata

import java.net.URL; //導入方法依賴的package包/類
public static ClassMetadata getClassMetadata(String className) throws IOException {

        String path = className.replace('.','/') + ".class";
        URL url = Thread.currentThread().getContextClassLoader().getResource(path);

        ClassReader cr = null;
        if(url != null && "file".equals(url.getProtocol())){
            try(InputStream in = (InputStream) url.getContent()) {
                cr = new ClassReader(in);
            }
        }else {
            URL realUrl = new URL(SourceCodeHelper.getJarLocationByPath(url));
            try (ZipInputStream zip = new ZipInputStream(realUrl.openStream())) {
                ZipEntry entry;
                while ((entry = zip.getNextEntry()) != null) {

                    if (entry.getName().equalsIgnoreCase(path)) {
                        cr = new ClassReader(zip);
                        break;
                    }
                }
            }
        }

        if(cr != null) {
            ClassMetadata metadata = new ClassMetadata();
            cr.accept(new MetadataCollector(metadata), ClassReader.SKIP_FRAMES);
            return metadata;
        }else {
            return null;
        }
    }
 
開發者ID:ctripcorp,項目名稱:cornerstone,代碼行數:33,代碼來源:AgentTool.java

示例6: fetch

import java.net.URL; //導入方法依賴的package包/類
private InputStream fetch(String urlString) throws IOException {
    URL url;
    final MyHtmlHttpImageGetter imageGetter = imageGetterReference.get();
    if (imageGetter == null) {
        return null;
    }
    if (imageGetter.baseUri != null) {
        url = imageGetter.baseUri.resolve(urlString).toURL();
    } else {
        url = URI.create(urlString).toURL();
    }

    return (InputStream) url.getContent();
}
 
開發者ID:mzlogin,項目名稱:guanggoo-android,代碼行數:15,代碼來源:MyHtmlHttpImageGetter.java

示例7: fetch

import java.net.URL; //導入方法依賴的package包/類
private InputStream fetch(String urlString) throws IOException {
    URL url;
    final HtmlHttpImageGetter imageGetter = imageGetterReference.get();
    if (imageGetter == null) {
        return null;
    }
    if (imageGetter.baseUri != null) {
        url = imageGetter.baseUri.resolve(urlString).toURL();
    } else {
        url = URI.create(urlString).toURL();
    }

    return (InputStream) url.getContent();
}
 
開發者ID:RanKKI,項目名稱:PSNine,代碼行數:15,代碼來源:HtmlHttpImageGetter.java

示例8: getAudioClip

import java.net.URL; //導入方法依賴的package包/類
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;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:11,代碼來源:Beans.java

示例9: loadImage

import java.net.URL; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:SimpleBeanInfo.java

示例10: loadLocalPDFFile

import java.net.URL; //導入方法依賴的package包/類
@When("the user load '$path' file with  key '$key'")
public void loadLocalPDFFile(String path, String key) throws URISyntaxException {
    URL pdfFile = FilePreconditionsSteps.class.getResource(path);
    try {
        Object content = pdfFile.getContent();
        URI uri = pdfFile.toURI();
        File file = new File(uri);
        Thucydides.getCurrentSession().put(key, file);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:tapack,項目名稱:satisfy,代碼行數:13,代碼來源:FilePreconditionsSteps.java

示例11: loadImage

import java.net.URL; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:SimpleBeanInfo.java

示例12: testGetContent

import java.net.URL; //導入方法依賴的package包/類
@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");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:Basic.java

示例13: main

import java.net.URL; //導入方法依賴的package包/類
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.");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:7,代碼來源:GetContentType.java


注:本文中的java.net.URL.getContent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。