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


Java IoUtils类代码示例

本文整理汇总了Java中com.nostra13.universalimageloader.utils.IoUtils的典型用法代码示例。如果您正苦于以下问题:Java IoUtils类的具体用法?Java IoUtils怎么用?Java IoUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IoUtils类属于com.nostra13.universalimageloader.utils包,在下文中一共展示了IoUtils类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: save

import com.nostra13.universalimageloader.utils.IoUtils; //导入依赖的package包/类
@Override
public boolean save(String imageUri, InputStream imageStream, IoUtils.CopyListener listener) throws IOException {
	File imageFile = getFile(imageUri);
	File tmpFile = new File(imageFile.getAbsolutePath() + TEMP_IMAGE_POSTFIX);
	boolean loaded = false;
	try {
		OutputStream os = new BufferedOutputStream(new FileOutputStream(tmpFile), bufferSize);
		try {
			loaded = IoUtils.copyStream(imageStream, os, listener, bufferSize);
		} finally {
			IoUtils.closeSilently(os);
		}
	} finally {
		if (loaded && !tmpFile.renameTo(imageFile)) {
			loaded = false;
		}
		if (!loaded) {
			tmpFile.delete();
		}
	}
	return loaded;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:BaseDiskCache.java

示例2: save

import com.nostra13.universalimageloader.utils.IoUtils; //导入依赖的package包/类
@Override
public boolean save(String imageUri, InputStream imageStream, IoUtils.CopyListener listener) throws IOException {
	DiskLruCache.Editor editor = cache.edit(getKey(imageUri));
	if (editor == null) {
		return false;
	}

	OutputStream os = new BufferedOutputStream(editor.newOutputStream(0), bufferSize);
	boolean copied = false;
	try {
		copied = IoUtils.copyStream(imageStream, os, listener, bufferSize);
	} finally {
		IoUtils.closeSilently(os);
		if (copied) {
			editor.commit();
		} else {
			editor.abort();
		}
	}
	return copied;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:LruDiskCache.java

示例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;
	}
	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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:BaseImageDownloader.java

示例4: save

import com.nostra13.universalimageloader.utils.IoUtils; //导入依赖的package包/类
public boolean save(String imageUri, Bitmap bitmap) throws IOException {
    File imageFile = getFile(imageUri);
    File tmpFile = new File(imageFile.getAbsolutePath() + TEMP_IMAGE_POSTFIX);
    OutputStream os = new BufferedOutputStream(new FileOutputStream(tmpFile), this.bufferSize);
    boolean savedSuccessfully = false;
    try {
        savedSuccessfully = bitmap.compress(this.compressFormat, this.compressQuality, os);
        bitmap.recycle();
        return savedSuccessfully;
    } finally {
        IoUtils.closeSilently(os);
        if (savedSuccessfully && !tmpFile.renameTo(imageFile)) {
            savedSuccessfully = false;
        }
        if (!savedSuccessfully) {
            tmpFile.delete();
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:20,代码来源:BaseDiscCache.java

示例5: save

import com.nostra13.universalimageloader.utils.IoUtils; //导入依赖的package包/类
public boolean save(String imageUri, InputStream imageStream, CopyListener listener) throws IOException {
    boolean z = false;
    Editor editor = this.cache.edit(getKey(imageUri));
    if (editor != null) {
        OutputStream os = new BufferedOutputStream(editor.newOutputStream(0), this.bufferSize);
        z = false;
        try {
            z = IoUtils.copyStream(imageStream, os, listener, this.bufferSize);
        } finally {
            IoUtils.closeSilently(os);
            if (z) {
                editor.commit();
            } else {
                editor.abort();
            }
        }
    }
    return z;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:20,代码来源:LruDiscCache.java

示例6: save

import com.nostra13.universalimageloader.utils.IoUtils; //导入依赖的package包/类
public boolean save(String imageUri, InputStream imageStream, CopyListener listener) throws
        IOException {
    boolean z = false;
    Editor editor = this.cache.edit(getKey(imageUri));
    if (editor != null) {
        OutputStream os = new BufferedOutputStream(editor.newOutputStream(0), this.bufferSize);
        z = false;
        try {
            z = IoUtils.copyStream(imageStream, os, listener, this.bufferSize);
        } finally {
            IoUtils.closeSilently(os);
            if (z) {
                editor.commit();
            } else {
                editor.abort();
            }
        }
    }
    return z;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:LruDiskCache.java

示例7: decode

import com.nostra13.universalimageloader.utils.IoUtils; //导入依赖的package包/类
public Bitmap decode(ImageDecodingInfo decodingInfo) throws IOException {
    Bitmap bitmap = null;
    InputStream imageStream = getImageStream(decodingInfo);
    if (imageStream == null) {
        L.e(ERROR_NO_IMAGE_STREAM, decodingInfo.getImageKey());
        return bitmap;
    }
    try {
        ImageFileInfo imageInfo = defineImageSizeAndRotation(imageStream, decodingInfo);
        imageStream = resetStream(imageStream, decodingInfo);
        bitmap = BitmapFactory.decodeStream(imageStream, null, prepareDecodingOptions
                (imageInfo.imageSize, decodingInfo));
        if (bitmap != null) {
            return considerExactScaleAndOrientatiton(bitmap, decodingInfo, imageInfo.exif
                    .rotation, imageInfo.exif.flipHorizontal);
        }
        L.e(ERROR_CANT_DECODE_IMAGE, decodingInfo.getImageKey());
        return bitmap;
    } finally {
        IoUtils.closeSilently(imageStream);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:BaseImageDecoder.java

示例8: 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;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:22,代码来源:BaseImageDownloader.java

示例9: save

import com.nostra13.universalimageloader.utils.IoUtils; //导入依赖的package包/类
@Override
public boolean save(String imageUri, InputStream imageStream, IoUtils.CopyListener listener) throws IOException {
	File imageFile = getFile(imageUri);
	File tmpFile = new File(imageFile.getAbsolutePath() + TEMP_IMAGE_POSTFIX);
	boolean loaded = false;
	try {
		OutputStream os = new BufferedOutputStream(new FileOutputStream(tmpFile), bufferSize);
		try {
			loaded = IoUtils.copyStream(imageStream, os, listener, bufferSize);
		} finally {
			IoUtils.closeSilently(os);
		}
	} finally {
		IoUtils.closeSilently(imageStream);
		if (loaded && !tmpFile.renameTo(imageFile)) {
			loaded = false;
		}
		if (!loaded) {
			tmpFile.delete();
		}
	}
	return loaded;
}
 
开发者ID:xulailing,项目名称:android-open-project-demo-master,代码行数:24,代码来源:BaseDiscCache.java

示例10: decode

import com.nostra13.universalimageloader.utils.IoUtils; //导入依赖的package包/类
/**
 * Decodes image from URI into {@link Bitmap}. Image is scaled close to incoming {@linkplain ImageSize target size}
 * during decoding (depend on incoming parameters).
 *
 * @param decodingInfo Needed data for decoding image
 * @return Decoded bitmap
 * @throws IOException                   if some I/O exception occurs during image reading
 * @throws UnsupportedOperationException if image URI has unsupported scheme(protocol)
 */
@Override
public Bitmap decode(ImageDecodingInfo decodingInfo) throws IOException {
	Bitmap decodedBitmap;
	ImageFileInfo imageInfo;

	InputStream imageStream = getImageStream(decodingInfo);
	try {
		imageInfo = defineImageSizeAndRotation(imageStream, decodingInfo);
		imageStream = resetStream(imageStream, decodingInfo);
		Options decodingOptions = prepareDecodingOptions(imageInfo.imageSize, decodingInfo);
		decodedBitmap = BitmapFactory.decodeStream(imageStream, null, decodingOptions);
	} finally {
		IoUtils.closeSilently(imageStream);
	}

	if (decodedBitmap == null) {
		L.e(ERROR_CANT_DECODE_IMAGE, decodingInfo.getImageKey());
	} else {
		decodedBitmap = considerExactScaleAndOrientatiton(decodedBitmap, decodingInfo, imageInfo.exif.rotation,
				imageInfo.exif.flipHorizontal);
	}
	return decodedBitmap;
}
 
开发者ID:xulailing,项目名称:android-open-project-demo-master,代码行数:33,代码来源:BaseImageDecoder.java

示例11: 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());
}
 
开发者ID:xulailing,项目名称:android-open-project-demo-master,代码行数:30,代码来源:BaseImageDownloader.java


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