aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes getBytes() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "getBytes() method" Watch "getBytes() method" New topic
Author

getBytes() method

Fred Barnes
Ranch Hand

Joined: Jun 11, 2002
Posts: 62
Hi Guys,
I replaced the depreciated methods in Data class as requested. If I replace the getBytes() in the writeRecord() method with getBytes() it corrupts the db.db file.
Has anyone found a solution to the problem or did you leave the depreciated method in?
Regards
Fred
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
Originally posted by Fred Barnes:
replace the getBytes() in the writeRecord() method with getBytes()

:roll:
I think you have to replace getBytes(), since it is required in spec.
Aruna Raghavan
Ranch Hand

Joined: May 14, 2002
Posts: 194
You can't just replace the method - you have to see what the method is doing and do some extra work to make sure to replace it properly. There are several ways to do it. You don't even have to use getBytes().


Aruna A. Raghavan<br />SCJP, SCJD, SCWCD
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
It is implied.
There could be more than one way to replace it, but I think the spec means to let you use the replacing method, since it is the recognized way.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Try do a search in the forum...
Rene


Regards, Rene Larsen
Dropbox Invite
steve nicholls
Greenhorn

Joined: Dec 10, 2002
Posts: 20
You definately have to replace all deprecated methods. In the case of getBytes this can be replaced by getBytes() or getBytes(String).
The getBytes() method uses your default CharacterSet to encode what is writeen to the binary file. Each VM has its own default CharacterSet based on the Operating System. It could be the case that your default character set does not encode the file into a writeable format that is readable later (I have read that if you use OS/390, which uses the EBCDIC character set, there are issues similar to this).
Instead try getBytes(String), where the string is the name of a character set. This forces the program to encode in the necessary character set. US-ASCII should work as the character set. If you decide to go this route, remember that since you are encoding it in US-ASCII, you should also read (decode) it in US-ASCII. This means using a method that allows an encoding parameter to replace the following:
rv[i] = new String(buffer, 0, offset, description[i].getLength());
Whatever you do, just remember to document it with your submission.
Fred Barnes
Ranch Hand

Joined: Jun 11, 2002
Posts: 62
Hi Guys,
Thank you for the reply!
However I am still having a problem.
I have replaced the following method
rv[i] = new String(buffer, 0, offset, description[i].getLength());//depreciated one
with
rv[i] = new String(buffer, offset, description[i].getLength());
and
newData[i].getBytes(0, toCopy, buffer, offset);//Depreciated method
with
newData[i].getBytes();
Reading of data works fine! But when I modify the db.db file it corrupts it.
Any advise?
Regards
Fred
Fred Barnes
Ranch Hand

Joined: Jun 11, 2002
Posts: 62
Hi Guys,
Sorry I have managed to fix my problem!
Thank you for your replies.
Regards
Fred
Jeff Mo
Greenhorn

Joined: Jan 06, 2003
Posts: 2
Test!
[ January 06, 2003: Message edited by: mo mo ]

Jeff Mo<br />SCJP2,SCWCD2,MCSD
Aruna Raghavan
Ranch Hand

Joined: May 14, 2002
Posts: 194
getBytes()worked just fine for me.
Fred Barnes
Ranch Hand

Joined: Jun 11, 2002
Posts: 62
Hi Aruna,
Did it work fine for writing to the db.db file too?
Regards
Fred
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getBytes() method
 
Similar Threads
boxes in data
Threads
How do you deprecate a class, and/or a method?
Depreciated methods
what is depreciation of methods