我不得不在一个项目中重构几个类,并且有一个关于如何解决覆盖问题的问题。
我有一个名为的类AccSysChannel
,它继承自另一个名为的类,SwitchChannel
并有一个blockUntilGetMessageLength()
用 a 表示的方法@Override
(下面的代码)。
SwitchChannel
曾经有一个方法被调用blockUntilGetMessageLength()
,我不得不转移到一个名为ActiveSocket
.
我现在的问题是我不知道如何使用现在的@Override
blockUntilGetMessageLength()
方法。由于`AccSysChannel 类中包含许多其他方法,仍然必须保持其从 l 的继承。AccSysChannel
ActiveSocket
AccSysChannel
SwitchChanne
我的问题是如何解决这个@Override
问题?希望这是有道理的。任何帮助/方向将不胜感激。谢谢你。
这是我blockUntilGetMessageLength()
的AccSysChannel
:
....
@Override
protected int blockUntilGetMessageLength() {
byte[] b = new byte[2];
byte[] other = new byte[14];
int size = -1;
String otherStr;
try {
Iterator<ActiveSocket> it = activeSockets.iterator();
while (it.hasNext()) {
ActiveSocket activeSocket = it.next();
DataInputStream dataInputStream = activeSocket.getDataInputStream();
if (dataInputStream.markSupported()) {
while (size == -1) {
dataInputStream.mark(14);
dataInputStream.readFully(other, 0, 14);
dataInputStream.reset();
otherStr = new String(other);
LOGGER.trace("Checking slice of the message: " + otherStr);
size = otherStr.indexOf("<AT");
if (size == -1){
size = otherStr.indexOf("<DSCREDIT");
}
LOGGER.trace("Found tag at index: " + size);
switch (size) {
case 0:
case 1:
// intentional fallthrough
case -1:
if (size == 0 || size == 1) {
size = -1;
}
dataInputStream.readFully(other, 0, 10);
break;
default:
// consume the bytes preceding the size bytes
dataInputStream.readFully(other, 0, size - 2);
// read the size bytes
dataInputStream.readFully(b, 0, 2);
size = (((((int) b[0]) & BYTEMASK) << BYTESHIFT) | (((int) b[1]) & BYTEMASK));
LOGGER.trace("Setting size to: " + size);
}
}
}
}
} catch (IOException ex) {
if (this.shouldTerminate) {
return 0;
} else {
Iterator<ActiveSocket> it = activeSockets.iterator();
while (it.hasNext()) {
ActiveSocket activeSocket = it.next();
Socket socket = activeSocket.getSocket();
LOGGER.warn(FormatData.formatStack(ex));
synchronized (socket) {
socket.notify();
}
}
return 0;
}
}
return size;
}