• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getBytes Deprecated Method

 
David Reck
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
 
SMK Reddy
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
 
Terry McKee
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic