当前位置: 编程技术>移动开发
本页文章导读:
▪gzip资料的解压缩 gzip文件的解压缩
to allow zlib compression/decompression of NSData. But a couple months ago I went looking for similar code to allow gzip compression/decompression. At the time I didn't find any, and found myself wading through the zlib docu.........
▪ 动态设立GridView宽,高 动态设置GridView宽,高
这里假设实例Id为mGrid:
RelativeLayout.LayoutParams linearParams = (RelativeLayout.LayoutParams) mGrid.getLayoutParams();
// 取控件mGrid当前的布局参数
linearParams.height = 150;
// 当控.........
▪ 汇集各大视频网站内容的网络视频播放器“天下视频" 汇集各大视频网站内容的网络视频播放器“天下视频"
天下视频集合了目前所有主流网络视频大站的资源,包括优酷、土豆、酷六、6间房、新浪视频等等,让您可以方便的欣赏各大站点的各.........
[1]gzip资料的解压缩
来源: 互联网 发布时间: 2014-02-18
gzip文件的解压缩
to allow zlib compression/decompression of NSData. But a couple months ago I went looking for similar code to allow gzip compression/decompression. At the time I didn't find any, and found myself wading through the zlib documentation and header files until I came up with a solution. I've recently noticed that someone else on CocoaDev has also mentioned the solution, but it looks like they didn't fully implement a deflate version of it. So, without further ado, here is an NSData category that adds support for gzip compression and decompression:
@interface NSData (DDData)
// gzip compression utilities
- (NSData *)gzipInflate;
- (NSData *)gzipDeflate;
@end
-----------------------------------------
#include
@implementation NSData (DDData)
- (NSData *)gzipInflate
{
if ([self length] == 0) return self;
unsigned full_length = [self length];
unsigned half_length = [self length] / 2;
NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length];
BOOL done = NO;
int status;
z_stream strm;
strm.next_in = (Bytef *)[self bytes];
strm.avail_in = [self length];
strm.total_out = 0;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
if (inflateInit2(&strm, (15+32)) != Z_OK) return nil;
while (!done)
{
// Make sure we have enough room and reset the lengths.
if (strm.total_out >= [decompressed length])
[decompressed increaseLengthBy: half_length];
strm.next_out = [decompressed mutableBytes] + strm.total_out;
strm.avail_out = [decompressed length] - strm.total_out;
// Inflate another chunk.
status = inflate (&strm, Z_SYNC_FLUSH);
if (status == Z_STREAM_END) done = YES;
else if (status != Z_OK) break;
}
if (inflateEnd (&strm) != Z_OK) return nil;
// Set real length.
if (done)
{
[decompressed setLength: strm.total_out];
return [NSData dataWithData: decompressed];
}
else return nil;
}
- (NSData *)gzipDeflate
{
if ([self length] == 0) return self;
z_stream strm;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.total_out = 0;
strm.next_in=(Bytef *)[self bytes];
strm.avail_in = [self length];
// Compresssion Levels:
// Z_NO_COMPRESSION
// Z_BEST_SPEED
// Z_BEST_COMPRESSION
// Z_DEFAULT_COMPRESSION
if (deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (15+16), 8, Z_DEFAULT_STRATEGY) != Z_OK) return nil;
NSMutableData *compressed = [NSMutableData dataWithLength:16384]; // 16K chunks for expansion
do {
if (strm.total_out >= [compressed length])
[compressed increaseLengthBy: 16384];
strm.next_out = [compressed mutableBytes] + strm.total_out;
strm.avail_out = [compressed length] - strm.total_out;
deflate(&strm, Z_FINISH);
} while (strm.avail_out == 0);
deflateEnd(&strm);
[compressed setLength: strm.total_out];
return [NSData dataWithData:compressed];
}
@end
转自 http://hi.baidu.com/leonqgl/blog/item/abe7eec7f9ac4dc6d10060b1.html
to allow zlib compression/decompression of NSData. But a couple months ago I went looking for similar code to allow gzip compression/decompression. At the time I didn't find any, and found myself wading through the zlib documentation and header files until I came up with a solution. I've recently noticed that someone else on CocoaDev has also mentioned the solution, but it looks like they didn't fully implement a deflate version of it. So, without further ado, here is an NSData category that adds support for gzip compression and decompression:
@interface NSData (DDData)
// gzip compression utilities
- (NSData *)gzipInflate;
- (NSData *)gzipDeflate;
@end
-----------------------------------------
#include
@implementation NSData (DDData)
- (NSData *)gzipInflate
{
if ([self length] == 0) return self;
unsigned full_length = [self length];
unsigned half_length = [self length] / 2;
NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length];
BOOL done = NO;
int status;
z_stream strm;
strm.next_in = (Bytef *)[self bytes];
strm.avail_in = [self length];
strm.total_out = 0;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
if (inflateInit2(&strm, (15+32)) != Z_OK) return nil;
while (!done)
{
// Make sure we have enough room and reset the lengths.
if (strm.total_out >= [decompressed length])
[decompressed increaseLengthBy: half_length];
strm.next_out = [decompressed mutableBytes] + strm.total_out;
strm.avail_out = [decompressed length] - strm.total_out;
// Inflate another chunk.
status = inflate (&strm, Z_SYNC_FLUSH);
if (status == Z_STREAM_END) done = YES;
else if (status != Z_OK) break;
}
if (inflateEnd (&strm) != Z_OK) return nil;
// Set real length.
if (done)
{
[decompressed setLength: strm.total_out];
return [NSData dataWithData: decompressed];
}
else return nil;
}
- (NSData *)gzipDeflate
{
if ([self length] == 0) return self;
z_stream strm;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.total_out = 0;
strm.next_in=(Bytef *)[self bytes];
strm.avail_in = [self length];
// Compresssion Levels:
// Z_NO_COMPRESSION
// Z_BEST_SPEED
// Z_BEST_COMPRESSION
// Z_DEFAULT_COMPRESSION
if (deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (15+16), 8, Z_DEFAULT_STRATEGY) != Z_OK) return nil;
NSMutableData *compressed = [NSMutableData dataWithLength:16384]; // 16K chunks for expansion
do {
if (strm.total_out >= [compressed length])
[compressed increaseLengthBy: 16384];
strm.next_out = [compressed mutableBytes] + strm.total_out;
strm.avail_out = [compressed length] - strm.total_out;
deflate(&strm, Z_FINISH);
} while (strm.avail_out == 0);
deflateEnd(&strm);
[compressed setLength: strm.total_out];
return [NSData dataWithData:compressed];
}
@end
转自 http://hi.baidu.com/leonqgl/blog/item/abe7eec7f9ac4dc6d10060b1.html
[2] 动态设立GridView宽,高
来源: 互联网 发布时间: 2014-02-18
动态设置GridView宽,高
这里假设实例Id为mGrid:
这里要说的是GridView的父View要是RelativeLayout的View类型,不然就会报错,本来这个尺寸设置都是相对父View来进行设置的.
现在写在这里供自己以后参考.
这里假设实例Id为mGrid:
RelativeLayout.LayoutParams linearParams = (RelativeLayout.LayoutParams) mGrid.getLayoutParams(); // 取控件mGrid当前的布局参数 linearParams.height = 150; // 当控件的高强制设成75象素 mGrid.setLayoutParams(linearParams); 使设置好的布局参数应用到控件mGrid2
这里要说的是GridView的父View要是RelativeLayout的View类型,不然就会报错,本来这个尺寸设置都是相对父View来进行设置的.
现在写在这里供自己以后参考.
[3] 汇集各大视频网站内容的网络视频播放器“天下视频"
来源: 互联网 发布时间: 2014-02-18
汇集各大视频网站内容的网络视频播放器“天下视频"
天下视频集合了目前所有主流网络视频大站的资源,包括优酷、土豆、酷六、6间房、新浪视频等等,让您可以方便的欣赏各大站点的各类视频,同时可以将您喜欢的视频分享到sina微博。
最新技术文章: