| Author |
Determining a multibyte sequence
|
Anupam Bhatt
Ranch Hand
Joined: Mar 12, 2004
Posts: 81
|
|
Hi, I am splitting a string [which could be composed of multibyte characters] in to chunks of 4000 bytes [so that i could store it in to varchar2 column in the database]. so i do "new String(bytes, currentPos, 4000);". The issue: A multibyte character could be broken due to splitting based on bytes. Question: how can i find out that the last byte in the 4000 bytes string is a part of a multibyte sequence, so that i don't split it up and should construct a smaller string [say 3997 bytes, avoiding splitting the last 3 byte multibyte char] Thanks, Anupam
|
 |
Anupam Bhatt
Ranch Hand
Joined: Mar 12, 2004
Posts: 81
|
|
|
any help anybody ?
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12324
|
|
A multibyte character could be broken due to splitting based on bytes.
Before doing anything drastic, exactly how does this database field get used? If all the bytes are reassembled before converting back to String, the multibyte char will be restored and there is no problem. Bill
|
Java Resources at www.wbrogden.com
|
 |
Anupam Bhatt
Ranch Hand
Joined: Mar 12, 2004
Posts: 81
|
|
Originally posted by William Brogden: Before doing anything drastic, exactly how does this database field get used? If all the bytes are reassembled before converting back to String, the multibyte char will be restored and there is no problem. Bill
The issue is this field is a varchar2, so we store string splitted in to multiple rows of 4000 bytes. so what i am doing is something like : so step 2 may result in the multibyte character being splitted .
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12324
|
|
Who cares if the multibyte sequence is split? I'm serious - do you ever use just one chunk of bytes or do you always put them back together? Your point 4 says you never use just one. If you never try to turn a single isolated chunk of bytes into a String you never get any problem. Bill
|
 |
Dave Wingate
Ranch Hand
Joined: Mar 26, 2002
Posts: 262
|
|
You could also consider writing your bytes to a single BLOB column in the DB. Typically, the size of a blob column can be very large. For example, in mysql a BLOB field can be 65k+ bytes.
|
Fun programming etcetera!
|
 |
 |
|
|
subject: Determining a multibyte sequence
|
|
|