gpt4 book ai didi

Java 类 chartobyteconverter 类型已弃用

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:22:29 24 4
gpt4 key购买 nike

我正在从事 DNA 蛋白质比对项目“readseq”。它的“flybase”包包含具有“charToByteConverter”类的 java 代码,该类无法编译并给出“type deprecated”消息。 (http://iubio.bio.indiana.edu/soft/molbio/readseq/java/)。 Here readseq source can be found我需要在此应用程序中添加更多功能,但不知道如何修复它以实现我的目标。我是 Java 的新手。如果可能请帮忙。 Readseq 及其图形用户界面很容易在网上获得。它只是将给定字符的数组转换为字节。以下是有关它的一些信息:(docjar.com/docs/api/sun/io/CharToByteConverter.html)。我不知道如何处理这个被弃用的问题。它是一个抽象类,如下所示:

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;
}
}

最佳答案

javadoc 注释说明了一切:

Deprecated! Replaced - by java.nio.charset

在 java.nio.charset 包中寻找替换类/方法。

请注意,在 JDK 中使用不属于正式记录的 API 的类首先不是一个好主意。

关于Java 类 chartobyteconverter 类型已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10444129/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com