ObjFW  Check-in [c79d076e58]

Overview
Comment:OFDataArray: Handle exceptions in init
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c79d076e58b8e201fed98b0f016c7f6b71b3da0185a722b70694419eb5b8ae81
User & Date: js on 2014-09-10 21:51:54
Other Links: manifest | tags
Context
2014-09-10
22:09
Fix OFBigDataArray's initWithStringRepresentation: check-in: ab270674db user: js tags: trunk
21:51
OFDataArray: Handle exceptions in init check-in: c79d076e58 user: js tags: trunk
14:05
Add OFBigDataArray.h to ObjFW.h check-in: 27902a926c user: js tags: trunk
Changes

Modified src/OFDataArray.m from [0c152683c1] to [e60942ae0f].

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223



















224
225
226
227

228
229
230
231
232
233
234
235
236
237
238
239
240
241





242
243
244
245
246
247
248
#ifdef OF_HAVE_FILES
	if ([scheme isEqual: @"file"])
		self = [self initWithContentsOfFile: [URL path]];
	else
#endif
#ifdef OF_HAVE_SOCKETS
	if ([scheme isEqual: @"http"] || [scheme isEqual: @"https"]) {
		OFHTTPClient *client = [OFHTTPClient client];
		OFHTTPRequest *request = [OFHTTPRequest requestWithURL: URL];
		OFHTTPResponse *response = [client performRequest: request];
		size_t pageSize;
		char *buffer;
		OFDictionary *headers;
		OFString *contentLength;

		if ([response statusCode] != 200)
			@throw [OFHTTPRequestFailedException
			    exceptionWithRequest: request
					response: response];

		self = [self init];

		pageSize = [OFSystemInfo pageSize];
		buffer = [self allocMemoryWithSize: pageSize];

		@try {



















			while (![response isAtEndOfStream]) {
				size_t length;

				length = [response readIntoBuffer: buffer

							   length: pageSize];
				[self addItems: buffer
					 count: length];
			}
		} @finally {
			[self freeMemory: buffer];
		}

		headers = [response headers];
		if ((contentLength =
		    [headers objectForKey: @"Content-Length"]) != nil)
			if ([self count] !=
			    (size_t)[contentLength decimalValue])
				@throw [OFTruncatedDataException exception];





	} else
#endif
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];

	objc_autoreleasePoolPop(pool);

	return self;







<
<
<
<
<
<
<
<
<
<
<
<
<


<
<
<

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|

|
>
|
|
|
|
|
|
|

|
|
|
|
|
|
>
>
>
>
>







198
199
200
201
202
203
204













205
206



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#ifdef OF_HAVE_FILES
	if ([scheme isEqual: @"file"])
		self = [self initWithContentsOfFile: [URL path]];
	else
#endif
#ifdef OF_HAVE_SOCKETS
	if ([scheme isEqual: @"http"] || [scheme isEqual: @"https"]) {













		self = [self init];




		@try {
			OFHTTPClient *client = [OFHTTPClient client];
			OFHTTPRequest *request = [OFHTTPRequest
			    requestWithURL: URL];
			OFHTTPResponse *response = [client
			    performRequest: request];
			size_t pageSize;
			char *buffer;
			OFDictionary *headers;
			OFString *contentLength;

			if ([response statusCode] != 200)
				@throw [OFHTTPRequestFailedException
				    exceptionWithRequest: request
						response: response];

			pageSize = [OFSystemInfo pageSize];
			buffer = [self allocMemoryWithSize: pageSize];

			@try {
				while (![response isAtEndOfStream]) {
					size_t length;

					length = [response
					    readIntoBuffer: buffer
						    length: pageSize];
					[self addItems: buffer
						 count: length];
				}
			} @finally {
				[self freeMemory: buffer];
			}

			headers = [response headers];
			if ((contentLength =
			    [headers objectForKey: @"Content-Length"]) != nil)
				if ([self count] !=
				    (size_t)[contentLength decimalValue])
					@throw [OFTruncatedDataException
					    exception];
		} @catch (id e) {
			[self release];
			@throw e;
		}
	} else
#endif
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];

	objc_autoreleasePoolPop(pool);

	return self;