2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "NGMimeJoinedData.h"
25 #include "timeMacros.h"
26 #include <sys/types.h>
30 #include "NGMimeFileData.h"
32 @implementation NGMimeJoinedData
35 if ((self = [super init])) {
36 self->joinedDataObjects = [[NSMutableArray alloc] initWithCapacity:16];
42 [self->joinedDataObjects release];
46 - (id)copyWithZone:(NSZone*)zone {
50 - (NSArray *)_joinedDataObjects {
51 return self->joinedDataObjects;
54 - (void)appendData:(NSData *)_data {
55 if ([_data isKindOfClass:[NGMimeJoinedData class]]) {
56 [self->joinedDataObjects addObjectsFromArray:
57 [(NGMimeJoinedData *)_data _joinedDataObjects]];
60 [self->joinedDataObjects addObject:_data];
63 - (void)appendBytes:(const void *)_bytes
64 length:(unsigned int)_length
68 data = (NSMutableData *)[self->joinedDataObjects lastObject];
70 if ([data isKindOfClass:[NSMutableData class]]) {
71 [data appendBytes:_bytes length:_length];
74 data = [NSMutableData dataWithBytes:_bytes length:_length];
75 [self->joinedDataObjects addObject:data];
79 - (BOOL)writeToFile:(NSString*)_path
80 atomically:(BOOL)_useAuxiliaryFile
82 NSString *filename = nil;
83 NSEnumerator *enumerator;
91 fd = open([filename fileSystemRepresentation],
92 O_WRONLY | O_CREAT | O_TRUNC, 0600);
94 fprintf(stderr, "Could not open file for writing %s: %s\n",
95 [filename fileSystemRepresentation], strerror(errno));
100 enumerator = [self->joinedDataObjects objectEnumerator];
102 while ((data = [enumerator nextObject])) {
104 TIME_START("write bytes ");
106 if ([data isKindOfClass:[NGMimeFileData class]]) {
107 if (![(NGMimeFileData *)data appendDataToFileDesc:fd]) {
108 fprintf(stderr, "Failed to write %i bytes to %s: %s\n",
110 [filename fileSystemRepresentation], strerror(errno));
118 TIME_START("bytes ...")
119 bytes = [data bytes];
123 if (write(fd, bytes, len) != (int)len) {
124 fprintf(stderr, "Failed to write %i bytes to %s: %s\n",
125 len, [filename fileSystemRepresentation], strerror(errno));
137 - (NSString *)description {
138 return [NSString stringWithFormat:@"<0x%08X[%@]: joinedDataObjects=%d>",
139 self, NSStringFromClass([self class]),
140 [self->joinedDataObjects count]];
143 @end /* NGMimeJoinedData */