• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The character encoding is 8 bit US ASCII

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
reply
    Bookmark Topic Watch Topic
  • New Topic