nsinputstream

SWIFT ONLY — Reading from NSInputStream [closed]

放肆的年华 提交于 2019-12-03 09:13:07
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . Could you please explain me how do I read properly from an NSInputStream? I couldn't understand what is UnsafePointer and what's the use of it (also for UnsafeArray). The NSInputStream read function gets an CMutablePointer which can be filled with an UnsafePointer object. It's a real mess comparing

Do the stream classes in Cocoa support seeking?

北慕城南 提交于 2019-12-02 04:03:20
问题 I need a Cocoa class that can read and write from a memory stream and that supports seeking. In C#, MemoryStream supports the method seek , and in Java, ByteArrayInputStream supports the methods mark , skip , and reset . In iOS development, what are the equivalent class and method? I need the above functionality for my project, and if it is by default not supported by the iOS frameworks, what would be the best way of going about implementing my own? E.g. write my own stream subclass

Do the stream classes in Cocoa support seeking?

雨燕双飞 提交于 2019-12-02 02:31:40
I need a Cocoa class that can read and write from a memory stream and that supports seeking. In C#, MemoryStream supports the method seek , and in Java, ByteArrayInputStream supports the methods mark , skip , and reset . In iOS development, what are the equivalent class and method? I need the above functionality for my project, and if it is by default not supported by the iOS frameworks, what would be the best way of going about implementing my own? E.g. write my own stream subclass inheriting from NSInputStream / NSOutputStream which will internally contain custom code? An arbitrary

Background Upload With Stream Request Using NSUrlSession in iOS8

让人想犯罪 __ 提交于 2019-12-01 13:42:05
Previously in iOS7 when we try to upload with stream request in background we get following exception Terminating app due to uncaught exception 'NSGenericException', reason: 'Upload tasks in background sessions must be from a file' But in iOS8 there is no exception when we try to upload with stream in background. Now my question is 1) Is backgourd upload with uploadTaskWithStreamedRequest: allowed in iOS8? 2) In iOS8 i am using background NSURLConfiguration with uploadTaskWithStreamedRequest . I am using -(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task needNewBodyStream:

Convert an Objective-C method into Swift for NSInputStream (convert bytes into double)

别说谁变了你拦得住时间么 提交于 2019-12-01 11:24:35
I have the following code in Objective-C: - (double)readDouble { double value = 0.0; if ([self read:(uint8_t *)&value maxLength:8] != 8) { NSLog(@"***** Couldn't read double"); } return value; } It works. But I don't know how to convert it to Swift. Here is my code: public func readDouble() -> Double { var value : Double = 0.0 var num = self.read((uint8_t *)&value, maxLength:8) // got compiling error here! if num != 8 { } } The error message is: Cannot invoke '&' with an argument list of type '($T4, maxLength: IntegerLiteralConvertible)' Can anybody help? Thanks The testing data I'm using (1

-[NSInputStream read:maxLength:] throws an exception saying length is too big, but it isn't

不羁的心 提交于 2019-12-01 05:29:17
I use an NSInputStream to read data from a file. It will crash if maxLength is greater than 49152. When it crashes -- sometimes, but not every time, it gives this message: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSConcreteData initWithBytes:length:copy:freeWhenDone:bytesAreVM:]: absurd length: 4294967295, maximum size: 2147483648 bytes' From my calculation, 524288 is still less than that maximum, and can fit in the return value. What did I miss? - (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode { switch (eventCode) { case

Using NSXMLParser initWithStream: no parser delegate methods received

痴心易碎 提交于 2019-11-30 16:04:43
问题 The basic problem I'm working on is using the NSStream classes to parse incoming incremental XML data. The data is never a complete XML Document, but I want to receive and process it in incremental chunks based off how much ever the socket can read. Looking at the documentation for NSXMLParser , it seems like the initWithStream: method to initialize a NSXMLParser would be the perfect solution to my problem. I can initialize the parser with a NSInputStream and then call the parse method on

Streaming NSXMLParser with NSInputStream

雨燕双飞 提交于 2019-11-30 05:13:15
Update: When using NSXMLParser class method initWithContentsOfURL , rather than parsing as the XML feed is downloaded, it appears to try to load the entire XML file into memory, and only then initiate the parsing process. This is problematic if the XML feed is large (using an excessive amount of RAM, inherently inefficient because rather than parsing in parallel with the download, it only starts the parsing once the download is done, etc.). Has anyone discovered how to parse as the feed is being streamed to the device using NSXMLParser ? Yes, you can use LibXML2 (as discussed below), but it

NSInputStream stops running, sometimes throws EXC_BAD_ACCESS

喜欢而已 提交于 2019-11-29 20:42:19
(UPDATED) this is the problem in a nutshell: in iOS I want to read a large file, do some processing on it (in this particular case encode as Base64 string() and save to a temp file on the device. I set up an NSInputStream to read from a file, then in (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode I'm doing most of the work. For some reason, sometimes I can see the NSInputStream just stops working. I know because I have a line NSLog(@"stream %@ got event %x", stream, (unsigned)eventCode); in the beginning of (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent

Streaming NSXMLParser with NSInputStream

断了今生、忘了曾经 提交于 2019-11-29 03:07:15
问题 Update: When using NSXMLParser class method initWithContentsOfURL , rather than parsing as the XML feed is downloaded, it appears to try to load the entire XML file into memory, and only then initiate the parsing process. This is problematic if the XML feed is large (using an excessive amount of RAM, inherently inefficient because rather than parsing in parallel with the download, it only starts the parsing once the download is done, etc.). Has anyone discovered how to parse as the feed is