Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Http File을 보낼 때 사용.
#import "bsHttpFile.h"
#import "bsMacro.h"
@interface bsHttpFile(){
NSMutableDictionary *_files;
}
@end
@implementation bsHttpFile
static NSMutableArray *__bsHttpFile_pool = nil;
+(bsHttpFile*)POP {
__block bsHttpFile *r;
@synchronized( __bsHttpFile_pool ) {
if( __bsHttpFile_pool == nil ) {
__bsHttpFile_pool = [[NSMutableArray alloc]init];
}
if( [__bsHttpFile_pool count] > 0 ) {
r = [__bsHttpFile_pool lastObject];
[__bsHttpFile_pool removeLastObject];
} else {
r = [[bsHttpFile alloc] init];
}
};
return r;
}
+(void)PUT:(bsHttpFile*)file {
if( file == nil ) return;
@synchronized( __bsHttpFile_pool ) {
if( __bsHttpFile_pool == nil ) {
__bsHttpFile_pool = [[NSMutableArray alloc] init];
}
[file clear];
[__bsHttpFile_pool addObject:file];
};
}
-(void)addWithName:(NSString*)name data:(NSData*)data {
if( name == nil ) bsException( @"name is nil" );
if( data == nil ) bsException( @"data is nil" );
@synchronized( _files ) {
if( _files == nil ) {
_files = [[NSMutableDictionary alloc]init];
}
_files[[name copy]] = data;
}
}
-(void)loop:(void (^)(NSString *name, NSData *data))block {
@synchronized( _files ) {
[_files enumerateKeysAndObjectsUsingBlock:^(NSString *name, NSData *data, BOOL *stop) {
if( block ) block( name, data );
}];
}
}
-(NSUInteger)count {
@synchronized( _files ) {
if( _files ) {
return [_files count];
}
}
return 0;
}
-(void)clear {
@synchronized( _files ){
[_files removeAllObjects];
};
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment