Code cleanup, add { to single-line if

This commit is contained in:
Jeroen van Erp
2018-07-12 14:55:03 +02:00
parent d2a16385da
commit 5bebe044aa
3 changed files with 24 additions and 13 deletions

View File

@@ -362,10 +362,12 @@ public abstract class AbstractChannel
} catch (Buffer.BufferException be) { } catch (Buffer.BufferException be) {
throw new ConnectionException(be); throw new ConnectionException(be);
} }
if (len < 0 || len > getLocalMaxPacketSize() || len > buf.available()) if (len < 0 || len > getLocalMaxPacketSize() || len > buf.available()) {
throw new ConnectionException(DisconnectReason.PROTOCOL_ERROR, "Bad item length: " + len); throw new ConnectionException(DisconnectReason.PROTOCOL_ERROR, "Bad item length: " + len);
if (log.isTraceEnabled()) }
if (log.isTraceEnabled()) {
log.trace("IN #{}: {}", id, ByteArrayUtils.printHex(buf.array(), buf.rpos(), len)); log.trace("IN #{}: {}", id, ByteArrayUtils.printHex(buf.array(), buf.rpos(), len));
}
stream.receive(buf.array(), buf.rpos(), len); stream.receive(buf.array(), buf.rpos(), len);
} }

View File

@@ -92,36 +92,43 @@ public final class ChannelInputStream
throws IOException { throws IOException {
synchronized (buf) { synchronized (buf) {
for (; ; ) { for (; ; ) {
if (buf.available() > 0) if (buf.available() > 0) {
break; break;
if (eof) }
if (error != null) if (eof) {
if (error != null) {
throw error; throw error;
else } else {
return -1; return -1;
}
}
try { try {
buf.wait(); buf.wait();
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw (IOException) new InterruptedIOException().initCause(e); throw (IOException) new InterruptedIOException().initCause(e);
} }
} }
if (len > buf.available()) if (len > buf.available()) {
len = buf.available(); len = buf.available();
}
buf.readRawBytes(b, off, len); buf.readRawBytes(b, off, len);
if (buf.rpos() > win.getMaxPacketSize() && buf.available() == 0) if (buf.rpos() > win.getMaxPacketSize() && buf.available() == 0) {
buf.clear(); buf.clear();
}
} }
if (!chan.getAutoExpand()) if (!chan.getAutoExpand()) {
checkWindow(); checkWindow();
}
return len; return len;
} }
public void receive(byte[] data, int offset, int len) public void receive(byte[] data, int offset, int len)
throws ConnectionException, TransportException { throws ConnectionException, TransportException {
if (eof) if (eof) {
throw new ConnectionException("Getting data on EOF'ed stream"); throw new ConnectionException("Getting data on EOF'ed stream");
}
synchronized (buf) { synchronized (buf) {
buf.putRawBytes(data, offset, len); buf.putRawBytes(data, offset, len);
buf.notifyAll(); buf.notifyAll();
@@ -132,8 +139,9 @@ public final class ChannelInputStream
synchronized (win) { synchronized (win) {
win.consume(len); win.consume(len);
} }
if (chan.getAutoExpand()) if (chan.getAutoExpand()) {
checkWindow(); checkWindow();
}
} }
private void checkWindow() private void checkWindow()
@@ -143,7 +151,7 @@ public final class ChannelInputStream
if (adjustment > 0) { if (adjustment > 0) {
log.debug("Sending SSH_MSG_CHANNEL_WINDOW_ADJUST to #{} for {} bytes", chan.getRecipient(), adjustment); log.debug("Sending SSH_MSG_CHANNEL_WINDOW_ADJUST to #{} for {} bytes", chan.getRecipient(), adjustment);
trans.write(new SSHPacket(Message.CHANNEL_WINDOW_ADJUST) trans.write(new SSHPacket(Message.CHANNEL_WINDOW_ADJUST)
.putUInt32(chan.getRecipient()).putUInt32(adjustment)); .putUInt32(chan.getRecipient()).putUInt32(adjustment));
win.expand(adjustment); win.expand(adjustment);
} }
} }

View File

@@ -59,8 +59,9 @@ public abstract class Window {
synchronized (lock) { synchronized (lock) {
size -= dec; size -= dec;
log.debug("Consuming by {} down to {}", dec, size); log.debug("Consuming by {} down to {}", dec, size);
if (size < 0) if (size < 0) {
throw new ConnectionException("Window consumed to below 0"); throw new ConnectionException("Window consumed to below 0");
}
} }
} }