• 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

Determining a multibyte sequence

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any help anybody ?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic