Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mac Character encoding



Hi Nicholas,

That's great thanks! Now I've finding the encoding to
the common ISO-8859-1 is not going to be satisfactory
to me as well.

What I'm finding that I need is to model in HTML what
swing components' use to encode strings, as well as
what the modern operating systems use for their file
system as well. i.e. filenames, directories, etc.

So I wish to have a string defining an object name,
and if the name includes foreign non-ASCII characters,
still have it properly represented in HTML as well as
the file system.

I believe swing Unicode utf-8 to do this. I know more
modern web browsers can support this. Not sure about
the mac file system. Probably the same..

If you have information with this regards, I'd
appreciate any feedback.

Regards,
Mike




--- "Nicholas R. Rinard" <email@hidden> wrote:

> I don't know if this will help, but I also had to
> struggle with 
> character encodings. I had a lot of trouble before I
> settled on UTF-16, 
> then I had more trouble before I figured out how to
> master the 
> byte-order mark at the front of UTF-16 files. At the
> bottom is the code 
> I wrote long ago to read in and write out files in
> UTF-16. For what 
> it's worth, since I figured this out I haven't had
> any trouble with any 
> character encoding at all because UTF-16 supports
> just about every 
> character in the world (right?).
> 
> peace
> Nicholas
> 
> 
> 
> 
> 
> 
> 
>      // dumps the contents of the file into a string
>      // ONLY WORKS WITH UTF-16 FILES INCLUDING A
> BYTE ORDER MARK
>      // the BOM is two bytes at the front of a
> UNICODE UTF-16 file
>      // which indicate... well, the byte order used
> in the file.
>      // the BOM will indicate either big-endian or
> little-endian.
>      // the BOM is not returned as a character from
> the file so long
>      // as we explicitly tell Java to interpret the
> file as UTF-16
>      protected static String dumpFile( File f ) {
>          StringBuffer ret = new StringBuffer();
>          try {
>              InputStreamReader reader = new
> InputStreamReader( new 
> FileInputStream( f ), "UTF-16" );
>              for( int c = reader.read(); c != -1; c
> = reader.read() ) {
>                  ret.append( (char) c );
>              }
>          } catch( Exception e ) {
>              Lex.out.error( "Error while trying to
> read file \"" + 
> f.getName() + "\": " + e.toString() );
>          }
>          return ret.toString();
>      }
> 
>      // writes an asset object to a given file
>      // ONLY WORKS WRITING OUT UTF-16 FILES
> INCLUDING A BYTE ORDER MARK
>      // explicitly written to work with UTF 16 files
> only
>      protected void writeAssetToFile( Asset asset,
> File f ) {
>          try {
>              FileOutputStream outStream = new
> FileOutputStream( f );
>              outStream.write(
> asset.getXmlDescription().getBytes( 
> "UTF-16" ) );
>              outStream.close();
>          } catch( FileNotFoundException fnfe ) {
>              Lex.out.error( "Could not write asset
> \"" + asset.getName() 
> + "\" to file because the output file could not be
> found: " + fnfe );
>          } catch( IOException ioe ) {
>              Lex.out.error( "Could not write asset
> \"" + asset.getName() 
> + "\" to file because an I/O error occured: " + ioe
> );
>          }
>      }
> 
>  _______________________________________________
> Do not post admin requests to the list. They will be
> ignored.
> Java-dev mailing list     
> (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
http://lists.apple.com/mailman/options/java-dev/email@hidden
> 
> This email sent to email@hidden
> 

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: Mac Character encoding (From: "Nicholas R. Rinard" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.