mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 23:30:55 +03:00
Cleaned up some code
This commit is contained in:
@@ -189,7 +189,7 @@ public abstract class AbstractChannel
|
||||
|
||||
default:
|
||||
gotUnknown(msg, buf);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,8 @@ public final class ChannelOutputStream extends OutputStream implements ErrorNoti
|
||||
}
|
||||
|
||||
boolean flush(int bufferSize, boolean canAwaitExpansion) throws TransportException, ConnectionException {
|
||||
while (bufferSize > 0) {
|
||||
int dataLeft = bufferSize;
|
||||
while (dataLeft > 0) {
|
||||
long remoteWindowSize = win.getSize();
|
||||
if (remoteWindowSize == 0) {
|
||||
if (canAwaitExpansion) {
|
||||
@@ -85,7 +86,7 @@ public final class ChannelOutputStream extends OutputStream implements ErrorNoti
|
||||
// a) how much data we have
|
||||
// b) the max packet size
|
||||
// c) what the current window size will allow
|
||||
final int writeNow = Math.min(bufferSize, (int) Math.min(win.getMaxPacketSize(), remoteWindowSize));
|
||||
final int writeNow = Math.min(dataLeft, (int) Math.min(win.getMaxPacketSize(), remoteWindowSize));
|
||||
|
||||
packet.wpos(headerOffset);
|
||||
packet.putMessageID(Message.CHANNEL_DATA);
|
||||
@@ -93,7 +94,7 @@ public final class ChannelOutputStream extends OutputStream implements ErrorNoti
|
||||
packet.putUInt32(writeNow);
|
||||
packet.wpos(dataOffset + writeNow);
|
||||
|
||||
final int leftOverBytes = bufferSize - writeNow;
|
||||
final int leftOverBytes = dataLeft - writeNow;
|
||||
if (leftOverBytes > 0) {
|
||||
leftOvers.putRawBytes(packet.array(), packet.wpos(), leftOverBytes);
|
||||
}
|
||||
@@ -109,7 +110,7 @@ public final class ChannelOutputStream extends OutputStream implements ErrorNoti
|
||||
leftOvers.clear();
|
||||
}
|
||||
|
||||
bufferSize = leftOverBytes;
|
||||
dataLeft = leftOverBytes;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -178,8 +179,7 @@ public final class ChannelOutputStream extends OutputStream implements ErrorNoti
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public synchronized void flush()
|
||||
throws IOException {
|
||||
public synchronized void flush() throws IOException {
|
||||
checkClose();
|
||||
buffer.flush(true);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import net.schmizz.sshj.xfer.FilePermission;
|
||||
import net.schmizz.sshj.xfer.LocalDestFile;
|
||||
import net.schmizz.sshj.xfer.LocalSourceFile;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -30,6 +30,8 @@ import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -39,6 +41,7 @@ import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class RemotePortForwarderTest {
|
||||
private static final Logger log = LoggerFactory.getLogger(RemotePortForwarderTest.class);
|
||||
|
||||
private static final PortRange RANGE = new PortRange(9000, 9999);
|
||||
private static final InetSocketAddress HTTP_SERVER_SOCKET_ADDR = new InetSocketAddress("127.0.0.1", 8080);
|
||||
@@ -125,7 +128,7 @@ public class RemotePortForwarderTest {
|
||||
private int httpGet(String server, int port) throws IOException {
|
||||
HttpClient client = HttpClientBuilder.create().build();
|
||||
String urlString = "http://" + server + ":" + port;
|
||||
System.out.println("Trying: GET " + urlString);
|
||||
log.info("Trying: GET " + urlString);
|
||||
HttpResponse execute = client.execute(new HttpGet(urlString));
|
||||
return execute.getStatusLine().getStatusCode();
|
||||
}
|
||||
|
||||
@@ -61,8 +61,7 @@ public class KeepAliveThreadTerminationTest {
|
||||
for (long l : threadMXBean.getAllThreadIds()) {
|
||||
ThreadInfo threadInfo = threadMXBean.getThreadInfo(l);
|
||||
if (threadInfo.getThreadName().equals("keep-alive") && threadInfo.getThreadState() != Thread.State.TERMINATED) {
|
||||
System.err.println("Found thread in state " + threadInfo.getThreadState());
|
||||
throw new RuntimeException("Found alive keep-alive thread");
|
||||
fail("Found alive keep-alive thread in state " + threadInfo.getThreadState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user