java.net.URL.getContent()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(834)

本文整理了Java中java.net.URL.getContent()方法的一些代码示例,展示了URL.getContent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URL.getContent()方法的具体详情如下:
包路径:java.net.URL
类名称:URL
方法名:getContent

URL.getContent介绍

[英]Returns the content of the resource which is referred by this URL. By default this returns an InputStream, or null if the content type of the response is unknown.
[中]返回此URL引用的资源的内容。默认情况下,这将返回InputStream,如果响应的内容类型未知,则返回null。

代码示例

代码示例来源:origin: stackoverflow.com

public static Drawable LoadImageFromWebOperations(String url) {
  try {
    InputStream is = (InputStream) new URL(url).getContent();
    Drawable d = Drawable.createFromStream(is, "src name");
    return d;
  } catch (Exception e) {
    return null;
  }
}

代码示例来源:origin: stackoverflow.com

try {
 ImageView i = (ImageView)findViewById(R.id.image);
 Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
 i.setImageBitmap(bitmap); 
} catch (MalformedURLException e) {
 e.printStackTrace();
} catch (IOException e) {
 e.printStackTrace();
}

代码示例来源:origin: stackoverflow.com

ImageView iv = new ImageView;

URL url = new URL(address);
InputStream content = (InputStream)url.getContent();
Drawable d = Drawable.createFromStream(content , "src"); 
iv.setImageDrawable(d)

代码示例来源:origin: stackoverflow.com

public static Bitmap loadImageFromNetwork(String url) {
  Bitmap bitmap = null;
  try {
    bitmap = BitmapFactory.decodeStream((InputStream) new URL(url)
        .getContent());
  } catch (Exception e) {
    e.printStackTrace();
  }
  return bitmap;
}

代码示例来源:origin: stackoverflow.com

System.out.println((new URL("http://pastebin.com/pastebin.php?dl=f722c7eb0")).getContent())

代码示例来源:origin: sephiroth74/ImageViewZoom

java.net.URL finalUrl;
try {
  finalUrl = new java.net.URL( uri.toString() );
} catch ( MalformedURLException e ) {
  e.printStackTrace();
  return (InputStream) finalUrl.getContent();
} catch ( IOException e ) {
  e.printStackTrace();

代码示例来源:origin: stackoverflow.com

try {
  bitmap = BitmapFactory.decodeStream((InputStream)
                 new URL(url).getContent());
} catch (Exception e) {
  e.printStackTrace();

代码示例来源:origin: Netflix/servo

/**
 * getContent from 169.254.169.254.
 */
@BeforeTest(groups = {"aws"})
public void checkEc2() throws Exception {
 URL testEc2Url = new URL("http://169.254.169.254/latest/meta-data");
 testEc2Url.getContent();
}

代码示例来源:origin: apache/incubator-gobblin

@Test(enabled = false)
public void mustDownloadLargeFiles()
  throws Exception {
 mockServer.when(HttpRequest.request().withMethod("CONNECT").withPath("www.us.apache.org:80"))
   .respond(HttpResponse.response().withStatusCode(200));
 mockServer.when(HttpRequest.request().withMethod("GET")
   .withPath("/dist//httpcomponents/httpclient/binary/httpcomponents-client-4.5.1-bin.tar.gz"))
   .forward(HttpForward.forward().withHost("www.us.apache.org").withPort(80));
 Tunnel tunnel = Tunnel.build("www.us.apache.org", 80, "localhost", PORT);
 try {
  IOUtils.copyLarge((InputStream) new URL("http://localhost:" + tunnel.getPort()
      + "/dist//httpcomponents/httpclient/binary/httpcomponents-client-4.5.1-bin.tar.gz")
      .getContent(new Class[]{InputStream.class}),
    new FileOutputStream(File.createTempFile("httpcomponents-client-4.5.1-bin", "tar.gz")));
 } finally {
  tunnel.close();
 }
}

代码示例来源:origin: stackoverflow.com

try {
 ImageView i = (ImageView)findViewById(R.id.image);
 Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
 i.setImageBitmap(bitmap); 
} catch (MalformedURLException e) {
 e.printStackTrace();
} catch (IOException e) {
 e.printStackTrace();
}

代码示例来源:origin: stackoverflow.com

/**
 * Function loads the users facebook profile pic
 * 
 * @param userID
 */
public Bitmap getUserPic(String userID) {
  String imageURL;
  Bitmap bitmap = null;
  Log.d(TAG, "Loading Picture");
  imageURL = "http://graph.facebook.com/"+userID+"/picture?type=small";
  try {
    bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageURL).getContent());
  } catch (Exception e) {
    Log.d("TAG", "Loading Picture FAILED");
    e.printStackTrace();
  }
  return bitmap;
}

代码示例来源:origin: stackoverflow.com

ImageView image = (ImageView)findViewById(R.id.image);
 if(!ImageUrl.equals("no image")) {          
   try {
     image.setImageDrawable(grabImageFromUrl(ImageUrl));
   } catch(Exception e) {     
    }  
 } 
 private Drawable grabImageFromUrl(String url) throws Exception {
    return Drawable.createFromStream((InputStream)new URL(url).getContent(), "src");
 }

代码示例来源:origin: multidots/android-app-common-tasks

public void run() {
    try {
      final Bitmap bitmap = BitmapFactory
          .decodeStream((InputStream) new URL(imgurl)
              .getContent());
      mImageView.post(new Runnable() {
        @Override
        public void run() {
          if (bitmap != null) {
            mImageView.setImageBitmap(bitmap);
          }
        }
      });
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}).start();

代码示例来源:origin: multidots/android-app-common-tasks

public void run() {
    try {
      final Bitmap bitmap = BitmapFactory
          .decodeStream((InputStream) new URL(imgurl)
              .getContent());
      mImageView.post(new Runnable() {
        @Override
        public void run() {
          if (bitmap != null) {
            mImageView.setImageBitmap(bitmap);
          }
        }
      });
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}).start();

代码示例来源:origin: stackoverflow.com

URL u = new URL("file:/"+System.getProperty("user.dir"));
PlainTextInputStream in = (PlainTextInputStream)u.getContent();

代码示例来源:origin: stackoverflow.com

remote_picture = BitmapFactory.decodeStream((InputStream) new URL(intent.getExtras().getString("imageurl")).getContent());
} catch (IOException e) {
  e.printStackTrace();

代码示例来源:origin: stackoverflow.com

public Drawable loadImageFromURL(String url, String name) {
  try {
    InputStream is = (InputStream) new URL(url).getContent();
    Drawable d = Drawable.createFromStream(is, name);
    return d;
  } catch (Exception e) {
    return null;
  }
}

代码示例来源:origin: stackoverflow.com

titleTv.setText(title);
contentTv.setText(content);
try {
 //where imageUrl is what you pulled out from the rss feed
 Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
 image.setImageBitmap(bitmap); 
} catch (MalformedURLException e) {
 //log exception here
} catch (IOException e) {
 //log exception here
}

代码示例来源:origin: org.apache.cocoon/cocoon-core

public void run() {
    try {
      URL url = new URL(this.uri);
      url.getContent();
    } catch (Exception ignore) {
    }
  }
}

代码示例来源:origin: stackoverflow.com

@Override public Drawable getDrawable(String url) {
 Drawable drawable = 
   Drawable.createFromStream((InputStream) new URL(url).getContent(), null);
 final float scalingFactor = 
   (float)textView.getMeasuredWidth() / d.getIntrinsicWidth();
 d.setBounds(0, 0, textView.getMeasuredWidth(), 
   (int) (d.getIntrinsicHeight()*scalingFactor));
}

相关文章