本文整理汇总了Java中com.nostra13.universalimageloader.utils.IoUtils.readAndCloseStream方法的典型用法代码示例。如果您正苦于以下问题:Java IoUtils.readAndCloseStream方法的具体用法?Java IoUtils.readAndCloseStream怎么用?Java IoUtils.readAndCloseStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.nostra13.universalimageloader.utils.IoUtils
的用法示例。
在下文中一共展示了IoUtils.readAndCloseStream方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStreamFromNetwork
import com.nostra13.universalimageloader.utils.IoUtils; //导入方法依赖的package包/类
/**
* Retrieves {@link InputStream} of image by URI (image is located in the network).
*
* @param imageUri Image URI
* @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object)
* DisplayImageOptions.extraForDownloader(Object)}; can be null
* @return {@link InputStream} of image
* @throws IOException if some I/O error occurs during network request or if no InputStream could be created for
* URL.
*/
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
HttpURLConnection conn = createConnection(imageUri, extra);
int redirectCount = 0;
while (conn.getResponseCode() / 100 == 3 && redirectCount < MAX_REDIRECT_COUNT) {
conn = createConnection(conn.getHeaderField("Location"), extra);
redirectCount++;
}
InputStream imageStream;
try {
imageStream = conn.getInputStream();
} catch (IOException e) {
// Read all data to allow reuse connection (http://bit.ly/1ad35PY)
IoUtils.readAndCloseStream(conn.getErrorStream());
throw e;
}
if (!shouldBeProcessed(conn)) {
IoUtils.closeSilently(imageStream);
throw new IOException("Image request failed with response code " + conn.getResponseCode());
}
return new ContentLengthInputStream(new BufferedInputStream(imageStream, BUFFER_SIZE), conn.getContentLength());
}
示例2: getStreamFromNetwork
import com.nostra13.universalimageloader.utils.IoUtils; //导入方法依赖的package包/类
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
HttpURLConnection conn = createConnection(imageUri, extra);
int redirectCount = 0;
while (conn.getResponseCode() / 100 == 3 && redirectCount < 5) {
conn = createConnection(conn.getHeaderField("Location"), extra);
redirectCount++;
}
try {
InputStream imageStream = conn.getInputStream();
if (shouldBeProcessed(conn)) {
return new ContentLengthInputStream(new BufferedInputStream(imageStream, 32768),
conn.getContentLength());
}
IoUtils.closeSilently(imageStream);
throw new IOException("Image request failed with response code " + conn
.getResponseCode());
} catch (IOException e) {
IoUtils.readAndCloseStream(conn.getErrorStream());
throw e;
}
}
示例3: getStreamFromNetwork
import com.nostra13.universalimageloader.utils.IoUtils; //导入方法依赖的package包/类
/**
* Retrieves {@link InputStream} of image by URI (image is located in the network).
*
* @param imageUri Image URI
* @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object)
* DisplayImageOptions.extraForDownloader(Object)}; can be null
* @return {@link InputStream} of image
* @throws IOException if some I/O error occurs during network request or if no InputStream could be created for
* URL.
*/
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
HttpURLConnection conn = createConnection(imageUri, extra);
int redirectCount = 0;
while (conn.getResponseCode() / 100 == 3 && redirectCount < MAX_REDIRECT_COUNT) {
conn = createConnection(conn.getHeaderField("Location"), extra);
redirectCount++;
}
InputStream imageStream;
try {
imageStream = conn.getInputStream();
} catch (IOException e) {
// Read all data to allow reuse connection (http://bit.ly/1ad35PY)
IoUtils.readAndCloseStream(conn.getErrorStream());
throw e;
}
return new ContentLengthInputStream(new BufferedInputStream(imageStream, BUFFER_SIZE), conn.getContentLength());
}
示例4: getStreamFromNetwork
import com.nostra13.universalimageloader.utils.IoUtils; //导入方法依赖的package包/类
/**
* Retrieves {@link java.io.InputStream} of image by URI (image is located in the network).
*
* @param imageUri Image URI
* @param extra Auxiliary object which was passed to {@link com.nostra13.universalimageloader.core.DisplayImageOptions.Builder#extraForDownloader(Object)
* DisplayImageOptions.extraForDownloader(Object)}; can be null
* @return {@link java.io.InputStream} of image
* @throws java.io.IOException if some I/O error occurs during network request or if no InputStream could be created for
* URL.
*/
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
HttpURLConnection conn = createConnection(imageUri, extra);
int redirectCount = 0;
while (conn.getResponseCode() / 100 == 3 && redirectCount < MAX_REDIRECT_COUNT) {
conn = createConnection(conn.getHeaderField("Location"), extra);
redirectCount++;
}
InputStream imageStream;
try {
imageStream = conn.getInputStream();
} catch (IOException e) {
// Read all data to allow reuse connection (http://bit.ly/1ad35PY)
IoUtils.readAndCloseStream(conn.getErrorStream());
throw e;
}
return new ContentLengthInputStream(new BufferedInputStream(imageStream, BUFFER_SIZE), conn.getContentLength());
}
示例5: getStreamFromNetwork
import com.nostra13.universalimageloader.utils.IoUtils; //导入方法依赖的package包/类
protected InputStream getStreamFromNetwork(String s, Object obj)
{
HttpURLConnection httpurlconnection = createConnection(s, obj);
for (int i = 0; httpurlconnection.getResponseCode() / 100 == 3 && i < 5; i++)
{
httpurlconnection = createConnection(httpurlconnection.getHeaderField("Location"), obj);
}
InputStream inputstream;
try
{
inputstream = httpurlconnection.getInputStream();
}
catch (IOException ioexception)
{
IoUtils.readAndCloseStream(httpurlconnection.getErrorStream());
throw ioexception;
}
return new ContentLengthInputStream(new BufferedInputStream(inputstream, 32768), httpurlconnection.getContentLength());
}
示例6: getStreamFromNetwork
import com.nostra13.universalimageloader.utils.IoUtils; //导入方法依赖的package包/类
/**
* 通过图片的网络地址来获取图片流--当前图片通过网络获取
* Retrieves {@link InputStream} of image by URI (image is located in the network).
*
* @param imageUri Image URI
* @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object)
* DisplayImageOptions.extraForDownloader(Object)}; can be null
* @return {@link InputStream} of image
* @throws IOException if some I/O error occurs during network request or if no InputStream could be created for
* URL.
*/
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
//创建网络连接
HttpURLConnection conn = createConnection(imageUri, extra);
//对于重定向进行判断判断,重定向的次数最大5次循环获取
int redirectCount = 0;
while (conn.getResponseCode() / 100 == 3 && redirectCount < MAX_REDIRECT_COUNT) {
conn = createConnection(conn.getHeaderField("Location"), extra);
redirectCount++;
}
//获取到图像流
InputStream imageStream;
try {
imageStream = conn.getInputStream();
} catch (IOException e) {
// Read all data to allow reuse connection (http://bit.ly/1ad35PY)
IoUtils.readAndCloseStream(conn.getErrorStream());
throw e;
}
if (!shouldBeProcessed(conn)) {
IoUtils.closeSilently(imageStream);
throw new IOException("Image request failed with response code " + conn.getResponseCode());
}
//对图像流数据进行包装
return new ContentLengthInputStream(new BufferedInputStream(imageStream, BUFFER_SIZE), conn.getContentLength());
}
示例7: getStreamFromNetwork
import com.nostra13.universalimageloader.utils.IoUtils; //导入方法依赖的package包/类
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
HttpURLConnection conn = createConnection(imageUri, extra);
int redirectCount = 0;
while (conn.getResponseCode() / 100 == 3 && redirectCount < 5) {
conn = createConnection(conn.getHeaderField(HttpRequest.HEADER_LOCATION), extra);
redirectCount++;
}
try {
return new ContentLengthInputStream(new BufferedInputStream(conn.getInputStream(), 32768), conn.getContentLength());
} catch (IOException e) {
IoUtils.readAndCloseStream(conn.getErrorStream());
throw e;
}
}