Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Reading large files from NSInputstream is not working in ios

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 1.98k
    Answer it

    I am trying to read large Image file more than 300KB from NSInputStream. But i'm getting only upto 300KB. Other data are missing. Could you please help me if you know. i'm waiting for your valuable answer. I mentioned my code below : Call this readAllData method from NSStreamEventsHasBytesAvailable:

    1. - (void)readAllData {
    2.  
    3. if ( _readData == nil) {
    4. _readData = [[NSMutableData data] retain];
    5. }
    6.  
    7. while ([[ _session inputStream] hasBytesAvailable])
    8. {
    9. unsigned int bytesRead = 0;
    10. bytesRead = [[ _session inputStream] read:buf maxLength: @"1024"];
    11.  
    12. if (bytesRead) {
    13.  
    14. NSMutableString * _string = [NSMutableString stringWithString:@""];
    15. for (int i = 0; i < _readData.length; i++) {
    16. unsigned char _byte;
    17. [&#95;readData getBytes:&&#95;byte range:NSMakeRange(i, 1)];
    18. i f ( _byte >= 32 && _byte < 127) {
    19. [ _string appendFormat:@"%c", _byte];
    20. } else {
    21. [ _string appendFormat:@"[%d]", _byte];
    22. }
    23. }
    24.  
    25. [ _readData appendBytes:(const void *)buf length:bytesRead];
    26.  
    27. }
    28.  
    29. }
    30.  
    31. NSString *string=[NSString stringWithFormat:@"%d", _readData.length];
    32. UIAlertView *sesView = [[UIAlertView alloc] initWithTitle:@"readDatalength"
    33. message:string
    34. delegate:self
    35. cancelButtonTitle:nil otherButtonTitles:@"OK" , nil];
    36. [sesView show];
    37. }

 1 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: