• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

8-bit US ASCII

 
Khaled Mahmoud
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic