アプリケーションからのデータのエクスポートを処理するコードが少しあります。XMLでいっぱいのNSStringを取り込んで、PHPスクリプトを介して実行し、HTM1、RTFなどを生成します。ユーザーが大きなリストを持っていない限り、うまく機能します。これは明らかに、NSPipeの8k程度のバッファをオーバーランしているためです。
readPipeとreadHandleで(私は思うに)回避しましたが、writeHandle/writePipeでどのように処理するかわかりません。アプリケーションは[writeHandle writeData:[in...
、gdbで中断しない限り、ビーチボールになります。数秒待ってから続行します。
コードでこれを回避する方法について何か助けはありますか?
- (NSString *)outputFromExporter:(COExporter *)exporter input:(NSString *)input {
NSString *exportedString = nil;
NSString *path = [exporter path];
NSTask *task = [[NSTask alloc] init];
NSPipe *writePipe = [NSPipe pipe];
NSFileHandle *writeHandle = [writePipe fileHandleForWriting];
NSPipe *readPipe = [NSPipe pipe];
NSFileHandle *readHandle = [readPipe fileHandleForReading];
NSMutableData *outputData = [[NSMutableData alloc] init];
NSData *readData = nil;
// Set the launch path and I/O for the task
[task setLaunchPath:path];
[task setStandardInput:writePipe];
[task setStandardOutput:readPipe];
// Launch the exporter, it will convert the raw OPML into HTML, Plaintext, etc
[task launch];
// Write the raw OPML representation to the exporter's input stream
[writeHandle writeData:[input dataUsingEncoding:NSUTF8StringEncoding]];
[writeHandle closeFile];
while ((readData = [readHandle availableData]) && [readData length]) {
[outputData appendData:readData];
}
exportedString = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
return exportedString;
}