當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。