• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The character encoding is 8 bit US ASCII

 
Mike Tilling
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using the RandomAccessFile object primitives to read and write from/into any location of the database file. I created the RandomAccessFile object like this: new RandomAccessFile(file, "rw"),

do I need any further parameter to specify in the RandomAccessFile arguments list to force the "8 bit US ASCII" character encoding to be used?

Best Regards
 
Paul Clapham
Sheriff
Posts: 21583
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no such thing as "8 bit US ASCII" (US ASCII is a 7-bit encoding). But in any case, you would specify the encoding when you write to the file, not when you create it. And it would be up to your code to do that encoding to bytes before you write the bytes, since there aren't any mechanisms in RandomAccessFile to do encoding except for the writeUTF method.

However, encoding to US-ASCII can only be at best an information-losing process. Would you like to explain a little more why this question arose?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Clapham:

However, encoding to US-ASCII can only be at best an information-losing process. Would you like to explain a little more why this question arose?


The question arises because of the following requirement specified by Sun for the SCJD assignment (quoted from my own assignment):
All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two places where a check for the character encoding (US-ASCII).

Reading Operations:
-------------------
When I read a bunch of bytes from the file I conver them to String objects using new String(byte[] data,String encoding). In this case I provide the encoding to convert the bytes into a String.


Writing Operations:
-------------------
When I write a String into the database file I first convert it into an array of bytes using String.getBytes(String encoding). In this case I provide the encoding I want to use to convert the String into bytes.

In both cases I am taking the default encoding value from the suncertify.properties file. To make sure that the configured encoding is supported I validate the settings during the application startup using:
Charset.availableCharsets().containsKey(String myEncoding).

I hope this helps!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic