This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

getBytes Deprecated Method

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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?
 
Hot dog! An advertiser loves us THIS much:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic