本文整理汇总了Java中java.net.URL.openStream方法的典型用法代码示例。如果您正苦于以下问题:Java URL.openStream方法的具体用法?Java URL.openStream怎么用?Java URL.openStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.URL
的用法示例。
在下文中一共展示了URL.openStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processLoad
import java.net.URL; //导入方法依赖的package包/类
private void processLoad ( final String stringUrl ) throws Exception
{
final ImageLoader loader = new ImageLoader ();
final URL url = new URL ( stringUrl );
final ImageData[] data;
try ( InputStream is = url.openStream () )
{
data = loader.load ( is );
}
logger.debug ( "Image loaded" );
Display.getDefault ().asyncExec ( new Runnable () {
@Override
public void run ()
{
showImage ( stringUrl, data );
}
} );
}
示例2: getURL
import java.net.URL; //导入方法依赖的package包/类
public static String getURL(String surl) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
System.setProperty("java.net.preferIPv4Addresses", "true");
System.setProperty("java.net.preferIPv6Addresses", "false");
System.setProperty("validated.ipv6", "false");
String fullString = "";
try {
URL url = new URL(surl);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while ((line = reader.readLine()) != null) {
fullString += line;
}
reader.close();
} catch (Exception ex) {
//showDialog("Verbindungsfehler.",parent);
}
return fullString;
}
示例3: MainFS
import java.net.URL; //导入方法依赖的package包/类
public MainFS() {
ALL.addLookupListener(this);
List<URL> layerUrls = new ArrayList<URL>();
ClassLoader l = Thread.currentThread().getContextClassLoader();
try {
for (URL manifest : NbCollections.iterable(l.getResources("META-INF/MANIFEST.MF"))) { // NOI18N
InputStream is = manifest.openStream();
try {
Manifest mani = new Manifest(is);
String layerLoc = mani.getMainAttributes().getValue("OpenIDE-Module-Layer"); // NOI18N
if (layerLoc != null) {
URL layer = l.getResource(layerLoc);
if (layer != null) {
layerUrls.add(layer);
}
}
} finally {
is.close();
}
}
layers.setXmlUrls(layerUrls.toArray(new URL[layerUrls.size()]));
} catch (Exception x) {
}
resultChanged(null); // run after add listener - see PN1 in #26338
}
示例4: testHandleSpaceInPathAsProducedByEclipse
import java.net.URL; //导入方法依赖的package包/类
public void testHandleSpaceInPathAsProducedByEclipse() throws Exception {
File d = new File(getWorkDir(), "space in path");
d.mkdirs();
File f = new File(d, "x.jar");
JarOutputStream os = new JarOutputStream(new FileOutputStream(f));
os.putNextEntry(new JarEntry("test.txt"));
os.write(10);
os.close();
URL u = new URL("jar:" + f.toURL() + "!/test.txt");
DataInputStream is = new DataInputStream(u.openStream());
byte[] arr = new byte[100];
is.readFully(arr, 0, 1);
assertEquals("One byte", 10, arr[0]);
is.close();
}
示例5: getConfResourceAsReader
import java.net.URL; //导入方法依赖的package包/类
/**
* Get a {@link Reader} attached to the configuration resource with the
* given <code>name</code>.
*
* @param name configuration resource name.
* @return a reader attached to the resource.
*/
public Reader getConfResourceAsReader(String name) {
try {
URL url= getResource(name);
if (url == null) {
LOG.info(name + " not found");
return null;
} else {
LOG.info("found resource " + name + " at " + url);
}
return new InputStreamReader(url.openStream());
} catch (Exception e) {
return null;
}
}
示例6: getResourceAsStream
import java.net.URL; //导入方法依赖的package包/类
/**
* Delegate to parent
*
* @see java.lang.ClassLoader#getResourceAsStream(java.lang.String)
*/
@Override
public InputStream getResourceAsStream(String name) {
InputStream is = parent.getResourceAsStream(name);
if (is == null) {
URL url = findResource(name);
if (url != null) {
try {
is = url.openStream();
} catch (IOException e) {
// Ignore
}
}
}
return is;
}
示例7: getResourceAsStream
import java.net.URL; //导入方法依赖的package包/类
/**
* This is a convenience method to load a resource as a stream. <p/> The
* algorithm used to find the resource is given in getResource()
*
* @param resourceName The name of the resource to load
* @param callingClass The Class object of the calling object
*/
static InputStream getResourceAsStream(String resourceName, Class<?> callingClass) {
URL url = getResource(resourceName, callingClass);
try {
return (url != null) ? url.openStream() : null;
} catch (IOException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, e.getMessage(), e);
}
return null;
}
}
示例8: testGetResourceWithCustomLoader
import java.net.URL; //导入方法依赖的package包/类
/**
* Verifies that <tt>getResource</tt> works with custom loader from {@link ClassPathLoader}.
*/
@Test
public void testGetResourceWithCustomLoader() throws Exception {
System.out.println("\nStarting ClassPathLoaderTest#testGetResourceWithCustomLoader");
ClassPathLoader dcl = ClassPathLoader.createWithDefaults(false);
dcl = dcl.addOrReplace(new GeneratingClassLoader());
String resourceToGet = "com/nowhere/testGetResourceWithCustomLoader.rsc";
URL url = dcl.getResource(resourceToGet);
assertNotNull(url);
InputStream is = url != null ? url.openStream() : null;
assertNotNull(is);
int totalBytesRead = 0;
byte[] input = new byte[128];
BufferedInputStream bis = new BufferedInputStream(is);
for (int bytesRead = bis.read(input); bytesRead > -1;) {
totalBytesRead += bytesRead;
bytesRead = bis.read(input);
}
bis.close();
assertEquals(TEMP_FILE_BYTES_COUNT, totalBytesRead);
}
示例9: getContentFromUrl
import java.net.URL; //导入方法依赖的package包/类
private String getContentFromUrl(URL url, String readAfter, String readBefore) throws SchoolException {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
StringBuffer buffer = new StringBuffer();
String inputLine;
boolean reading = false;
while ((inputLine = reader.readLine()) != null) {
if (reading) {
if (inputLine.contains(readBefore))
break;
buffer.append(inputLine);
} else {
if (inputLine.contains(readAfter))
reading = true;
}
}
reader.close();
return buffer.toString();
} catch (IOException e) {
throw new SchoolException("교육청 서버에 접속하지 못하였습니다.");
}
}
示例10: openManifestStream
import java.net.URL; //导入方法依赖的package包/类
protected InputStream openManifestStream(ProtectionDomain protectionDomain)
throws MalformedURLException, IOException {
URL manifestUrl = null;
// try to pick the Manifest in the source JAR
manifestUrl = selectManifestFromJars(protectionDomain);
LOG.debug("Manifest location in JARs is {}", manifestUrl);
if (manifestUrl == null) {
// if we can't locate the correct JAR then try get to manifest file via a file path (e.g. in Hadoop case where
// jar is unpacked to disk)
manifestUrl = selectFromFileLocation(protectionDomain);
LOG.debug("Manifest location on disk is {}", manifestUrl);
}
if (manifestUrl == null) {
// file not found, get via class loader resource (e.g. from inside jar)
manifestUrl = protectionDomain.getClassLoader().getResource(META_INF_MANIFEST_MF);
LOG.debug("Manifest location via getResource() is {}", manifestUrl);
}
if (manifestUrl == null) {
LOG.warn("Manifest not found!");
return null;
}
return manifestUrl.openStream();
}
示例11: doFunnyZipEntryNames
import java.net.URL; //导入方法依赖的package包/类
private void doFunnyZipEntryNames(String file) throws Exception {
File docx = new File(getWorkDir(), "ms-docx.jar");
JarOutputStream jos = new JarOutputStream(new FileOutputStream(docx));
ZipEntry entry = new ZipEntry(file);
jos.putNextEntry(entry);
jos.write("content".getBytes());
jos.close();
FileObject docxFO = URLMapper.findFileObject(Utilities.toURI(docx).toURL());
assertNotNull(docxFO);
assertTrue(FileUtil.isArchiveFile(docxFO));
FileObject docxRoot = FileUtil.getArchiveRoot(docxFO);
assertNotNull("Root found", docxRoot);
FileObject content = docxRoot.getFileObject(file);
assertNotNull("content.xml found", content);
assertEquals("Has right bytes", "content", content.asText());
CharSequence log = Log.enable("", Level.WARNING);
URL u = URLMapper.findURL(content, URLMapper.EXTERNAL);
InputStream is = u.openStream();
byte[] arr = new byte[30];
int len = is.read(arr);
assertEquals("Len is content", "content".length(), len);
assertEquals("OK", "content", new String(arr, 0, len));
assertEquals("No warnings:\n" + log, 0, log.length());
assertEquals(u.toString(), content, URLMapper.findFileObject(u));
}
示例12: getAudioFileFormat
import java.net.URL; //导入方法依赖的package包/类
public AudioFileFormat getAudioFileFormat(URL url)
throws UnsupportedAudioFileException, IOException {
InputStream stream = url.openStream();
AudioFileFormat format;
try {
format = getAudioFileFormat(new BufferedInputStream(stream));
} finally {
stream.close();
}
return format;
}
示例13: fromFile
import java.net.URL; //导入方法依赖的package包/类
private static String fromFile(String name) {
URL url = Pre90403Phase1CompatibilityTest.class.getResource(name);
if (url == null) {
return "";
}
try {
InputStream is = url.openStream();
try {
StringBuilder sb = new StringBuilder();
byte [] buffer = new byte [1024];
int size;
while(0 < (size = is.read(buffer, 0, buffer.length))) {
String s = new String(buffer, 0, size);
sb.append(s);
}
return sb.toString();
} finally {
is.close();
}
} catch (IOException e) {
fail("Can't read file: '" + name + "'");
return null; // can't be reached
}
}
示例14: getResource
import java.net.URL; //导入方法依赖的package包/类
/**
* Loads a resource from the specified URL. Note that this method does obviously not recognize the <code>useClassLoader</code> flag.
* @param url of the resource to load
* @return returns the input stream to the resource
* @throws MalformedURLException, IOException thrown in case that the resource can not be loaded (can not be found)
*/
public InputStream getResource(URL url) throws MalformedURLException, IOException
{
InputStream is = url.openStream();
if (is == null) throw new MalformedURLException("A problem occured while loading the resource (url.openStream() returned null)");
return is;
}
示例15: loadSyntaxCheckers
import java.net.URL; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadSyntaxCheckers( Schema... schemas ) throws LdapException, IOException
{
List<Entry> syntaxCheckerList = new ArrayList<>();
if ( schemas == null )
{
return syntaxCheckerList;
}
for ( Schema schema : schemas )
{
String start = getSchemaDirectoryString( schema )
+ SchemaConstants.SYNTAX_CHECKERS_PATH + "/" + "m-oid=";
String end = "." + LDIF_EXT;
for ( String resourcePath : RESOURCE_MAP.keySet() )
{
if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
{
URL resource = getResource( resourcePath, "syntaxChecker LDIF file" );
LdifReader reader = new LdifReader( resource.openStream() );
LdifEntry entry = reader.next();
reader.close();
syntaxCheckerList.add( entry.getEntry() );
}
}
}
return syntaxCheckerList;
}