当前位置: 首页>>代码示例>>Java>>正文


Java URL.openStream方法代码示例

本文整理汇总了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 );
        }
    } );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:23,代码来源:URLImageLabel.java

示例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;
}
 
开发者ID:LV-Crew,项目名称:Adblocker-for-Android,代码行数:24,代码来源:MainActivity.java

示例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
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:SetupUtil.java

示例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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ProxyURLStreamHandlerFactoryTest.java

示例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;
  }
}
 
开发者ID:spafka,项目名称:spark_deep,代码行数:24,代码来源:Configuration.java

示例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;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:21,代码来源:JasperLoader.java

示例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;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:ClassLoaderUtils.java

示例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);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:30,代码来源:ClassPathLoaderIntegrationTest.java

示例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("교육청 서버에 접속하지 못하였습니다.");
        }
    }
 
开发者ID:JoMingyu,项目名称:Bobsim-Server,代码行数:28,代码来源:School.java

示例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();
}
 
开发者ID:HotelsDotCom,项目名称:waggle-dance,代码行数:29,代码来源:ManifestAttributes.java

示例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));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:ArchiveURLMapperTest.java

示例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;
}
 
开发者ID:axlecho,项目名称:tuxguitar,代码行数:12,代码来源:WaveExtensibleFileReader.java

示例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
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:Pre90403Phase1CompatibilityTest.java

示例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;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:13,代码来源:Binding.java

示例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;
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:36,代码来源:JarLdifSchemaLoader.java


注:本文中的java.net.URL.openStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。