Re: Tiger Decoding problem
Re: Tiger Decoding problem
- Subject: Re: Tiger Decoding problem
- From: Nicholas Crosbie <email@hidden>
- Date: Mon, 30 May 2005 13:16:12 +1000 (EST)
Thanks very much to Ondra and Malcolm, but still
not quite there.
Program gives the following Run Log:
[Session started at 2005-05-30 12:56:39 +1000.]
2005-05-30 12:56:40.483 test2[716] ERROR: NSError "The
file could not be opened using specified text
encoding." Domain=NSCocoaErrorDomain Code=261
UserInfo={NSFilePath = "/Users/nicholas/test2/fileB";
}
test2 has exited with status 0.
I therefore tried the usedEncoding method, which I set
up as
following (please comment if incorrect).
// DECODE TO HUMAN READABLE FORM
#import <Cocoa/Cocoa.h>
int main() {
[NSAutoreleasePool new];
NSString *path = @"/Users/nicholas/test2/fileB";
NSError *myLog = nil;
NSStringEncoding *guessEnc = nil;
NSString *contents = [NSString
stringWithContentsOfFile:path usedEncoding:&guessEnc
error:&myLog]; // note the "&"
if (!contents) // could not read in the contents for
some reason: let us see the reason
NSLog(@"ERROR: %@",myLog); // which was filled into
myLog by the method
else /*all right*/ NSLog(@"OK: %@",contents);
return 0;
}
I get the same Run Log as when specifying an encoding.
Note that the data I'm trying to read says that "A
10-bit number would be stored in 16-bit space
.......leaving 6 empty bits"
Does this mean that I need to include a bitmask, even
just to open the file for decoding?
Can someone help with this?
Nick
--- Ondra Cada <email@hidden> wrote:
> Nicholas,
>
> well, it is all documented :), but it's always a
> pleasure to help a
> newbie :)
>
> On 30.5.2005, at 2:24, Nicholas Crosbie wrote:
> > What's wrong with my code (see below)?
>
> > #import <Cocoa/Cocoa.h>
> >
> > int main (int argc, char *argv[])
> > {
> > NSAutoreleasePool *pool = [NSAutoreleasePool
> new];
> > NSString *path = [NSString new];
>
> No need to create a new object...
>
> > path = @"/Users/nicholas/test2/fileB";
>
> ... to be immediately replaced by another. Also,
> with new it would
> leak (none of the errors so far is fatal).
>
> > NSString *contents = [NSString
> > stringWithContentsOfFile:path NSStringEncoding
>
> The "NSStringEncoding" above is the culprit it
> cannot be built. It
> just does not belong there. It is the argument type.
>
> > encoding:NSUTF8StringEncoding];
>
> Here you lack the error: argument.
>
> > NSLog(@"contents %@",contents);
> > [pool release];
>
> In this special case, not needed (but some would
> probably argue its
> cleaner from the theoretical point of view :))
>
> > return 0;
> > }
>
> All right, here is how it works:
>
> 56 /tmp> <q.m
> #import <Cocoa/Cocoa.h>
> int main() {
> [NSAutoreleasePool new];
> NSError *err; // no need to create/initialize any
> object, just
> declaring a variable
> NSString *contents=[NSString
> stringWithContentsOfFile:@"/tmp/q"
> encoding:NSUTF8StringEncoding error:&err];
> // note '&' above: the err variable is
> references, so that the
> method can change its value
> if (!contents) // could not read in the contents for
> some reason: let
> us see the reason
> NSLog(@"ERROR: %@",err); // which was filled into
> err by the method
> else /*all right*/ NSLog(@"OK: %@",contents);
> return 0;
> }
> 57 /tmp> cc -Wall -framework Cocoa q.m
> 58 /tmp> ./a.out
> 2005-05-30 03:40:36.851 a.out[2287] ERROR: NSError
> "File âqâ? does
> not exist." Domain=NSCocoaErrorDomain Code=260
> UserInfo={
> NSFilePath = "/tmp/q";
> NSUnderlyingError = NSError "POSIX error: No
> such file or
> directory" Domain=NSPOSIXErrorDomain Code=2;
> }
> 59 /tmp> touch q
> 60 /tmp> ./a.out
> 2005-05-30 03:40:46.810 a.out[2289] OK:
> 61 /tmp> echo 'Whatever' > q
> 62 /tmp> ./a.out
> 2005-05-30 03:41:02.233 a.out[2290] OK: Whatever
> 63 /tmp> # from TextEdit, saved into q a UTF-8
> nonsense
> 63 /tmp> ./a.out
> 2005-05-30 03:45:12.471 a.out[2308] ERROR: NSError
> "File âqâ? could
> not be opened using text encoding Unicode (UTF-8)."
>
> Domain=NSCocoaErrorDomain Code=261
> UserInfo={NSFilePath = "/tmp/q";
> NSStringEncoding = 4; }
> 64 /tmp>
>
> All right?
> ---
> Ondra Äada
> OCSoftware: email@hidden
> http://www.ocs.cz
> private email@hidden
> http://www.ocs.cz/oc
>
>
>
Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden