• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

getBytes Deprecated Method

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am strugling trying to remove the deprecated method from the writeRecord method. I have decided to use the getBytes() method that uses the systems default character encoding but the byte array returned is different from the byte array returned from the deprecated method. Could someone give me a hint about what else I need to do other than just changing to the non deprecated method?
Thanks in Advance,
David
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use This
writing to the file
/*getBytes(int srcBegin, int srcEnd,byte[] dst,int dstBegin)
is deprecated method
newData[i].getBytes(0, toCopy, buffer, offset);*/

byte[] utfb =newData[i].getBytes("UTF-8");
for(int j=0;j<utfb.length;j++)>
buffer[offset+j] = utfb[j];
offset += space;
Reading from File

/* String(byte[] ascii, int hibyte, int offset, int count)
This constructor is deprecated the preferred way to do
this is via the String constructors that take
a character-encoding name
rv[i] = new String(buffer, 0, offset,
description[i].getLength());
*/
rv[i] = new String(buffer, offset,
description[i].getLength(),"UTF-8");
offset += description[i].getLength();
Regards
SMK Reddy
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did the following within the for loop:
...
byte[] tempBytes = newData[i].substring(0, toCopy).getBytes();
System.arraycopy(tempBytes, 0, buffer, offset, tempBytes.length);
offset += space;
...
I didn't use any encoding other than the system default.
For the second deprecated method I used the following:
...
for (int i = 0; i < description.length; i++) {
rv[i] = new String(buffer, offset, description[i].getLength(), ISO_ENCODING);
offset += description[i].getLength();
}
...
ISO_ENCODING is "ISO-8859-1"
I am not sure if the encoding is correct.
Any suggestions?
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic