• 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

Writting to the DB File - totally lost

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do we write to the DB file in 8 bit US ASCII?
I was thinking of using String(byte[] bytes, String charsetName)
where charsetName was US ASCII, but US ASCII is 7 bits!!!
Can you just use RandomAccessFiles writeUTF?
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Bill,
There are 6 standard charsets in the class Charset. You cannot use US-ASCII, but why not try ISO-8859-1? UTF is different from 8 bit US ASCII becuase they use 16 bits to present one character.
Regards.
Rick
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You cannot use US-ASCII


But my instructions say "The character encoding is 8 bit US ASCII".
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill and Rick,

Bill
(...) where charsetName was US ASCII, but US ASCII is 7 bits!!!


Rick
You cannot use US-ASCII


Mmh... I think that you must use US-ASCII to fulfil the requirements. It's a 8 bits character set, with, among the 8 bits, one simply unused.
Best,
Phil.
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill,
To read in data to within the DB I am using

I imagine that you confusion is coming from :

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.


I then write the String out as:

I am not specifying the charset when writing is that right?
Chris
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
QUOTE]Mmh... I think that you must use US-ASCII to fulfil the requirements. It's a 8 bits character set, with, among the 8 bits, one simply unused.

According to javasoft.com its 7 bit, or am I missing something:
http://java.sun.com/j2ee/1.3/docs/tutorial/doc/Encodings.html
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mmh... I think that you must use US-ASCII to fulfil the requirements. It's a 8 bits character set, with, among the 8 bits, one simply unused.


According to javasoft.com its 7 bit, or am I missing something:
http://java.sun.com/j2ee/1.3/docs/tutorial/doc/Encodings.html
 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Sorry about that. The sentence should be "You cannot use US-ASCII 7 bits". You can see that

ISO-8859-1
This is the character set for Western European languages. It's an 8-bit encoding scheme in which every encoded character takes exactly 8-bits. (With the remaining character sets, on the other hand, some codes are reserved to signal the start of a multi-byte character.)


This implies ISO-8859-1 is 8 bit scheme. I suppose that should be fine with our assignment.
Rick
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again, in US-ASCII, there are 8 bits, but only 7 are realy used. Take a look at the individual bytes in your sample file. They're all in the range 0-127, except possibly for the delete flag or other non-text data. Each 8-bit byte represents a character. If you don't allow that the 8th bit is simply unused, that would mean that 7 bytes = 56 bits = 8 characters. You could try to write a routine that would decode a set of 7 bytes into 8 chars, assuming no unused bits are included - but if you try that on the sample file, you'll just get gibberish. All common character encodings are implicitly built around 8-bit bytes. When they say 7-bit, they're just ignoring the 8th bit.
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you sound very confident. you have me sold. thanks jim!!!
reply
    Bookmark Topic Watch Topic
  • New Topic