File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes 8-bit US ASCII Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "8-bit US ASCII" Watch "8-bit US ASCII" New topic
Author

8-bit US ASCII

Khaled Mahmoud
Ranch Hand

Joined: Jul 15, 2006
Posts: 361
I almost finished 75% of the application.While reading the instructions document again the following sentance confused me :


The character encoding is 8 bit US ASCII.
Database schema


When converting string to bytes as the charset name "ASCII" and here is the code :

Such simple mistakes can cause to fail the assignment.In my code this statament throws a UnsupportedEncodingException.
I catch this exception an then throw a RunTime exception that indicates that the US-ASCII encoding is not supported.
What do you think??


SCJP, SCJD,SCWCD,SCDJWS,SCEA 5 MCP-C#, MCP-ASP.NET - http://www.khaledinho.com/
Life is the biggest school
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
The encoding ASCII is a 7-bit encoding, namely, it just supports characters from 0-127.

My assignment says that I should use 8-bit encoding. Therefore I think you should revise this.

Go over the list of Supported Encodings.

I think the ISO-8859-X family are 8-bit encodings, as well as windows-1252
(aka Cp1252).

Now, you should use the encoding every time you read a bunch of bytes from the database and you want to convert them to a String, and also every time you want to convert a String into a bunch of bytes to write them back into the database.

If you use ASCII encoding you will only be able to represent as byte the first 128 characters, that is, you would be using just the first 7 bits of every character spectrum.

Whether you want to throw UnsupportedEncondingException or not is up to you and your design. In my case I absorb the exception and use the default encoding when this exception happens. However, I do that because when I try to create the database object I always check that the proposed encoding is supported using java.nio.charset.Charset.isSupported(String) method. Therefore I am not expecting this exception to happen here.
[ October 26, 2006: Message edited by: Edwin Dalorzo ]
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Khaled Mahmoud:
I almost finished 75% of the application.While reading the instructions document again the following sentance confused me :



When converting string to bytes as the charset name "ASCII" and here is the code :

Such simple mistakes can cause to fail the assignment.In my code this statament throws a UnsupportedEncodingException.
I catch this exception an then throw a RunTime exception that indicates that the US-ASCII encoding is not supported.
What do you think??


Hi Khaled,
The reason for the UnsupportedEncodingException is that the encoding type string you have entered is incorrect. The encoding string for Ascii is "US-ASCII" not "ASCII"
[ October 27, 2006: Message edited by: Mark Smyth ]

SCJP<br />SCJD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 8-bit US ASCII
 
Similar Threads
Writting to the DB File - totally lost
NX:[URLyBird]Get the correct field values
writeUTF() and writeBytes()
NX: US-ASCII confusion
8-bit US ASCII encoding???