Class Classobyteconverter Java Class Type Deprecated

I am working on a readseq DNA protein alignment project. Its "flybase" package contains Java code that has the "charToByteConverter" class, which does not compile and does not produce an outdated message. (Http://iubio.bio.indiana.edu/soft/molbio/readseq/java/). You can find the readseq source here. I need to add some additional features to this application, I don’t know how to fix this in order to get to my goal. I am a kind of new bie in java. Plz help if possible. Readseq with its gui is easily available online. It just converts an array of given characters into bytes. Here is some information about this: (docjar.com/docs/api/sun/io/CharToByteConverter.html). I do not know what to do with this. This is an abstract class that is used as:

protected byte[] getBytes(CharToByteConverter ctb) { ctb.reset(); int estLength = ctb.getMaxBytesPerChar() * count; byte[] result = new byte[estLength]; int length; try { length = ctb.convert(value, offset, offset + count, result, 0, estLength); length += ctb.flush(result, ctb.nextByteIndex(), estLength); } catch (CharConversionException e) { length = ctb.nextByteIndex(); } if (length < estLength) { // A short format was used: Trim the byte array. byte[] trimResult = new byte[length]; System.arraycopy(result, 0, trimResult, 0, length); return trimResult; } else { return result; } } 
+3
source share
3 answers

The javadoc comment says it all:

Outdated! Replaced - by java.nio.charset

Look for the replacement class / method in the java.nio.charset package.

Note that using classes in the JDK that are not part of the officially documented API is, firstly, a bad idea.

+3
source

Altough sun.io.CharToByteConverter has the @Deprecated annotation, which still exists in Java 1.7. Compile your code with the -Xlint:deprecation argument and -Xlint:deprecation warning message.

If you compile eclipse:

  • Open the project properties and find the Java Compiler β†’ Errors / Warnings tab. See Deprecated and Restricted APIs

  • find the Forbidden link (access rule) parameter and change its value from Error to Warning

  • Compile project

enter image description here

+2
source

This is an ideal case for Adapt Parameter , from the book by Michael Persa Effective work with outdated code .

Shameless self-loading: here is a short prezi that I made on it . It has a phased breakdown of what you need to do.

Essentially, you have to change the code that you have and apply the Adapter parameter to the parameter. You want to define your own interface (call it ByteSource ), do getBytes() instead of your interface ( getBytes(ByteSource ctb) ), then make an adapter that internally has a CharToByteConverter for testing. To fix a broken library, you must create one that has java.nio.charset .

+1
source

Source: https://habr.com/ru/post/1245899/


All Articles