プロジェクト内のいくつかのクラスをリファクタリングする必要があり、オーバーライドの問題を修正する方法について質問があります。
私は、呼び出さAccSysChannel
れた別のクラスから継承し、 (以下のコード) で示されるSwitchChannel
メソッドを呼び出したクラスを持っています。blockUntilGetMessageLength()
@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;
}