• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Determining a multibyte sequence

 
Anupam Bhatt
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any help anybody ?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anupam Bhatt
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic