This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes 175: warning: BASE64Encoder is internal proprietary API and m ay be removed in a future release Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "175: warning: BASE64Encoder is internal proprietary API and m ay be removed in a future release" Watch "175: warning: BASE64Encoder is internal proprietary API and m ay be removed in a future release" New topic
Author

175: warning: BASE64Encoder is internal proprietary API and m ay be removed in a future release

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
Hello,

I am getting this warning:


I have downloaded base64coder.jar and placed into tomcat/lib, jdk/jre/lib/ext but still getting this warning. How can I fix it?

Best regards
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13872
    
  10

Where did you download that JAR file from?

Ofcourse downloading the JAR and putting it in your classpath is not enough. You'll also need to change your program to make use of the Base64 codec that's in the JAR file, instead of using class sun.misc.BASE64Encoder.

You get the error because sun.misc.BASE64Encoder is an internal API of the JDK. It's not part of the official public Java API, so you are not supposed to be using it. There's no guarantee that in a future Java update this class will still exist, and in other Java implementations (for example IBM's JVM) this class doesn't exist.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
You're probably better off using the base64 classes of the Apache Commons Codec library.


Ping & DNS - updated with new look and Ping home screen widget
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
I am using it as but still throwing the same exception. What else I do?

Thanks for your reply
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
Ulf Dittmer wrote:You're probably better off using the base64 classes of the Apache Commons Codec library.

Yes I downloaded from Apache Commons Codec Library
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Good, now you just need to change your code to use it :-)
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726


These two changes I made but still getting the same warning. What else I have to change?

regards
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Where do you think you are using the org.apache.commons.codec.binary.Base64 class?
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
I think am using it here.
String encodedString = new sun.misc.BASE64Encoder().encode(fileContent);

thanks again for your prompt replies
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Farakh khan wrote:I think am using it here.
String encodedString = new sun.misc.BASE64Encoder().encode(fileContent);

thanks again for your prompt replies


But this states that you are using the class sun.misc.BASE64Encoder. And that is an internal proprietary API and may be removed in a future release. If Sun/Oracle wants to do it.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13872
    
  10

Really? Look again. Can you not see the difference between:

sun.misc.BASE64Encoder and org.apache.commons.codec.binary.Base64
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
Ulf Dittmer wrote:Where do you think you are using the org.apache.commons.codec.binary.Base64 class?


I tied like this:


Its throwing the following error:

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
How are you defining "fileContent"? Note that the error message talks about "fileContents" - a different variable.

fileContent is byte[], and you're trying to call its "getBytes" method?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13872
    
  10

fileContent is a byte[] in your code, and in line 5 you are calling the method getBytes() on it. That is not going to work, because a byte[] doesn't have a getBytes() method.

Also, there are more reasons why this will not work. The method read() of class FileInputStream, that you are calling in line 3, does not necessarily read the entire content of the file. It might just read the first few bytes, or even nothing at all. Just calling read() the way that you are doing is not a good way to read the content of a file into a byte array.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726


Thanks for help
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19542
    
  16

You haven't modified anything?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13872
    
  10

As I already mentioned above, this is not guaranteed to work correctly:

This will not always read the entire content of the file into the byte array. The API documentation of FileInputStream.read(byte[] b) explains:
API documentation wrote:
Reads up to b.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available.

Returns: the total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached.

Note that it might not read the entire file. It might read only the first 10 bytes, for example. Note that the method returns the number of bytes read. To read an entire file into a byte array, you need to call this method in a loop until it returns -1, or until you've filled the whole array. Like this:

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19542
    
  16

Or wrap the FileInputStream into a DataInputStream and use its readFully method. That essentially does the same.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
Thanks Jasper from the bottom of my heart. Now I change the code like this:


Its still throwing the following error:
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Maybe you missed my earlier post:
fileContent is byte[], and you're trying to call its "getBytes" method?


And Jesper's:
fileContent is a byte[] in your code, and in line 5 you are calling the method getBytes() on it. That is not going to work, because a byte[] doesn't have a getBytes() method.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
Thanks all

The following piece of code solved my problem


Thanks again
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 175: warning: BASE64Encoder is internal proprietary API and m ay be removed in a future release
 
Similar Threads
CachedRowSet Warning
Propietary api class
How to Generalize the code?
While replacing char of soap response then it throws error
Where can I download a jar that has sun.misc.BASE64Decoder