Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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?
 
What? What, what, what? What what tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic