You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2016/08/04 17:06:33 UTC
[1/3] mina-sshd git commit: [SSHD-674] Converted some more code to
Java 8
Repository: mina-sshd
Updated Branches:
refs/heads/master 5a133292b -> 997ae449f
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java
index b9a26be..23548f1 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java
@@ -26,11 +26,11 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Predicate;
import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.PropertyResolver;
import org.apache.sshd.common.PropertyResolverUtils;
-import org.apache.sshd.common.util.Predicate;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.logging.AbstractLoggingBean;
@@ -50,7 +50,7 @@ public class Window extends AbstractLoggingBean implements java.nio.channels.Cha
public static final Predicate<Window> SPACE_AVAILABLE_PREDICATE = new Predicate<Window>() {
@SuppressWarnings("synthetic-access")
@Override
- public boolean evaluate(Window input) {
+ public boolean test(Window input) {
// NOTE: we do not call "getSize()" on purpose in order to avoid the lock
return input.sizeHolder.get() > 0;
}
@@ -233,7 +233,7 @@ public class Window extends AbstractLoggingBean implements java.nio.channels.Cha
waitForCondition(new Predicate<Window>() {
@SuppressWarnings("synthetic-access")
@Override
- public boolean evaluate(Window input) {
+ public boolean test(Window input) {
// NOTE: we do not call "getSize()" on purpose in order to avoid the lock
return input.sizeHolder.get() >= len;
}
@@ -291,7 +291,7 @@ public class Window extends AbstractLoggingBean implements java.nio.channels.Cha
long remWaitNanos = maxWaitNanos;
// The loop takes care of spurious wakeups
while (isOpen() && (remWaitNanos > 0L)) {
- if (predicate.evaluate(this)) {
+ if (predicate.test(this)) {
return;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/cipher/BaseCipher.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/BaseCipher.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/BaseCipher.java
index 546685e..baaf3fc 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/BaseCipher.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/cipher/BaseCipher.java
@@ -22,7 +22,6 @@ import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.util.NumberUtils;
import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.common.util.ValidateUtils;
@@ -83,11 +82,6 @@ public class BaseCipher implements Cipher {
}
@Override
- public void update(byte[] input) throws Exception {
- update(input, 0, NumberUtils.length(input));
- }
-
- @Override
public void update(byte[] input, int inputOffset, int inputLen) throws Exception {
cipher.update(input, inputOffset, inputLen, input, inputOffset);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/cipher/BuiltinCiphers.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/BuiltinCiphers.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/BuiltinCiphers.java
index 9300b59..4038440 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/BuiltinCiphers.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/cipher/BuiltinCiphers.java
@@ -177,7 +177,6 @@ public enum BuiltinCiphers implements CipherFactory {
* according to the factory name (case <U>insensitive</U>)
*/
public static SortedSet<CipherFactory> getRegisteredExtensions() {
- // TODO for JDK-8 return Collections.emptySortedSet()
synchronized (EXTENSIONS) {
return GenericUtils.asSortedSet(NamedResource.BY_NAME_COMPARATOR, EXTENSIONS.values());
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/cipher/Cipher.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/Cipher.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/Cipher.java
index dd9cfdf..6f35973 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/Cipher.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/cipher/Cipher.java
@@ -18,6 +18,7 @@
*/
package org.apache.sshd.common.cipher;
+import org.apache.sshd.common.util.NumberUtils;
import org.apache.sshd.common.util.ValidateUtils;
/**
@@ -50,7 +51,9 @@ public interface Cipher extends CipherInformation {
* @throws Exception If failed to execute
* @see #update(byte[], int, int)
*/
- void update(byte[] input) throws Exception; // TODO make this a default method in JDK-8
+ default void update(byte[] input) throws Exception {
+ update(input, 0, NumberUtils.length(input));
+ }
/**
* Performs in-place encryption or decryption on the given data.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherNone.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherNone.java b/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherNone.java
index 616e305..15b6e9f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherNone.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/cipher/CipherNone.java
@@ -18,9 +18,6 @@
*/
package org.apache.sshd.common.cipher;
-import org.apache.sshd.common.util.NumberUtils;
-
-
/**
* Represents a no-op cipher.
* This cipher can not really be used during authentication and should only
@@ -60,11 +57,6 @@ public class CipherNone implements Cipher {
}
@Override
- public void update(byte[] input) throws Exception {
- update(input, 0, NumberUtils.length(input));
- }
-
- @Override
public void update(byte[] input, int inputOffset, int inputLen) throws Exception {
// ignored - always succeeds
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/compression/BuiltinCompressions.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/compression/BuiltinCompressions.java b/sshd-core/src/main/java/org/apache/sshd/common/compression/BuiltinCompressions.java
index 43213d8..e27e4a6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/compression/BuiltinCompressions.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/compression/BuiltinCompressions.java
@@ -129,7 +129,6 @@ public enum BuiltinCompressions implements CompressionFactory {
* according to the factory name (case <U>insensitive</U>)
*/
public static SortedSet<CompressionFactory> getRegisteredExtensions() {
- // TODO for JDK-8 return Collections.emptySortedSet()
synchronized (EXTENSIONS) {
return GenericUtils.asSortedSet(NamedResource.BY_NAME_COMPARATOR, EXTENSIONS.values());
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java b/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java
index 0f1f809..91ac27e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/compression/Compression.java
@@ -68,5 +68,4 @@ public interface Compression extends CompressionInformation {
* @throws IOException if an error occurs
*/
void uncompress(Buffer from, Buffer to) throws IOException;
-
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/file/FileSystemAware.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/file/FileSystemAware.java b/sshd-core/src/main/java/org/apache/sshd/common/file/FileSystemAware.java
index dc27fa1..e73c37d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/file/FileSystemAware.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/file/FileSystemAware.java
@@ -24,6 +24,7 @@ import java.nio.file.FileSystem;
* Interface that can be implemented by a command to be able to access the
* file system in which this command will be used.
*/
+@FunctionalInterface
public interface FileSystemAware {
/**
* Set the file system in which this shell will be executed.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/file/FileSystemFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/file/FileSystemFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/file/FileSystemFactory.java
index 76cc472..509e481 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/file/FileSystemFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/file/FileSystemFactory.java
@@ -29,6 +29,7 @@ import org.apache.sshd.common.session.Session;
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
+@FunctionalInterface
public interface FileSystemFactory {
/**
@@ -39,5 +40,4 @@ public interface FileSystemFactory {
* @throws IOException if the filesystem can not be created
*/
FileSystem createFileSystem(Session session) throws IOException;
-
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipForwarderFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipForwarderFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipForwarderFactory.java
index 70cd098..e001ab2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipForwarderFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipForwarderFactory.java
@@ -24,6 +24,7 @@ import org.apache.sshd.common.session.ConnectionService;
* A factory for creating forwarder objects for client port forwarding
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface TcpipForwarderFactory {
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/future/AbstractSshFuture.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/future/AbstractSshFuture.java b/sshd-core/src/main/java/org/apache/sshd/common/future/AbstractSshFuture.java
index 610b305..f10f0f5 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/future/AbstractSshFuture.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/future/AbstractSshFuture.java
@@ -22,7 +22,6 @@ package org.apache.sshd.common.future;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.StreamCorruptedException;
-import java.util.concurrent.TimeUnit;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.util.GenericUtils;
@@ -42,39 +41,18 @@ public abstract class AbstractSshFuture<T extends SshFuture> extends AbstractLog
super();
}
- @Override // TODO make this a default method in JDK-8
- public boolean await() throws IOException {
- return await(Long.MAX_VALUE);
- }
-
- @Override // TODO make this a default method in JDK-8
- public boolean await(long timeout, TimeUnit unit) throws IOException {
- return await(unit.toMillis(timeout));
- }
-
@Override
public boolean await(long timeoutMillis) throws IOException {
return await0(timeoutMillis, true) != null;
}
- @Override // TODO make this a default method in JDK-8
- public boolean awaitUninterruptibly() {
- return awaitUninterruptibly(Long.MAX_VALUE);
- }
-
- @Override // TODO make this a default method in JDK-8
- public boolean awaitUninterruptibly(long timeout, TimeUnit unit) {
- return awaitUninterruptibly(unit.toMillis(timeout));
- }
-
@Override
public boolean awaitUninterruptibly(long timeoutMillis) {
try {
return await0(timeoutMillis, false) != null;
} catch (InterruptedIOException e) {
- // TODO for JDK-8 use the 2-args constructors
- throw (InternalError) new InternalError("Unexpected interrupted exception wile awaitUninterruptibly "
- + timeoutMillis + " msec.: " + e.getMessage()).initCause(e);
+ throw new InternalError("Unexpected interrupted exception wile awaitUninterruptibly "
+ + timeoutMillis + " msec.: " + e.getMessage(), e);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultCloseFuture.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultCloseFuture.java b/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultCloseFuture.java
index c71bb57..3de2d01 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultCloseFuture.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultCloseFuture.java
@@ -35,7 +35,7 @@ public class DefaultCloseFuture extends DefaultSshFuture<CloseFuture> implements
super(lock);
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public boolean isClosed() {
if (isDone()) {
return (Boolean) getValue();
@@ -44,7 +44,7 @@ public class DefaultCloseFuture extends DefaultSshFuture<CloseFuture> implements
}
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public void setClosed() {
setValue(Boolean.TRUE);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultKeyExchangeFuture.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultKeyExchangeFuture.java b/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultKeyExchangeFuture.java
index 9aceaa5..548a0ae 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultKeyExchangeFuture.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultKeyExchangeFuture.java
@@ -31,7 +31,7 @@ public class DefaultKeyExchangeFuture extends DefaultVerifiableSshFuture<KeyExch
super(lock);
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public KeyExchangeFuture verify(long timeoutMillis) throws IOException {
Boolean result = verifyResult(Boolean.class, timeoutMillis);
if (!result.booleanValue()) {
@@ -41,7 +41,7 @@ public class DefaultKeyExchangeFuture extends DefaultVerifiableSshFuture<KeyExch
return this;
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public Throwable getException() {
Object v = getValue();
if (v instanceof Throwable) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultVerifiableSshFuture.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultVerifiableSshFuture.java b/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultVerifiableSshFuture.java
index c073d0f..61c8761 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultVerifiableSshFuture.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultVerifiableSshFuture.java
@@ -19,9 +19,6 @@
package org.apache.sshd.common.future;
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
-
/**
* @param <T> Type of future
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
@@ -30,14 +27,4 @@ public abstract class DefaultVerifiableSshFuture<T extends SshFuture> extends De
protected DefaultVerifiableSshFuture(Object lock) {
super(lock);
}
-
- @Override // TODO for JDK-8 make this a default method
- public T verify() throws IOException {
- return verify(Long.MAX_VALUE);
- }
-
- @Override // TODO for JDK-8 make this a default method
- public T verify(long timeout, TimeUnit unit) throws IOException {
- return verify(unit.toMillis(timeout));
- }
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/future/SshFutureListener.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/future/SshFutureListener.java b/sshd-core/src/main/java/org/apache/sshd/common/future/SshFutureListener.java
index c17f551..2fadaf7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/future/SshFutureListener.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/future/SshFutureListener.java
@@ -28,6 +28,7 @@ import java.util.EventListener;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
@SuppressWarnings("rawtypes")
+@FunctionalInterface
public interface SshFutureListener<T extends SshFuture> extends EventListener {
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/future/VerifiableFuture.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/future/VerifiableFuture.java b/sshd-core/src/main/java/org/apache/sshd/common/future/VerifiableFuture.java
index fc23cb7..e318de7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/future/VerifiableFuture.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/future/VerifiableFuture.java
@@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit;
* @param <T> Type of verification result
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface VerifiableFuture<T> {
/**
* Wait {@link Long#MAX_VALUE} msec. and verify that the operation was successful
@@ -39,7 +40,9 @@ public interface VerifiableFuture<T> {
* @throws IOException If failed to verify successfully on time
* @see #verify(long)
*/
- T verify() throws IOException;
+ default T verify() throws IOException {
+ return verify(Long.MAX_VALUE);
+ }
/**
* Wait and verify that the operation was successful
@@ -50,7 +53,9 @@ public interface VerifiableFuture<T> {
* @throws IOException If failed to verify successfully on time
* @see #verify(long)
*/
- T verify(long timeout, TimeUnit unit) throws IOException;
+ default T verify(long timeout, TimeUnit unit) throws IOException {
+ return verify(unit.toMillis(timeout));
+ }
/**
* Wait and verify that the operation was successful
@@ -60,5 +65,4 @@ public interface VerifiableFuture<T> {
* @throws IOException If failed to verify successfully on time
*/
T verify(long timeoutMillis) throws IOException;
-
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/future/WaitableFuture.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/future/WaitableFuture.java b/sshd-core/src/main/java/org/apache/sshd/common/future/WaitableFuture.java
index ae0f735..ba84820 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/future/WaitableFuture.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/future/WaitableFuture.java
@@ -43,7 +43,9 @@ public interface WaitableFuture {
* if waiting was interrupted
* @see #await(long)
*/
- boolean await() throws IOException;
+ default boolean await() throws IOException {
+ return await(Long.MAX_VALUE);
+ }
/**
* Wait for the asynchronous operation to complete with the specified timeout.
@@ -55,7 +57,9 @@ public interface WaitableFuture {
* if waiting was interrupted
* @see #await(long)
*/
- boolean await(long timeout, TimeUnit unit) throws IOException;
+ default boolean await(long timeout, TimeUnit unit) throws IOException {
+ return await(unit.toMillis(timeout));
+ }
/**
* Wait for the asynchronous operation to complete with the specified timeout.
@@ -75,7 +79,9 @@ public interface WaitableFuture {
* @return {@code true} if the operation is completed.
* @see #awaitUninterruptibly(long)
*/
- boolean awaitUninterruptibly();
+ default boolean awaitUninterruptibly() {
+ return awaitUninterruptibly(Long.MAX_VALUE);
+ }
/**
* Wait for the asynchronous operation to complete with the specified timeout
@@ -86,7 +92,9 @@ public interface WaitableFuture {
* @return {@code true} if the operation is completed.
* @see #awaitUninterruptibly(long)
*/
- boolean awaitUninterruptibly(long timeout, TimeUnit unit);
+ default boolean awaitUninterruptibly(long timeout, TimeUnit unit) {
+ return awaitUninterruptibly(unit.toMillis(timeout));
+ }
/**
* Wait for the asynchronous operation to complete with the specified timeout
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/io/AbstractIoWriteFuture.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/AbstractIoWriteFuture.java b/sshd-core/src/main/java/org/apache/sshd/common/io/AbstractIoWriteFuture.java
index 6b3e905..755d5a5 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/AbstractIoWriteFuture.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/AbstractIoWriteFuture.java
@@ -20,6 +20,7 @@
package org.apache.sshd.common.io;
import java.io.IOException;
+
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.future.DefaultVerifiableSshFuture;
@@ -31,7 +32,7 @@ public abstract class AbstractIoWriteFuture extends DefaultVerifiableSshFuture<I
super(lock);
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public IoWriteFuture verify(long timeout) throws IOException {
Boolean result = verifyResult(Boolean.class, timeout);
if (!result) {
@@ -41,13 +42,13 @@ public abstract class AbstractIoWriteFuture extends DefaultVerifiableSshFuture<I
return this;
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public boolean isWritten() {
Object value = getValue();
return (value instanceof Boolean) && (Boolean) value;
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public Throwable getException() {
Object v = getValue();
if (v instanceof Throwable) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/kex/BuiltinDHFactories.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/kex/BuiltinDHFactories.java b/sshd-core/src/main/java/org/apache/sshd/common/kex/BuiltinDHFactories.java
index 65af0b0..b2c2f72 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/kex/BuiltinDHFactories.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/kex/BuiltinDHFactories.java
@@ -160,7 +160,7 @@ public enum BuiltinDHFactories implements DHFactory {
Collections.unmodifiableSet(EnumSet.allOf(BuiltinDHFactories.class));
private static final Map<String, DHFactory> EXTENSIONS =
- new TreeMap<String, DHFactory>(String.CASE_INSENSITIVE_ORDER);
+ new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private final String factoryName;
@@ -207,7 +207,6 @@ public enum BuiltinDHFactories implements DHFactory {
* according to the factory name (case <U>insensitive</U>)
*/
public static SortedSet<DHFactory> getRegisteredExtensions() {
- // TODO for JDK-8 return Collections.emptySortedSet()
synchronized (EXTENSIONS) {
return GenericUtils.asSortedSet(NamedResource.BY_NAME_COMPARATOR, EXTENSIONS.values());
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/KeyIdentityProvider.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/KeyIdentityProvider.java b/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/KeyIdentityProvider.java
index 4656190..4f331aa 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/KeyIdentityProvider.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/KeyIdentityProvider.java
@@ -25,10 +25,10 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
+import java.util.function.Supplier;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Supplier;
import org.apache.sshd.common.util.Transformer;
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/mac/BaseMac.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/mac/BaseMac.java b/sshd-core/src/main/java/org/apache/sshd/common/mac/BaseMac.java
index 72adddd..3210cf6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/mac/BaseMac.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/mac/BaseMac.java
@@ -20,7 +20,6 @@ package org.apache.sshd.common.mac;
import javax.crypto.spec.SecretKeySpec;
-import org.apache.sshd.common.util.NumberUtils;
import org.apache.sshd.common.util.SecurityUtils;
/**
@@ -81,29 +80,11 @@ public class BaseMac implements Mac {
update(tmp, 0, 4);
}
- @Override // TODO make this a default method in Java 8
- public void update(byte buf[]) {
- update(buf, 0, NumberUtils.length(buf));
- }
-
@Override
public void update(byte buf[], int offset, int len) {
mac.update(buf, offset, len);
}
- @Override // TODO make this a default method in Java 8
- public byte[] doFinal() throws Exception {
- int blockSize = getBlockSize();
- byte[] buf = new byte[blockSize];
- doFinal(buf);
- return buf;
- }
-
- @Override // TODO make this a default method in Java 8
- public void doFinal(byte[] buf) throws Exception {
- doFinal(buf, 0);
- }
-
@Override
public void doFinal(byte[] buf, int offset) throws Exception {
int blockSize = getBlockSize();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/mac/BuiltinMacs.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/mac/BuiltinMacs.java b/sshd-core/src/main/java/org/apache/sshd/common/mac/BuiltinMacs.java
index eac8855..35614d3 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/mac/BuiltinMacs.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/mac/BuiltinMacs.java
@@ -126,7 +126,6 @@ public enum BuiltinMacs implements MacFactory {
* according to the factory name (case <U>insensitive</U>)
*/
public static SortedSet<MacFactory> getRegisteredExtensions() {
- // TODO for JDK-8 return Collections.emptySortedSet()
synchronized (EXTENSIONS) {
return GenericUtils.asSortedSet(NamedResource.BY_NAME_COMPARATOR, EXTENSIONS.values());
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/mac/Mac.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/mac/Mac.java b/sshd-core/src/main/java/org/apache/sshd/common/mac/Mac.java
index b69ad34..4b80447 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/mac/Mac.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/mac/Mac.java
@@ -18,6 +18,8 @@
*/
package org.apache.sshd.common.mac;
+import org.apache.sshd.common.util.NumberUtils;
+
/**
* Message Authentication Code for use in SSH.
* It usually wraps a javax.crypto.Mac class.
@@ -27,15 +29,24 @@ package org.apache.sshd.common.mac;
public interface Mac extends MacInformation {
void init(byte[] key) throws Exception;
- void update(byte[] buf);
+ default void update(byte[] buf) {
+ update(buf, 0, NumberUtils.length(buf));
+ }
void update(byte[] buf, int start, int len);
void updateUInt(long foo);
- byte[] doFinal() throws Exception;
+ default byte[] doFinal() throws Exception {
+ int blockSize = getBlockSize();
+ byte[] buf = new byte[blockSize];
+ doFinal(buf);
+ return buf;
+ }
- void doFinal(byte[] buf) throws Exception;
+ default void doFinal(byte[] buf) throws Exception {
+ doFinal(buf, 0);
+ }
void doFinal(byte[] buf, int offset) throws Exception;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/random/AbstractRandom.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/random/AbstractRandom.java b/sshd-core/src/main/java/org/apache/sshd/common/random/AbstractRandom.java
index 8bb8df7..2a1f825 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/random/AbstractRandom.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/random/AbstractRandom.java
@@ -27,11 +27,6 @@ public abstract class AbstractRandom implements Random {
super();
}
- @Override // TODO in JDK-8 make this a default method
- public void fill(byte[] bytes) {
- fill(bytes, 0, bytes.length);
- }
-
@Override
public String toString() {
return getName();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/random/Random.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/random/Random.java b/sshd-core/src/main/java/org/apache/sshd/common/random/Random.java
index 555a659..6e597ef 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/random/Random.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/random/Random.java
@@ -32,7 +32,9 @@ public interface Random extends NamedResource {
* @param bytes The bytes to fill
* @see #fill(byte[], int, int)
*/
- void fill(byte[] bytes); // TODO in JDK-8 make this a default method
+ default void fill(byte[] bytes) {
+ fill(bytes, 0, bytes.length);
+ }
/**
* Fill part of bytes with random values.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/session/SessionHolder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/SessionHolder.java b/sshd-core/src/main/java/org/apache/sshd/common/session/SessionHolder.java
index 1f7a204..280bbf0 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/SessionHolder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/SessionHolder.java
@@ -23,6 +23,7 @@ package org.apache.sshd.common.session;
* @param <S> Type of {@link Session} being held
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface SessionHolder<S extends Session> {
S getSession();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/signature/AbstractSignature.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/signature/AbstractSignature.java b/sshd-core/src/main/java/org/apache/sshd/common/signature/AbstractSignature.java
index a22b97b..e9a25c7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/signature/AbstractSignature.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/signature/AbstractSignature.java
@@ -106,33 +106,33 @@ public abstract class AbstractSignature implements Signature {
protected Pair<String, byte[]> extractEncodedSignature(byte[] sig) {
final int dataLen = NumberUtils.length(sig);
// if it is encoded then we must have at least 2 UINT32 values
- if (dataLen < (2 * (Integer.SIZE / Byte.SIZE))) {
+ if (dataLen < (2 * Integer.BYTES)) {
return null;
}
long keyTypeLen = BufferUtils.getUInt(sig, 0, dataLen);
// after the key type we MUST have data bytes
- if (keyTypeLen >= (dataLen - (Integer.SIZE / Byte.SIZE))) {
+ if (keyTypeLen >= (dataLen - Integer.BYTES)) {
return null;
}
- int keyTypeStartPos = Integer.SIZE / Byte.SIZE;
+ int keyTypeStartPos = Integer.BYTES;
int keyTypeEndPos = keyTypeStartPos + (int) keyTypeLen;
int remainLen = dataLen - keyTypeEndPos;
// must have UINT32 with the data bytes length
- if (remainLen < (Integer.SIZE / Byte.SIZE)) {
+ if (remainLen < Integer.BYTES) {
return null;
}
long dataBytesLen = BufferUtils.getUInt(sig, keyTypeEndPos, remainLen);
// make sure reported number of bytes does not exceed available
- if (dataBytesLen > (remainLen - (Integer.SIZE / Byte.SIZE))) {
+ if (dataBytesLen > (remainLen - Integer.BYTES)) {
return null;
}
String keyType = new String(sig, keyTypeStartPos, (int) keyTypeLen, StandardCharsets.UTF_8);
byte[] data = new byte[(int) dataBytesLen];
- System.arraycopy(sig, keyTypeEndPos + (Integer.SIZE / Byte.SIZE), data, 0, (int) dataBytesLen);
+ System.arraycopy(sig, keyTypeEndPos + Integer.BYTES, data, 0, (int) dataBytesLen);
return new Pair<>(keyType, data);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/signature/BuiltinSignatures.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/signature/BuiltinSignatures.java b/sshd-core/src/main/java/org/apache/sshd/common/signature/BuiltinSignatures.java
index 922e4ae..50beb8e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/signature/BuiltinSignatures.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/signature/BuiltinSignatures.java
@@ -154,7 +154,6 @@ public enum BuiltinSignatures implements SignatureFactory {
* according to the factory name (case <U>insensitive</U>)
*/
public static SortedSet<SignatureFactory> getRegisteredExtensions() {
- // TODO for JDK-8 return Collections.emptySortedSet()
synchronized (EXTENSIONS) {
return GenericUtils.asSortedSet(NamedResource.BY_NAME_COMPARATOR, EXTENSIONS.values());
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpConstants.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpConstants.java b/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpConstants.java
index 47042ef..ce64bfb 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpConstants.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpConstants.java
@@ -20,9 +20,9 @@ package org.apache.sshd.common.subsystem.sftp;
import java.lang.reflect.Field;
import java.util.Map;
+import java.util.function.Predicate;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Predicate;
import org.apache.sshd.common.util.logging.LoggingUtils;
/**
@@ -280,7 +280,7 @@ public final class SftpConstants {
private static final Map<Integer, String> NAMES_MAP =
LoggingUtils.generateMnemonicMap(SftpConstants.class, new Predicate<Field>() {
@Override
- public boolean evaluate(Field f) {
+ public boolean test(Field f) {
String name = f.getName();
return name.startsWith("SSH_FXP_")
// exclude the rename modes which are not opcodes
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/extensions/AbstractParser.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/extensions/AbstractParser.java b/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/extensions/AbstractParser.java
index e4e1c9d..15cb3fe 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/extensions/AbstractParser.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/extensions/AbstractParser.java
@@ -19,7 +19,6 @@
package org.apache.sshd.common.subsystem.sftp.extensions;
-import org.apache.sshd.common.util.NumberUtils;
import org.apache.sshd.common.util.ValidateUtils;
/**
@@ -37,14 +36,4 @@ public abstract class AbstractParser<T> implements ExtensionParser<T> {
public final String getName() {
return name;
}
-
- @Override // TODO in JDK-8 make this a default method
- public T transform(byte[] input) {
- return parse(input);
- }
-
- @Override // TODO in JDK-8 make this a default method
- public T parse(byte[] input) {
- return parse(input, 0, NumberUtils.length(input));
- }
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/extensions/ExtensionParser.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/extensions/ExtensionParser.java b/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/extensions/ExtensionParser.java
index cb3a3cb..df22517 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/extensions/ExtensionParser.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/extensions/ExtensionParser.java
@@ -20,6 +20,7 @@
package org.apache.sshd.common.subsystem.sftp.extensions;
import org.apache.sshd.common.NamedResource;
+import org.apache.sshd.common.util.NumberUtils;
import org.apache.sshd.common.util.Transformer;
/**
@@ -27,7 +28,14 @@ import org.apache.sshd.common.util.Transformer;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public interface ExtensionParser<T> extends NamedResource, Transformer<byte[], T> {
- T parse(byte[] input);
+ default T parse(byte[] input) {
+ return parse(input, 0, NumberUtils.length(input));
+ }
T parse(byte[] input, int offset, int len);
+
+ @Override
+ default T transform(byte[] input) {
+ return parse(input);
+ }
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
index 3b23895..5516e44 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/GenericUtils.java
@@ -38,6 +38,8 @@ import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
import javax.management.MBeanException;
import javax.management.ReflectionException;
@@ -76,16 +78,6 @@ public final class GenericUtils {
public static final String QUOTES = "\"'";
@SuppressWarnings("rawtypes")
- private static final Comparator<Comparable> NATURAL_ORDER_COMPARATOR = new Comparator<Comparable>() {
- // TODO for JDK-8 use Comparator.naturalOrder()
- @Override
- @SuppressWarnings("unchecked")
- public int compare(Comparable c1, Comparable c2) {
- return c1.compareTo(c2);
- }
- };
-
- @SuppressWarnings("rawtypes")
private static final Factory CASE_INSENSITIVE_MAP_FACTORY = new Factory() {
@Override
@SuppressWarnings("unchecked")
@@ -306,15 +298,8 @@ public final class GenericUtils {
}
}
- @SuppressWarnings({"unchecked", "rawtypes"})
- public static <V extends Comparable<V>> Comparator<V> naturalComparator() {
- // TODO for JDK-8 use Comparator.naturalOrder()
- return (Comparator) NATURAL_ORDER_COMPARATOR;
- }
-
public static <V extends Comparable<V>> SortedSet<V> asSortedSet(Collection<? extends V> values) {
- // TODO for JDK-8 use Comparator.naturalOrder()
- return asSortedSet(GenericUtils.<V>naturalComparator(), values);
+ return asSortedSet(Comparator.<V>naturalOrder(), values);
}
/**
@@ -337,8 +322,7 @@ public final class GenericUtils {
* using the provided comparator
*/
public static <V> SortedSet<V> asSortedSet(Comparator<? super V> comp, Collection<? extends V> values) {
- // TODO for JDK-8 return Collections.emptySortedSet()
- SortedSet<V> set = new TreeSet<V>(ValidateUtils.checkNotNull(comp, "No comparator"));
+ SortedSet<V> set = new TreeSet<>(Objects.requireNonNull(comp, "No comparator"));
if (size(values) > 0) {
set.addAll(values);
}
@@ -431,9 +415,9 @@ public final class GenericUtils {
return Collections.emptyList();
}
- List<T> matches = new ArrayList<T>(values.size());
+ List<T> matches = new ArrayList<>(values.size());
for (T v : values) {
- if (acceptor.evaluate(v)) {
+ if (acceptor.test(v)) {
matches.add(v);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/Int2IntFunction.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/Int2IntFunction.java b/sshd-core/src/main/java/org/apache/sshd/common/util/Int2IntFunction.java
index 90bab63..cedb963 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/Int2IntFunction.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/Int2IntFunction.java
@@ -22,6 +22,7 @@ package org.apache.sshd.common.util;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface Int2IntFunction {
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/NumberUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/NumberUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/NumberUtils.java
index b859386..e988f8a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/NumberUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/NumberUtils.java
@@ -89,9 +89,9 @@ public final class NumberUtils {
return 0;
}
- int hash = hashCode(values[0]);
+ int hash = Long.hashCode(values[0]);
for (int index = 1; index < values.length; index++) {
- hash += 31 * hash + hashCode(values[index]);
+ hash += 31 * hash + Long.hashCode(values[index]);
}
return hash;
@@ -110,11 +110,6 @@ public final class NumberUtils {
return hash;
}
- // TODO in JDK-8 use Long.hashCode(long)
- public static int hashCode(long value) {
- return (int) (value ^ (value >>> 32));
- }
-
/**
* @param clazz The {@link Class} to examine - ignored if {@code null}
* @return If the class is a {@link Number} or one of the primitive numerical types
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/ObjectBuilder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/ObjectBuilder.java b/sshd-core/src/main/java/org/apache/sshd/common/util/ObjectBuilder.java
index a02324e..ba9da4d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/ObjectBuilder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/ObjectBuilder.java
@@ -25,8 +25,7 @@ package org.apache.sshd.common.util;
* @param <T> Type of object being built
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface ObjectBuilder<T> {
-
T build();
-
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/Predicate.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/Predicate.java b/sshd-core/src/main/java/org/apache/sshd/common/util/Predicate.java
deleted file mode 100644
index 70a310a..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/Predicate.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.common.util;
-
-/**
- * @param <T> Evaluation input type
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public interface Predicate<T> {
- // TODO replace this with Java-8 predicate when Java-8 becomes min. version for SSHD
- boolean evaluate(T input);
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/ReflectionUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/ReflectionUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/ReflectionUtils.java
index 089d6f6..961f32a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/ReflectionUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/ReflectionUtils.java
@@ -21,6 +21,7 @@ package org.apache.sshd.common.util;
import java.lang.reflect.Field;
import java.util.Collection;
+import java.util.function.Predicate;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
index 462e8fa..824aef9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java
@@ -299,9 +299,8 @@ public final class SecurityUtils {
/* -------------------------------------------------------------------- */
- // TODO in JDK-8 make this an interface...
- private static class BouncyCastleInputStreamLoader {
- public static KeyPair loadKeyPair(String resourceKey, InputStream inputStream, FilePasswordProvider provider)
+ private interface BouncyCastleInputStreamLoader {
+ static KeyPair loadKeyPair(String resourceKey, InputStream inputStream, FilePasswordProvider provider)
throws IOException, GeneralSecurityException {
try (PEMParser r = new PEMParser(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
Object o = r.readObject();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/Supplier.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/Supplier.java b/sshd-core/src/main/java/org/apache/sshd/common/util/Supplier.java
deleted file mode 100644
index c40a175..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/Supplier.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.common.util;
-
-/**
- * Same as in Java 8
- * @param <T> Type of object being supplied
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public interface Supplier<T> {
- T get();
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/Transformer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/Transformer.java b/sshd-core/src/main/java/org/apache/sshd/common/util/Transformer.java
index 88528f5..d353f8d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/Transformer.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/Transformer.java
@@ -20,15 +20,15 @@
package org.apache.sshd.common.util;
import java.util.Objects;
+import java.util.function.Function;
/**
* @param <I> Input type
* @param <O> Output type
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public interface Transformer<I, O> {
- // TODO in JDK-8 replace this with Function
-
+@FunctionalInterface
+public interface Transformer<I, O> extends Function<I, O> {
/**
* Invokes {@link Objects#toString(Object, String)} on the argument
* with {@code null} as the value to return if argument is {@code null}
@@ -54,6 +54,10 @@ public interface Transformer<I, O> {
}
};
+ @Override
+ default O apply(I input) {
+ return transform(input);
+ }
/**
* @param input Input value
* @return Transformed output value
@@ -76,9 +80,9 @@ public interface Transformer<I, O> {
throw new UnsupportedOperationException("No instance allowed");
}
- @SuppressWarnings({ "cast", "unchecked" })
+ @SuppressWarnings({ "unchecked" })
public static <U extends V, V> Transformer<U, V> identity() {
- return (Transformer<U, V>) IDENTITY;
+ return IDENTITY;
}
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
index c708a3e..b040853 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java
@@ -71,9 +71,7 @@ import org.apache.sshd.common.util.logging.SimplifiedLog;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public abstract class Buffer implements Readable {
-
- // TODO use Long.BYTES in JDK-8
- protected final byte[] workBuf = new byte[Long.SIZE / Byte.SIZE];
+ protected final byte[] workBuf = new byte[Long.BYTES];
protected Buffer() {
super();
@@ -131,16 +129,14 @@ public abstract class Buffer implements Readable {
}
public byte getByte() {
- // TODO use Byte.BYTES for JDK-8
- ensureAvailable(Byte.SIZE / Byte.SIZE);
- getRawBytes(workBuf, 0, Byte.SIZE / Byte.SIZE);
+ ensureAvailable(Byte.BYTES);
+ getRawBytes(workBuf, 0, Byte.BYTES);
return workBuf[0];
}
public short getShort() {
- // TODO use Short.BYTES for JDK-8
- ensureAvailable(Short.SIZE / Byte.SIZE);
- getRawBytes(workBuf, 0, Short.SIZE / Byte.SIZE);
+ ensureAvailable(Short.BYTES);
+ getRawBytes(workBuf, 0, Short.BYTES);
short v = (short) ((workBuf[1] << Byte.SIZE) & 0xFF00);
v |= workBuf[0] & 0xF;
return v;
@@ -151,16 +147,14 @@ public abstract class Buffer implements Readable {
}
public long getUInt() {
- // TODO use Integer.BYTES for JDK-8
- ensureAvailable(Integer.SIZE / Byte.SIZE);
- getRawBytes(workBuf, 0, Integer.SIZE / Byte.SIZE);
- return BufferUtils.getUInt(workBuf, 0, Integer.SIZE / Byte.SIZE);
+ ensureAvailable(Integer.BYTES);
+ getRawBytes(workBuf, 0, Integer.BYTES);
+ return BufferUtils.getUInt(workBuf, 0, Integer.BYTES);
}
public long getLong() {
- // TODO use Long.BYTES for JDK-8
- ensureAvailable(Long.SIZE / Byte.SIZE);
- getRawBytes(workBuf, 0, Long.SIZE / Byte.SIZE);
+ ensureAvailable(Long.BYTES);
+ getRawBytes(workBuf, 0, Long.BYTES);
long l = ((long) workBuf[0] << 56) & 0xff00000000000000L;
l |= ((long) workBuf[1] << 48) & 0x00ff000000000000L;
l |= ((long) workBuf[2] << 40) & 0x0000ff0000000000L;
@@ -226,7 +220,7 @@ public abstract class Buffer implements Readable {
* @see #getString(Charset)
*/
public Collection<String> getAvailableStrings(Charset charset) {
- Collection<String> list = new LinkedList<String>();
+ Collection<String> list = new LinkedList<>();
while (available() > 0) {
String s = getString(charset);
list.add(s);
@@ -255,7 +249,7 @@ public abstract class Buffer implements Readable {
return Collections.emptyList();
}
- List<String> list = new ArrayList<String>(count);
+ List<String> list = new ArrayList<>(count);
for (int index = 0; index < count; index++) {
String s = getString(charset);
list.add(s);
@@ -417,10 +411,9 @@ public abstract class Buffer implements Readable {
======================*/
public void putByte(byte b) {
- // TODO use Byte.BYTES in JDK-8
- ensureCapacity(Byte.SIZE / Byte.SIZE);
+ ensureCapacity(Byte.BYTES);
workBuf[0] = b;
- putRawBytes(workBuf, 0, Byte.SIZE / Byte.SIZE);
+ putRawBytes(workBuf, 0, Byte.BYTES);
}
public void putBuffer(Readable buffer) {
@@ -435,11 +428,10 @@ public abstract class Buffer implements Readable {
* @param i The 16-bit value
*/
public void putShort(int i) {
- // TODO use Short.BYTES for JDK-8
- ensureCapacity(Short.SIZE / Byte.SIZE);
+ ensureCapacity(Short.BYTES);
workBuf[0] = (byte) (i >> 8);
workBuf[1] = (byte) i;
- putRawBytes(workBuf, 0, Short.SIZE / Byte.SIZE);
+ putRawBytes(workBuf, 0, Short.BYTES);
}
/**
@@ -448,10 +440,9 @@ public abstract class Buffer implements Readable {
* @param i The 32-bit value
*/
public void putInt(long i) {
- // TODO use Integer.BYTES for JDK-8
- ensureCapacity(Integer.SIZE / Byte.SIZE);
- BufferUtils.putUInt(i, workBuf, 0, Integer.SIZE / Byte.SIZE);
- putRawBytes(workBuf, 0, Integer.SIZE / Byte.SIZE);
+ ensureCapacity(Integer.BYTES);
+ BufferUtils.putUInt(i, workBuf, 0, Integer.BYTES);
+ putRawBytes(workBuf, 0, Integer.BYTES);
}
/**
@@ -460,8 +451,7 @@ public abstract class Buffer implements Readable {
* @param i The 64-bit value
*/
public void putLong(long i) {
- // TODO use Long.BYTES for JDK-8
- ensureCapacity(Long.SIZE / Byte.SIZE);
+ ensureCapacity(Long.BYTES);
workBuf[0] = (byte) (i >> 56);
workBuf[1] = (byte) (i >> 48);
workBuf[2] = (byte) (i >> 40);
@@ -470,7 +460,7 @@ public abstract class Buffer implements Readable {
workBuf[5] = (byte) (i >> 16);
workBuf[6] = (byte) (i >> 8);
workBuf[7] = (byte) i;
- putRawBytes(workBuf, 0, Long.SIZE / Byte.SIZE);
+ putRawBytes(workBuf, 0, Long.BYTES);
}
public void putBoolean(boolean b) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
index 9181b90..ab62c0e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java
@@ -306,13 +306,11 @@ public final class BufferUtils {
*/
public static long readUInt(InputStream input, byte[] buf, int offset, int len) throws IOException {
try {
- // TODO use Integer.BYTES for JDK-8
- if (len < (Integer.SIZE / Byte.SIZE)) {
- throw new IllegalArgumentException("Not enough data for a UINT: required=" + (Integer.SIZE / Byte.SIZE) + ", available=" + len);
+ if (len < Integer.BYTES) {
+ throw new IllegalArgumentException("Not enough data for a UINT: required=" + Integer.BYTES + ", available=" + len);
}
- // TODO use Integer.BYTES for JDK-8
- IoUtils.readFully(input, buf, offset, Integer.SIZE / Byte.SIZE);
+ IoUtils.readFully(input, buf, offset, Integer.BYTES);
return getUInt(buf, offset, len);
} catch (RuntimeException | Error e) {
throw new StreamCorruptedException("Failed (" + e.getClass().getSimpleName() + ")"
@@ -341,9 +339,8 @@ public final class BufferUtils {
* @return The result as a {@code long} whose 32 high-order bits are zero
*/
public static long getUInt(byte[] buf, int off, int len) {
- // TODO use Integer.BYTES for JDK-8
- if (len < (Integer.SIZE / Byte.SIZE)) {
- throw new IllegalArgumentException("Not enough data for a UINT: required=" + (Integer.SIZE / Byte.SIZE) + ", available=" + len);
+ if (len < Integer.BYTES) {
+ throw new IllegalArgumentException("Not enough data for a UINT: required=" + Integer.BYTES + ", available=" + len);
}
long l = (buf[off] << 24) & 0xff000000L;
@@ -439,9 +436,8 @@ public final class BufferUtils {
* @throws IllegalArgumentException if not enough space available
*/
public static int putUInt(long value, byte[] buf, int off, int len) {
- // TODO use Integer.BYTES for JDK-8
- if (len < Integer.SIZE / Byte.SIZE) {
- throw new IllegalArgumentException("Not enough data for a UINT: required=" + (Integer.SIZE / Byte.SIZE) + ", available=" + len);
+ if (len < Integer.BYTES) {
+ throw new IllegalArgumentException("Not enough data for a UINT: required=" + Integer.BYTES + ", available=" + len);
}
buf[off] = (byte) ((value >> 24) & 0xFF);
@@ -449,7 +445,7 @@ public final class BufferUtils {
buf[off + 2] = (byte) ((value >> 8) & 0xFF);
buf[off + 3] = (byte) (value & 0xFF);
- return Integer.SIZE / Byte.SIZE;
+ return Integer.BYTES;
}
public static boolean equals(byte[] a1, byte[] a2) {
@@ -497,7 +493,7 @@ public final class BufferUtils {
* @return The amount of data that has been encoded
*/
public static int updateLengthPlaceholder(Buffer buffer, int lenPos) {
- int startPos = lenPos + (Integer.SIZE / Byte.SIZE);
+ int startPos = lenPos + Integer.BYTES;
int endPos = buffer.wpos();
int dataLength = endPos - startPos;
// NOTE: although data length is defined as UINT32, we do not expected sizes above Integer.MAX_VALUE
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/ByteArrayBuffer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/ByteArrayBuffer.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/ByteArrayBuffer.java
index 831a4d7..8d29494 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/ByteArrayBuffer.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/ByteArrayBuffer.java
@@ -126,15 +126,13 @@ public class ByteArrayBuffer extends Buffer {
@Override
public byte getByte() {
- // TODO use Byte.BYTES for JDK-8
- ensureAvailable(Byte.SIZE / Byte.SIZE);
+ ensureAvailable(Byte.BYTES);
return data[rpos++];
}
@Override
public void putByte(byte b) {
- // TODO use Byte.BYTES in JDK-8
- ensureCapacity(Byte.SIZE / Byte.SIZE);
+ ensureCapacity(Byte.BYTES);
data[wpos++] = b;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/io/DERParser.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/io/DERParser.java b/sshd-core/src/main/java/org/apache/sshd/common/util/io/DERParser.java
index c66c57d..0f94726 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/io/DERParser.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/io/DERParser.java
@@ -45,8 +45,7 @@ public class DERParser extends FilterInputStream {
*/
public static final int MAX_DER_VALUE_LENGTH = 2 * Short.MAX_VALUE;
- // TODO in JDK-8 use Integer.BYTES
- private final byte[] lenBytes = new byte[Integer.SIZE / Byte.SIZE];
+ private final byte[] lenBytes = new byte[Integer.BYTES];
public DERParser(byte... bytes) {
this(bytes, 0, NumberUtils.length(bytes));
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/io/DERWriter.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/io/DERWriter.java b/sshd-core/src/main/java/org/apache/sshd/common/util/io/DERWriter.java
index f5cb0c9..09999cd 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/io/DERWriter.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/io/DERWriter.java
@@ -38,8 +38,7 @@ import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class DERWriter extends FilterOutputStream {
- // TODO in JDK-8 use Integer.BYTES
- private final byte[] lenBytes = new byte[Integer.SIZE / Byte.SIZE];
+ private final byte[] lenBytes = new byte[Integer.BYTES];
public DERWriter() {
this(ByteArrayBuffer.DEFAULT_SIZE);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java
index 55797b1..5757fb2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java
@@ -29,11 +29,11 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
+import java.util.function.Predicate;
import java.util.logging.Level;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.NumberUtils;
-import org.apache.sshd.common.util.Predicate;
import org.apache.sshd.common.util.ReflectionUtils;
import org.slf4j.Logger;
@@ -60,7 +60,7 @@ public final class LoggingUtils {
public static Map<Integer, String> generateMnemonicMap(Class<?> clazz, final String commonPrefix) {
return generateMnemonicMap(clazz, new Predicate<Field>() {
@Override
- public boolean evaluate(Field f) {
+ public boolean test(Field f) {
String name = f.getName();
return name.startsWith(commonPrefix);
}
@@ -113,10 +113,10 @@ public final class LoggingUtils {
* fields in this map. The key is the field's name and value is its associated opcode.
* @see #getAmbiguousMenmonics(Class, Predicate)
*/
- public static Map<String, Integer> getAmbiguousMenmonics(Class<?> clazz, final String commonPrefix) {
+ public static Map<String, Integer> getAmbiguousMenmonics(Class<?> clazz, String commonPrefix) {
return getAmbiguousMenmonics(clazz, new Predicate<Field>() {
@Override
- public boolean evaluate(Field f) {
+ public boolean test(Field f) {
String name = f.getName();
return name.startsWith(commonPrefix);
}
@@ -141,7 +141,7 @@ public final class LoggingUtils {
return Collections.emptyMap();
}
- Map<String, Integer> result = new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);
+ Map<String, Integer> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
Map<Integer, List<String>> opcodesMap = new HashMap<>(fields.size());
for (Field f : fields) {
String name = f.getName();
@@ -150,7 +150,7 @@ public final class LoggingUtils {
Integer key = NumberUtils.toInteger(value);
List<String> nameList = opcodesMap.get(key);
if (nameList == null) {
- nameList = new ArrayList<String>();
+ nameList = new ArrayList<>();
opcodesMap.put(key, nameList);
}
nameList.add(name);
@@ -179,10 +179,10 @@ public final class LoggingUtils {
* (besides being a {@link Number} and {@code public static final}).
* @return A {@link Collection} of all the fields that have satisfied all conditions
*/
- public static Collection<Field> getMnemonicFields(Class<?> clazz, final Predicate<? super Field> acceptor) {
+ public static Collection<Field> getMnemonicFields(Class<?> clazz, Predicate<? super Field> acceptor) {
return ReflectionUtils.getMatchingFields(clazz, new Predicate<Field>() {
@Override
- public boolean evaluate(Field f) {
+ public boolean test(Field f) {
int mods = f.getModifiers();
if ((!Modifier.isPublic(mods)) || (!Modifier.isStatic(mods)) || (!Modifier.isFinal(mods))) {
return false;
@@ -193,7 +193,7 @@ public final class LoggingUtils {
return false;
}
- return acceptor.evaluate(f);
+ return acceptor.test(f);
}
});
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/server/ChannelSessionAware.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/ChannelSessionAware.java b/sshd-core/src/main/java/org/apache/sshd/server/ChannelSessionAware.java
index 26ecb92..150e719 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/ChannelSessionAware.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/ChannelSessionAware.java
@@ -24,6 +24,7 @@ import org.apache.sshd.server.channel.ChannelSession;
* {@link Command} can implement this optional interface
* to receive a reference to {@link ChannelSession}.
*/
+@FunctionalInterface
public interface ChannelSessionAware {
/**
* Receives the channel in which the command is being executed.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/server/SessionAware.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/SessionAware.java b/sshd-core/src/main/java/org/apache/sshd/server/SessionAware.java
index 2f34aea..c331663 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/SessionAware.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/SessionAware.java
@@ -24,6 +24,7 @@ import org.apache.sshd.server.session.ServerSession;
* Interface that can be implemented by a command to be able to access the
* server session in which this command will be used.
*/
+@FunctionalInterface
public interface SessionAware {
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/HostBasedAuthenticator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/HostBasedAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/HostBasedAuthenticator.java
index 37d2d3d..3f069c7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/HostBasedAuthenticator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/HostBasedAuthenticator.java
@@ -30,6 +30,7 @@ import org.apache.sshd.server.session.ServerSession;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
* @see <A HREF="https://www.ietf.org/rfc/rfc4252.txt">RFC 4252 - section 9</A>
*/
+@FunctionalInterface
public interface HostBasedAuthenticator {
/**
* @param session The {@link ServerSession} through which the request was received
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/server/auth/password/PasswordAuthenticator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/password/PasswordAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/password/PasswordAuthenticator.java
index 494b691..902c128 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/password/PasswordAuthenticator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/password/PasswordAuthenticator.java
@@ -25,6 +25,7 @@ import org.apache.sshd.server.session.ServerSession;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface PasswordAuthenticator {
/**
* Check the validity of a password.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/PublickeyAuthenticator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/PublickeyAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/PublickeyAuthenticator.java
index 67b2cf1..5146ea7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/PublickeyAuthenticator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/PublickeyAuthenticator.java
@@ -28,6 +28,7 @@ import org.apache.sshd.server.session.ServerSession;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface PublickeyAuthenticator {
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
index 52801d6..457ded9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
@@ -64,7 +64,7 @@ public class CancelTcpipForwardHandler extends AbstractConnectionServiceRequestH
if (wantReply) {
Session session = connectionService.getSession();
- buffer = session.createBuffer(SshConstants.SSH_MSG_REQUEST_SUCCESS, Integer.SIZE / Byte.SIZE);
+ buffer = session.createBuffer(SshConstants.SSH_MSG_REQUEST_SUCCESS, Integer.BYTES);
buffer.putInt(port);
session.writePacket(buffer);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
index 037c1ea..3dd2d06 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
@@ -70,7 +70,7 @@ public class TcpipForwardHandler extends AbstractConnectionServiceRequestHandler
port = bound.getPort();
if (wantReply) {
Session session = connectionService.getSession();
- buffer = session.createBuffer(SshConstants.SSH_MSG_REQUEST_SUCCESS, Integer.SIZE / Byte.SIZE);
+ buffer = session.createBuffer(SshConstants.SSH_MSG_REQUEST_SUCCESS, Integer.BYTES);
buffer.putInt(port);
session.writePacket(buffer);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerProxyAcceptor.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerProxyAcceptor.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerProxyAcceptor.java
index cf6fac0..fa0cff7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerProxyAcceptor.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerProxyAcceptor.java
@@ -28,6 +28,7 @@ import org.apache.sshd.common.util.buffer.Buffer;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface ServerProxyAcceptor {
/**
* Invoked <U>before</U> any attempt is made to retrieve the SSH client
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionHolder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionHolder.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionHolder.java
index 6b4ff38..729cff2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionHolder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionHolder.java
@@ -22,6 +22,7 @@ package org.apache.sshd.server.session;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface ServerSessionHolder {
/**
* @return The underlying {@link ServerSession} used
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShell.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShell.java b/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShell.java
index 78492b7..755f390 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShell.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShell.java
@@ -62,7 +62,7 @@ public class ProcessShell extends AbstractLoggingBean implements InvertedShell,
public ProcessShell(Collection<String> command) {
// we copy the original list so as not to change it
- this.command = new ArrayList<String>(ValidateUtils.checkNotNullAndNotEmpty(command, "No process shell command(s)"));
+ this.command = new ArrayList<>(ValidateUtils.checkNotNullAndNotEmpty(command, "No process shell command(s)"));
this.cmdValue = GenericUtils.join(command, ' ');
}
@@ -145,18 +145,11 @@ public class ProcessShell extends AbstractLoggingBean implements InvertedShell,
@Override
public boolean isAlive() {
- // TODO in JDK-8 call process.isAlive()
- try {
- process.exitValue();
- return false;
- } catch (IllegalThreadStateException e) {
- return true;
- }
+ return process.isAlive();
}
@Override
public int exitValue() {
- // TODO in JDK-8 call process.isAlive()
if (isAlive()) {
try {
return process.waitFor();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
index 8b53016..89cb6f1 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
@@ -291,7 +291,7 @@ public class SftpSubsystem
protected ExecutorService executors;
protected boolean shutdownExecutor;
protected Future<?> pendingFuture;
- protected byte[] workBuf = new byte[Math.max(DEFAULT_FILE_HANDLE_SIZE, Integer.SIZE / Byte.SIZE)]; // TODO in JDK-8 use Integer.BYTES
+ protected byte[] workBuf = new byte[Math.max(DEFAULT_FILE_HANDLE_SIZE, Integer.BYTES)];
protected FileSystem fileSystem = FileSystems.getDefault();
protected Path defaultDir = fileSystem.getPath(System.getProperty("user.dir"));
protected long requestsCount;
@@ -427,9 +427,9 @@ public class SftpSubsystem
try {
for (long count = 1L;; count++) {
int length = BufferUtils.readInt(in, workBuf, 0, workBuf.length);
- ValidateUtils.checkTrue(length >= ((Integer.SIZE / Byte.SIZE) + 1 /* command */), "Bad length to read: %d", length);
+ ValidateUtils.checkTrue(length >= (Integer.BYTES + 1 /* command */), "Bad length to read: %d", length);
- Buffer buffer = new ByteArrayBuffer(length + (Integer.SIZE / Byte.SIZE) + Long.SIZE /* a bit extra */, false);
+ Buffer buffer = new ByteArrayBuffer(length + Integer.BYTES + Long.SIZE /* a bit extra */, false);
buffer.putInt(length);
for (int remainLen = length; remainLen > 0;) {
int l = in.read(buffer.array(), buffer.wpos(), remainLen);
[2/3] mina-sshd git commit: [SSHD-674] Converted some more code to
Java 8
Posted by lg...@apache.org.
[SSHD-674] Converted some more code to Java 8
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/25bc715a
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/25bc715a
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/25bc715a
Branch: refs/heads/master
Commit: 25bc715a5680499375b5de12c6e14c3017380053
Parents: 5a13329
Author: Lyor Goldstein <ly...@gmail.com>
Authored: Thu Aug 4 20:06:53 2016 +0300
Committer: Lyor Goldstein <ly...@gmail.com>
Committed: Thu Aug 4 20:06:53 2016 +0300
----------------------------------------------------------------------
.../apache/sshd/agent/SshAgentConstants.java | 4 +-
.../java/org/apache/sshd/client/SshClient.java | 2 +-
.../auth/password/PasswordIdentityProvider.java | 2 +-
.../channel/PtyCapableChannelSession.java | 2 +-
.../keys/BuiltinClientIdentitiesWatcher.java | 2 +-
.../config/keys/ClientIdentitiesWatcher.java | 2 +-
.../config/keys/ClientIdentityFileWatcher.java | 2 +-
.../keys/DefaultClientIdentitiesWatcher.java | 2 +-
.../sshd/client/future/DefaultAuthFuture.java | 10 +-
.../client/future/DefaultConnectFuture.java | 15 +--
.../sshd/client/future/DefaultOpenFuture.java | 14 +--
.../keyverifier/ModifiedServerKeyAcceptor.java | 1 +
.../client/keyverifier/ServerKeyVerifier.java | 1 +
.../sshd/client/scp/AbstractScpClient.java | 107 +------------------
.../sshd/client/scp/DefaultScpClient.java | 10 +-
.../org/apache/sshd/client/scp/ScpClient.java | 96 ++++++++++++++---
.../sshd/client/scp/ScpClientCreator.java | 12 ++-
.../client/session/AbstractClientSession.java | 26 +----
.../client/session/ClientSessionHolder.java | 1 +
.../subsystem/sftp/AbstractSftpClient.java | 107 +------------------
.../subsystem/sftp/DefaultSftpClient.java | 14 ++-
.../sshd/client/subsystem/sftp/SftpClient.java | 88 +++++++++++----
.../subsystem/sftp/SftpClientCreator.java | 8 +-
.../extensions/BuiltinSftpClientExtensions.java | 6 --
.../extensions/SftpClientExtensionFactory.java | 7 +-
.../helpers/AbstractMD5HashExtension.java | 2 +-
.../helpers/AbstractSftpClientExtension.java | 8 +-
.../helpers/CopyDataExtensionImpl.java | 6 +-
.../helpers/CopyFileExtensionImpl.java | 4 +-
.../helpers/OpenSSHFsyncExtensionImpl.java | 2 +-
.../java/org/apache/sshd/common/Factory.java | 1 +
.../sshd/common/FactoryManagerHolder.java | 1 +
.../org/apache/sshd/common/NamedResource.java | 1 +
.../org/apache/sshd/common/OptionalFeature.java | 3 +-
.../org/apache/sshd/common/SshConstants.java | 6 +-
.../sshd/common/channel/AbstractChannel.java | 4 +-
.../common/channel/ChannelAsyncInputStream.java | 6 +-
.../sshd/common/channel/ChannelHolder.java | 1 +
.../sshd/common/channel/RequestHandler.java | 2 +-
.../org/apache/sshd/common/channel/Window.java | 8 +-
.../apache/sshd/common/cipher/BaseCipher.java | 6 --
.../sshd/common/cipher/BuiltinCiphers.java | 1 -
.../org/apache/sshd/common/cipher/Cipher.java | 5 +-
.../apache/sshd/common/cipher/CipherNone.java | 8 --
.../common/compression/BuiltinCompressions.java | 1 -
.../sshd/common/compression/Compression.java | 1 -
.../sshd/common/file/FileSystemAware.java | 1 +
.../sshd/common/file/FileSystemFactory.java | 2 +-
.../common/forward/TcpipForwarderFactory.java | 1 +
.../sshd/common/future/AbstractSshFuture.java | 26 +----
.../sshd/common/future/DefaultCloseFuture.java | 4 +-
.../common/future/DefaultKeyExchangeFuture.java | 4 +-
.../future/DefaultVerifiableSshFuture.java | 13 ---
.../sshd/common/future/SshFutureListener.java | 1 +
.../sshd/common/future/VerifiableFuture.java | 10 +-
.../sshd/common/future/WaitableFuture.java | 16 ++-
.../sshd/common/io/AbstractIoWriteFuture.java | 7 +-
.../sshd/common/kex/BuiltinDHFactories.java | 3 +-
.../common/keyprovider/KeyIdentityProvider.java | 2 +-
.../org/apache/sshd/common/mac/BaseMac.java | 19 ----
.../org/apache/sshd/common/mac/BuiltinMacs.java | 1 -
.../java/org/apache/sshd/common/mac/Mac.java | 17 ++-
.../sshd/common/random/AbstractRandom.java | 5 -
.../org/apache/sshd/common/random/Random.java | 4 +-
.../sshd/common/session/SessionHolder.java | 1 +
.../common/signature/AbstractSignature.java | 12 +--
.../common/signature/BuiltinSignatures.java | 1 -
.../common/subsystem/sftp/SftpConstants.java | 4 +-
.../sftp/extensions/AbstractParser.java | 11 --
.../sftp/extensions/ExtensionParser.java | 10 +-
.../apache/sshd/common/util/GenericUtils.java | 28 ++---
.../sshd/common/util/Int2IntFunction.java | 1 +
.../apache/sshd/common/util/NumberUtils.java | 9 +-
.../apache/sshd/common/util/ObjectBuilder.java | 3 +-
.../org/apache/sshd/common/util/Predicate.java | 29 -----
.../sshd/common/util/ReflectionUtils.java | 1 +
.../apache/sshd/common/util/SecurityUtils.java | 5 +-
.../org/apache/sshd/common/util/Supplier.java | 29 -----
.../apache/sshd/common/util/Transformer.java | 14 ++-
.../apache/sshd/common/util/buffer/Buffer.java | 52 ++++-----
.../sshd/common/util/buffer/BufferUtils.java | 22 ++--
.../common/util/buffer/ByteArrayBuffer.java | 6 +-
.../apache/sshd/common/util/io/DERParser.java | 3 +-
.../apache/sshd/common/util/io/DERWriter.java | 3 +-
.../sshd/common/util/logging/LoggingUtils.java | 18 ++--
.../apache/sshd/server/ChannelSessionAware.java | 1 +
.../org/apache/sshd/server/SessionAware.java | 1 +
.../auth/hostbased/HostBasedAuthenticator.java | 1 +
.../auth/password/PasswordAuthenticator.java | 1 +
.../auth/pubkey/PublickeyAuthenticator.java | 1 +
.../global/CancelTcpipForwardHandler.java | 2 +-
.../sshd/server/global/TcpipForwardHandler.java | 2 +-
.../server/session/ServerProxyAcceptor.java | 1 +
.../server/session/ServerSessionHolder.java | 1 +
.../apache/sshd/server/shell/ProcessShell.java | 11 +-
.../server/subsystem/sftp/SftpSubsystem.java | 6 +-
96 files changed, 397 insertions(+), 647 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentConstants.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentConstants.java b/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentConstants.java
index e533cb0..aecf89d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentConstants.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentConstants.java
@@ -20,9 +20,9 @@ package org.apache.sshd.agent;
import java.lang.reflect.Field;
import java.util.Map;
+import java.util.function.Predicate;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Predicate;
import org.apache.sshd.common.util.logging.LoggingUtils;
/**
@@ -78,7 +78,7 @@ public final class SshAgentConstants {
private static final Map<Integer, String> MESSAGES_MAP =
LoggingUtils.generateMnemonicMap(SshAgentConstants.class, new Predicate<Field>() {
@Override
- public boolean evaluate(Field f) {
+ public boolean test(Field f) {
String name = f.getName();
if (name.startsWith("SSH_AGENT_CONSTRAIN")) {
return false;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
index 1299518..244f285 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
@@ -50,6 +50,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.Supplier;
import java.util.logging.ConsoleHandler;
import java.util.logging.Formatter;
import java.util.logging.Handler;
@@ -118,7 +119,6 @@ import org.apache.sshd.common.session.helpers.AbstractSession;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.OsUtils;
import org.apache.sshd.common.util.SecurityUtils;
-import org.apache.sshd.common.util.Supplier;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.common.util.io.NoCloseInputStream;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/auth/password/PasswordIdentityProvider.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/password/PasswordIdentityProvider.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/password/PasswordIdentityProvider.java
index 44f3b17..8250462 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/password/PasswordIdentityProvider.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/password/PasswordIdentityProvider.java
@@ -24,10 +24,10 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
+import java.util.function.Supplier;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Supplier;
import org.apache.sshd.common.util.Transformer;
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
index 61d0e91..bba9947 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
@@ -252,7 +252,7 @@ public class PtyCapableChannelSession extends ChannelSession {
buffer.putInt(ptyHeight);
buffer.putInt(ptyWidth);
- Buffer modes = new ByteArrayBuffer(GenericUtils.size(ptyModes) * (1 + (Integer.SIZE / Byte.SIZE)) + Long.SIZE, false);
+ Buffer modes = new ByteArrayBuffer(GenericUtils.size(ptyModes) * (1 + Integer.BYTES) + Long.SIZE, false);
for (Map.Entry<PtyMode, ? extends Number> modeEntry : ptyModes.entrySet()) {
PtyMode mode = modeEntry.getKey();
Number value = modeEntry.getValue();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcher.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcher.java b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcher.java
index fb104b4..fb9abce 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcher.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcher.java
@@ -26,13 +26,13 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
+import java.util.function.Supplier;
import org.apache.sshd.common.NamedResource;
import org.apache.sshd.common.config.keys.BuiltinIdentities;
import org.apache.sshd.common.config.keys.FilePasswordProvider;
import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Supplier;
import org.apache.sshd.common.util.ValidateUtils;
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java
index 4abd4f7..c3dfe01 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java
@@ -25,12 +25,12 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.function.Supplier;
import org.apache.sshd.common.config.keys.FilePasswordProvider;
import org.apache.sshd.common.keyprovider.AbstractKeyPairProvider;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Supplier;
import org.apache.sshd.common.util.ValidateUtils;
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcher.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcher.java b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcher.java
index a982324..3974930 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcher.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcher.java
@@ -25,12 +25,12 @@ import java.security.GeneralSecurityException;
import java.security.KeyPair;
import java.security.PublicKey;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Supplier;
import org.apache.sshd.common.config.keys.FilePasswordProvider;
import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.Pair;
-import org.apache.sshd.common.util.Supplier;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.common.util.io.ModifiableFileWatcher;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/DefaultClientIdentitiesWatcher.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/DefaultClientIdentitiesWatcher.java b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/DefaultClientIdentitiesWatcher.java
index ba1719f..b91fa7b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/DefaultClientIdentitiesWatcher.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/DefaultClientIdentitiesWatcher.java
@@ -21,11 +21,11 @@ package org.apache.sshd.client.config.keys;
import java.nio.file.Path;
import java.util.List;
+import java.util.function.Supplier;
import org.apache.sshd.common.config.keys.FilePasswordProvider;
import org.apache.sshd.common.config.keys.PublicKeyEntry;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Supplier;
import org.apache.sshd.common.util.ValidateUtils;
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultAuthFuture.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultAuthFuture.java b/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultAuthFuture.java
index f42b94c..c41bed1 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultAuthFuture.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultAuthFuture.java
@@ -45,7 +45,7 @@ public class DefaultAuthFuture extends DefaultVerifiableSshFuture<AuthFuture> im
return this;
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public Throwable getException() {
Object v = getValue();
if (v instanceof Throwable) {
@@ -55,13 +55,13 @@ public class DefaultAuthFuture extends DefaultVerifiableSshFuture<AuthFuture> im
}
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public boolean isSuccess() {
Object v = getValue();
return (v instanceof Boolean) && ((Boolean) v).booleanValue();
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public boolean isFailure() {
Object v = getValue();
if (v instanceof Boolean) {
@@ -71,12 +71,12 @@ public class DefaultAuthFuture extends DefaultVerifiableSshFuture<AuthFuture> im
}
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public void setAuthed(boolean authed) {
setValue(authed);
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public void setException(Throwable exception) {
ValidateUtils.checkNotNull(exception, "No exception provided");
setValue(exception);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultConnectFuture.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultConnectFuture.java b/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultConnectFuture.java
index fd896ad..eb207ac 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultConnectFuture.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultConnectFuture.java
@@ -19,6 +19,7 @@
package org.apache.sshd.client.future;
import java.io.IOException;
+import java.util.Objects;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.RuntimeSshException;
@@ -36,7 +37,7 @@ public class DefaultConnectFuture extends DefaultVerifiableSshFuture<ConnectFutu
super(lock);
}
- @Override // TODO in JDK-8 make this a default method
+ @Override
public ConnectFuture verify(long timeout) throws IOException {
long startTime = System.nanoTime();
ClientSession session = verifyResult(ClientSession.class, timeout);
@@ -48,7 +49,7 @@ public class DefaultConnectFuture extends DefaultVerifiableSshFuture<ConnectFutu
return this;
}
- @Override // TODO in JDK-8 make this a default method
+ @Override
public ClientSession getSession() {
Object v = getValue();
if (v instanceof RuntimeException) {
@@ -64,7 +65,7 @@ public class DefaultConnectFuture extends DefaultVerifiableSshFuture<ConnectFutu
}
}
- @Override // TODO in JDK-8 make this a default method
+ @Override
public Throwable getException() {
Object v = getValue();
if (v instanceof Throwable) {
@@ -74,18 +75,18 @@ public class DefaultConnectFuture extends DefaultVerifiableSshFuture<ConnectFutu
}
}
- @Override // TODO in JDK-8 make this a default method
+ @Override
public boolean isConnected() {
return getValue() instanceof ClientSession;
}
- @Override // TODO in JDK-8 make this a default method
+ @Override
public void setSession(ClientSession session) {
- ValidateUtils.checkNotNull(session, "No client session provided");
+ Objects.requireNonNull(session, "No client session provided");
setValue(session);
}
- @Override // TODO in JDK-8 make this a default method
+ @Override
public void setException(Throwable exception) {
ValidateUtils.checkNotNull(exception, "No exception provided");
setValue(exception);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultOpenFuture.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultOpenFuture.java b/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultOpenFuture.java
index 0f3bc2e..4034003 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultOpenFuture.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/future/DefaultOpenFuture.java
@@ -19,10 +19,10 @@
package org.apache.sshd.client.future;
import java.io.IOException;
+import java.util.Objects;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.future.DefaultVerifiableSshFuture;
-import org.apache.sshd.common.util.ValidateUtils;
/**
* A default implementation of {@link OpenFuture}.
@@ -34,7 +34,7 @@ public class DefaultOpenFuture extends DefaultVerifiableSshFuture<OpenFuture> im
super(lock);
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public OpenFuture verify(long timeoutMillis) throws IOException {
Boolean result = verifyResult(Boolean.class, timeoutMillis);
if (!result.booleanValue()) {
@@ -44,7 +44,7 @@ public class DefaultOpenFuture extends DefaultVerifiableSshFuture<OpenFuture> im
return this;
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public Throwable getException() {
Object v = getValue();
if (v instanceof Throwable) {
@@ -54,20 +54,20 @@ public class DefaultOpenFuture extends DefaultVerifiableSshFuture<OpenFuture> im
}
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public boolean isOpened() {
Object value = getValue();
return (value instanceof Boolean) && ((Boolean) value).booleanValue();
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public void setOpened() {
setValue(Boolean.TRUE);
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public void setException(Throwable exception) {
- ValidateUtils.checkNotNull(exception, "No exception provided");
+ Objects.requireNonNull(exception, "No exception provided");
setValue(exception);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/ModifiedServerKeyAcceptor.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/ModifiedServerKeyAcceptor.java b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/ModifiedServerKeyAcceptor.java
index 784576e..6472e04 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/ModifiedServerKeyAcceptor.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/ModifiedServerKeyAcceptor.java
@@ -28,6 +28,7 @@ import org.apache.sshd.client.session.ClientSession;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface ModifiedServerKeyAcceptor {
/**
* Invoked when a matching known host key was found but it does not match
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/ServerKeyVerifier.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/ServerKeyVerifier.java b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/ServerKeyVerifier.java
index 5305dab..6122cee 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/ServerKeyVerifier.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/ServerKeyVerifier.java
@@ -29,6 +29,7 @@ import org.apache.sshd.client.session.ClientSession;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface ServerKeyVerifier {
/**
* Verify that the server key provided is really the one of the host.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/scp/AbstractScpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/scp/AbstractScpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/scp/AbstractScpClient.java
index 3c1b5af..fa979c6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/scp/AbstractScpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/scp/AbstractScpClient.java
@@ -19,15 +19,11 @@
package org.apache.sshd.client.scp;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
-import java.nio.file.attribute.PosixFilePermission;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -45,7 +41,6 @@ import org.apache.sshd.common.SshException;
import org.apache.sshd.common.file.FileSystemFactory;
import org.apache.sshd.common.scp.ScpException;
import org.apache.sshd.common.scp.ScpHelper;
-import org.apache.sshd.common.scp.ScpTimestamp;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.io.IoUtils;
@@ -68,16 +63,6 @@ public abstract class AbstractScpClient extends AbstractLoggingBean implements S
}
@Override
- public void download(String remote, String local, Option... options) throws IOException {
- download(remote, local, GenericUtils.isEmpty(options) ? Collections.<Option>emptySet() : GenericUtils.of(options));
- }
-
- @Override
- public void download(String[] remote, String local, Option... options) throws IOException {
- download(remote, local, GenericUtils.isEmpty(options) ? Collections.<Option>emptySet() : GenericUtils.of(options));
- }
-
- @Override
public void download(String[] remote, String local, Collection<Option> options) throws IOException {
local = ValidateUtils.checkNotNullAndNotEmpty(local, "Invalid argument local: %s", local);
remote = ValidateUtils.checkNotNullAndNotEmpty(remote, "Invalid argument remote: %s", (Object) remote);
@@ -92,11 +77,6 @@ public abstract class AbstractScpClient extends AbstractLoggingBean implements S
}
@Override
- public void download(String[] remote, Path local, Option... options) throws IOException {
- download(remote, local, GenericUtils.isEmpty(options) ? Collections.<Option>emptySet() : GenericUtils.of(options));
- }
-
- @Override
public void download(String[] remote, Path local, Collection<Option> options) throws IOException {
remote = ValidateUtils.checkNotNullAndNotEmpty(remote, "Invalid argument remote: %s", (Object) remote);
@@ -110,11 +90,6 @@ public abstract class AbstractScpClient extends AbstractLoggingBean implements S
}
@Override
- public void download(String remote, Path local, Option... options) throws IOException {
- download(remote, local, GenericUtils.of(options));
- }
-
- @Override
public void download(String remote, Path local, Collection<Option> options) throws IOException {
local = ValidateUtils.checkNotNull(local, "Invalid argument local: %s", local);
remote = ValidateUtils.checkNotNullAndNotEmpty(remote, "Invalid argument remote: %s", remote);
@@ -167,57 +142,6 @@ public abstract class AbstractScpClient extends AbstractLoggingBean implements S
protected abstract void download(String remote, FileSystem fs, Path local, Collection<Option> options) throws IOException;
@Override
- public byte[] downloadBytes(String remote) throws IOException {
- try (ByteArrayOutputStream local = new ByteArrayOutputStream()) {
- download(remote, local);
- return local.toByteArray();
- }
- }
-
- @Override
- public void upload(String local, String remote, Option... options) throws IOException {
- upload(local, remote, GenericUtils.of(options));
- }
-
- @Override
- public void upload(String local, String remote, Collection<Option> options) throws IOException {
- upload(new String[]{ValidateUtils.checkNotNullAndNotEmpty(local, "Invalid argument local: %s", local)}, remote, options);
- }
-
- @Override
- public void upload(String[] local, String remote, Option... options) throws IOException {
- upload(local, remote, GenericUtils.isEmpty(options) ? Collections.<Option>emptySet() : GenericUtils.of(options));
- }
-
- @Override
- public void upload(Path local, String remote, Option... options) throws IOException {
- upload(local, remote, GenericUtils.isEmpty(options) ? Collections.<Option>emptySet() : GenericUtils.of(options));
- }
-
- @Override
- public void upload(Path local, String remote, Collection<Option> options) throws IOException {
- upload(new Path[]{ValidateUtils.checkNotNull(local, "Invalid local argument: %s", local)},
- remote, GenericUtils.isEmpty(options) ? Collections.<Option>emptySet() : GenericUtils.of(options));
- }
-
- @Override
- public void upload(Path[] local, String remote, Option... options) throws IOException {
- upload(local, remote, GenericUtils.isEmpty(options) ? Collections.<Option>emptySet() : GenericUtils.of(options));
- }
-
- @Override
- public void upload(byte[] data, String remote, Collection<PosixFilePermission> perms, ScpTimestamp time) throws IOException {
- upload(data, 0, data.length, remote, perms, time);
- }
-
- @Override
- public void upload(byte[] data, int offset, int len, String remote, Collection<PosixFilePermission> perms, ScpTimestamp time) throws IOException {
- try (InputStream local = new ByteArrayInputStream(data, offset, len)) {
- upload(local, remote, len, perms, time);
- }
- }
-
- @Override
public void upload(String[] local, String remote, Collection<Option> options) throws IOException {
final Collection<String> paths = Arrays.asList(ValidateUtils.checkNotNullAndNotEmpty(local, "Invalid argument local: %s", (Object) local));
runUpload(remote, options, paths, new ScpOperationExecutor<String>() {
@@ -350,36 +274,7 @@ public abstract class AbstractScpClient extends AbstractLoggingBean implements S
}
}
- public static String createSendCommand(String remote, Collection<Option> options) {
- StringBuilder sb = new StringBuilder(remote.length() + Long.SIZE).append(ScpHelper.SCP_COMMAND_PREFIX);
- if (options.contains(Option.Recursive)) {
- sb.append(" -r");
- }
- if (options.contains(Option.TargetIsDirectory)) {
- sb.append(" -d");
- }
- if (options.contains(Option.PreserveAttributes)) {
- sb.append(" -p");
- }
-
- sb.append(" -t").append(" --").append(" ").append(remote);
- return sb.toString();
- }
-
- public static String createReceiveCommand(String remote, Collection<Option> options) {
- ValidateUtils.checkNotNullAndNotEmpty(remote, "No remote location specified");
- StringBuilder sb = new StringBuilder(remote.length() + Long.SIZE).append(ScpHelper.SCP_COMMAND_PREFIX);
- if (options.contains(Option.Recursive)) {
- sb.append(" -r");
- }
- if (options.contains(Option.PreserveAttributes)) {
- sb.append(" -p");
- }
-
- sb.append(" -f").append(" --").append(' ').append(remote);
- return sb.toString();
- }
-
+ @FunctionalInterface
public interface ScpOperationExecutor<T> {
void execute(ScpHelper helper, Collection<T> local, Collection<Option> options) throws IOException;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java
index 7b950a7..d750e5c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java
@@ -78,7 +78,7 @@ public class DefaultScpClient extends AbstractScpClient {
@Override
public void download(String remote, OutputStream local) throws IOException {
- String cmd = createReceiveCommand(remote, Collections.<Option>emptyList());
+ String cmd = ScpClient.createReceiveCommand(remote, Collections.<Option>emptyList());
ClientSession session = getClientSession();
ChannelExec channel = openCommandChannel(session, cmd);
try (InputStream invOut = channel.getInvertedOut();
@@ -94,7 +94,7 @@ public class DefaultScpClient extends AbstractScpClient {
@Override
protected void download(String remote, FileSystem fs, Path local, Collection<Option> options) throws IOException {
- String cmd = createReceiveCommand(remote, options);
+ String cmd = ScpClient.createReceiveCommand(remote, options);
ClientSession session = getClientSession();
ChannelExec channel = openCommandChannel(session, cmd);
try (InputStream invOut = channel.getInvertedOut();
@@ -117,7 +117,7 @@ public class DefaultScpClient extends AbstractScpClient {
final String name = (namePos < 0)
? remote
: ValidateUtils.checkNotNullAndNotEmpty(remote.substring(namePos + 1), "No name value in remote=%s", remote);
- final String cmd = createSendCommand(remote, (time != null) ? EnumSet.of(Option.PreserveAttributes) : Collections.<Option>emptySet());
+ final String cmd = ScpClient.createSendCommand(remote, (time != null) ? EnumSet.of(Option.PreserveAttributes) : Collections.<Option>emptySet());
ClientSession session = getClientSession();
ChannelExec channel = openCommandChannel(session, cmd);
try (InputStream invOut = channel.getInvertedOut();
@@ -141,7 +141,7 @@ public class DefaultScpClient extends AbstractScpClient {
options = addTargetIsDirectory(options);
}
- String cmd = createSendCommand(remote, options);
+ String cmd = ScpClient.createSendCommand(remote, options);
ClientSession session = getClientSession();
ChannelExec channel = openCommandChannel(session, cmd);
try {
@@ -182,7 +182,7 @@ public class DefaultScpClient extends AbstractScpClient {
return args;
}
- List<String> effective = new ArrayList<String>(numArgs);
+ List<String> effective = new ArrayList<>(numArgs);
boolean error = false;
for (int index = 0; (index < numArgs) && (!error); index++) {
String argName = args[index];
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClient.java
index a51f9c3..b2a6091 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClient.java
@@ -18,6 +18,8 @@
*/
package org.apache.sshd.client.scp;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -28,13 +30,16 @@ import java.util.concurrent.TimeUnit;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.client.session.ClientSessionHolder;
+import org.apache.sshd.common.scp.ScpHelper;
import org.apache.sshd.common.scp.ScpTimestamp;
import org.apache.sshd.common.session.SessionHolder;
+import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.common.util.ValidateUtils;
/**
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public interface ScpClient extends SessionHolder<ClientSession>, ClientSessionHolder {
-
enum Option {
Recursive,
PreserveAttributes,
@@ -61,48 +66,109 @@ public interface ScpClient extends SessionHolder<ClientSession>, ClientSessionHo
String SCP_EXEC_CHANNEL_EXIT_STATUS_TIMEOUT = "scp-exec-channel-exit-status-timeout";
long DEFAULT_EXEC_CHANNEL_EXIT_STATUS_TIMEOUT = TimeUnit.SECONDS.toMillis(5L);
- void download(String remote, String local, Option... options) throws IOException;
+ default void download(String remote, String local, Option... options) throws IOException {
+ download(remote, local, GenericUtils.of(options));
+ }
void download(String remote, String local, Collection<Option> options) throws IOException;
- void download(String remote, Path local, Option... options) throws IOException;
+ default void download(String remote, Path local, Option... options) throws IOException {
+ download(remote, local, GenericUtils.of(options));
+ }
void download(String remote, Path local, Collection<Option> options) throws IOException;
// NOTE: the remote location MUST be a file or an exception is generated
void download(String remote, OutputStream local) throws IOException;
- byte[] downloadBytes(String remote) throws IOException;
+ default byte[] downloadBytes(String remote) throws IOException {
+ try (ByteArrayOutputStream local = new ByteArrayOutputStream()) {
+ download(remote, local);
+ return local.toByteArray();
+ }
+ }
+
+ default void download(String[] remote, String local, Option... options) throws IOException {
+ download(remote, local, GenericUtils.of(options));
+ }
- void download(String[] remote, String local, Option... options) throws IOException;
+ default void download(String[] remote, Path local, Option... options) throws IOException {
+ download(remote, local, GenericUtils.of(options));
+ }
void download(String[] remote, String local, Collection<Option> options) throws IOException;
- void download(String[] remote, Path local, Option... options) throws IOException;
-
void download(String[] remote, Path local, Collection<Option> options) throws IOException;
- void upload(String local, String remote, Option... options) throws IOException;
+ default void upload(String local, String remote, Option... options) throws IOException {
+ upload(local, remote, GenericUtils.of(options));
+ }
- void upload(String local, String remote, Collection<Option> options) throws IOException;
+ default void upload(String local, String remote, Collection<Option> options) throws IOException {
+ upload(new String[]{ValidateUtils.checkNotNullAndNotEmpty(local, "Invalid argument local: %s", local)}, remote, options);
+ }
- void upload(Path local, String remote, Option... options) throws IOException;
+ default void upload(Path local, String remote, Option... options) throws IOException {
+ upload(local, remote, GenericUtils.of(options));
+ }
- void upload(Path local, String remote, Collection<Option> options) throws IOException;
+ default void upload(Path local, String remote, Collection<Option> options) throws IOException {
+ upload(new Path[]{ValidateUtils.checkNotNull(local, "Invalid local argument: %s", local)}, remote, GenericUtils.of(options));
+ }
- void upload(String[] local, String remote, Option... options) throws IOException;
+ default void upload(String[] local, String remote, Option... options) throws IOException {
+ upload(local, remote, GenericUtils.of(options));
+ }
void upload(String[] local, String remote, Collection<Option> options) throws IOException;
- void upload(Path[] local, String remote, Option... options) throws IOException;
+ default void upload(Path[] local, String remote, Option... options) throws IOException {
+ upload(local, remote, GenericUtils.of(options));
+ }
void upload(Path[] local, String remote, Collection<Option> options) throws IOException;
// NOTE: due to SCP command limitations, the amount of data to be uploaded must be known a-priori
// To upload a dynamic amount of data use SFTP
- void upload(byte[] data, String remote, Collection<PosixFilePermission> perms, ScpTimestamp time) throws IOException;
+ default void upload(byte[] data, String remote, Collection<PosixFilePermission> perms, ScpTimestamp time) throws IOException {
+ upload(data, 0, data.length, remote, perms, time);
+ }
- void upload(byte[] data, int offset, int len, String remote, Collection<PosixFilePermission> perms, ScpTimestamp time) throws IOException;
+ default void upload(byte[] data, int offset, int len, String remote, Collection<PosixFilePermission> perms, ScpTimestamp time) throws IOException {
+ try (InputStream local = new ByteArrayInputStream(data, offset, len)) {
+ upload(local, remote, len, perms, time);
+ }
+ }
void upload(InputStream local, String remote, long size, Collection<PosixFilePermission> perms, ScpTimestamp time) throws IOException;
+
+ static String createSendCommand(String remote, Collection<Option> options) {
+ StringBuilder sb = new StringBuilder(remote.length() + Long.SIZE).append(ScpHelper.SCP_COMMAND_PREFIX);
+ if (options.contains(Option.Recursive)) {
+ sb.append(" -r");
+ }
+ if (options.contains(Option.TargetIsDirectory)) {
+ sb.append(" -d");
+ }
+ if (options.contains(Option.PreserveAttributes)) {
+ sb.append(" -p");
+ }
+
+ sb.append(" -t").append(" --").append(" ").append(remote);
+ return sb.toString();
+ }
+
+ static String createReceiveCommand(String remote, Collection<Option> options) {
+ ValidateUtils.checkNotNullAndNotEmpty(remote, "No remote location specified");
+ StringBuilder sb = new StringBuilder(remote.length() + Long.SIZE).append(ScpHelper.SCP_COMMAND_PREFIX);
+ if (options.contains(Option.Recursive)) {
+ sb.append(" -r");
+ }
+ if (options.contains(Option.PreserveAttributes)) {
+ sb.append(" -p");
+ }
+
+ sb.append(" -f").append(" --").append(' ').append(remote);
+ return sb.toString();
+ }
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java b/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java
index 37fea18..b3199b2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClientCreator.java
@@ -35,7 +35,9 @@ public interface ScpClientCreator extends ScpFileOpenerHolder {
* @see #setScpFileOpener(ScpFileOpener)
* @see #setScpTransferEventListener(ScpTransferEventListener)
*/
- ScpClient createScpClient();
+ default ScpClient createScpClient() {
+ return createScpClient(getScpFileOpener(), getScpTransferEventListener());
+ }
/**
* Create an SCP client from this session.
@@ -46,7 +48,9 @@ public interface ScpClientCreator extends ScpFileOpenerHolder {
* is used <U>instead</U> of any listener set via {@link #setScpTransferEventListener(ScpTransferEventListener)}
* @return An {@link ScpClient} instance
*/
- ScpClient createScpClient(ScpTransferEventListener listener);
+ default ScpClient createScpClient(ScpTransferEventListener listener) {
+ return createScpClient(getScpFileOpener(), listener);
+ }
/**
* Create an SCP client from this session.
@@ -57,7 +61,9 @@ public interface ScpClientCreator extends ScpFileOpenerHolder {
* set via {@link #setScpFileOpener(ScpFileOpener)}
* @return An {@link ScpClient} instance
*/
- ScpClient createScpClient(ScpFileOpener opener);
+ default ScpClient createScpClient(ScpFileOpener opener) {
+ return createScpClient(opener, getScpTransferEventListener());
+ }
/**
* Create an SCP client from this session.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java b/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
index 9079b02..b7453f8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
@@ -322,34 +322,10 @@ public abstract class AbstractClientSession extends AbstractSession implements C
scpListener = listener;
}
- @Override // TODO make this a default method in JDK-8
- public ScpClient createScpClient() {
- return createScpClient(getScpFileOpener(), getScpTransferEventListener());
- }
-
- @Override // TODO make this a default method in JDK-8
- public ScpClient createScpClient(ScpTransferEventListener listener) {
- return createScpClient(getScpFileOpener(), listener);
- }
-
- @Override // TODO make this a default method in JDK-8
- public ScpClient createScpClient(ScpFileOpener opener) {
- return createScpClient(opener, getScpTransferEventListener());
- }
-
@Override
public ScpClient createScpClient(ScpFileOpener opener, ScpTransferEventListener listener) {
return new DefaultScpClient(this, opener, listener);
}
- @Override // TODO make this a default method in JDK-8
- public SftpClient createSftpClient() throws IOException {
- return createSftpClient(SftpVersionSelector.CURRENT);
- }
-
- @Override // TODO make this a default method in JDK-8
- public SftpClient createSftpClient(final int version) throws IOException {
- return createSftpClient(SftpVersionSelector.Utils.fixedVersionSelector(version));
- }
@Override
public SftpClient createSftpClient(SftpVersionSelector selector) throws IOException {
@@ -589,7 +565,7 @@ public abstract class AbstractClientSession extends AbstractSession implements C
} else {
log.info("switchToNoneCipher({}) switching", this);
- Map<KexProposalOption, String> proposal = new EnumMap<KexProposalOption, String>(KexProposalOption.class);
+ Map<KexProposalOption, String> proposal = new EnumMap<>(KexProposalOption.class);
synchronized (clientProposal) {
proposal.putAll(clientProposal);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionHolder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionHolder.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionHolder.java
index f4a3349..41072cf 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionHolder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionHolder.java
@@ -22,6 +22,7 @@ package org.apache.sshd.client.session;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface ClientSessionHolder {
/**
* @return The underlying {@link ClientSession} used
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java
index 6c20da3..4284dc2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java
@@ -65,91 +65,6 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
}
@Override
- public String getName() {
- return SftpConstants.SFTP_SUBSYSTEM_NAME;
- }
-
- @Override
- public CloseableHandle open(String path) throws IOException {
- return open(path, Collections.<OpenMode>emptySet());
- }
-
- @Override
- public CloseableHandle open(String path, OpenMode... options) throws IOException {
- return open(path, GenericUtils.of(options));
- }
-
- @Override
- public void rename(String oldPath, String newPath) throws IOException {
- rename(oldPath, newPath, Collections.<CopyMode>emptySet());
- }
-
- @Override
- public void rename(String oldPath, String newPath, CopyMode... options) throws IOException {
- rename(oldPath, newPath, GenericUtils.of(options));
- }
-
- @Override
- public InputStream read(String path) throws IOException {
- return read(path, DEFAULT_READ_BUFFER_SIZE);
- }
-
- @Override
- public InputStream read(String path, int bufferSize) throws IOException {
- return read(path, bufferSize, EnumSet.of(OpenMode.Read));
- }
-
- @Override
- public InputStream read(String path, OpenMode... mode) throws IOException {
- return read(path, DEFAULT_READ_BUFFER_SIZE, mode);
- }
-
- @Override
- public InputStream read(String path, int bufferSize, OpenMode... mode) throws IOException {
- return read(path, bufferSize, GenericUtils.of(mode));
- }
-
- @Override
- public InputStream read(String path, Collection<OpenMode> mode) throws IOException {
- return read(path, DEFAULT_READ_BUFFER_SIZE, mode);
- }
-
- @Override
- public OutputStream write(String path) throws IOException {
- return write(path, DEFAULT_WRITE_BUFFER_SIZE);
- }
-
- @Override
- public OutputStream write(String path, int bufferSize) throws IOException {
- return write(path, bufferSize, EnumSet.of(OpenMode.Write, OpenMode.Create, OpenMode.Truncate));
- }
-
- @Override
- public OutputStream write(String path, OpenMode... mode) throws IOException {
- return write(path, DEFAULT_WRITE_BUFFER_SIZE, mode);
- }
-
- @Override
- public OutputStream write(String path, Collection<OpenMode> mode) throws IOException {
- return write(path, DEFAULT_WRITE_BUFFER_SIZE, mode);
- }
-
- @Override
- public OutputStream write(String path, int bufferSize, OpenMode... mode) throws IOException {
- return write(path, bufferSize, GenericUtils.of(mode));
- }
-
- @Override
- public void write(Handle handle, long fileOffset, byte[] src) throws IOException {
- write(handle, fileOffset, src, 0, src.length);
- }
-
- @Override
- public void symLink(String linkPath, String targetPath) throws IOException {
- link(linkPath, targetPath, true);
- }
-
- @Override
public <E extends SftpClientExtension> E getExtension(Class<? extends E> extensionType) {
Object instance = getExtension(BuiltinSftpClientExtensions.fromType(extensionType));
if (instance == null) {
@@ -780,21 +695,6 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
checkCommandStatus(SftpConstants.SSH_FXP_RENAME, buffer);
}
- @Override // TODO make this a default method in Java 8
- public int read(Handle handle, long fileOffset, byte[] dst) throws IOException {
- return read(handle, fileOffset, dst, null);
- }
-
- @Override // TODO make this a default method in Java 8
- public int read(Handle handle, long fileOffset, byte[] dst, AtomicReference<Boolean> eofSignalled) throws IOException {
- return read(handle, fileOffset, dst, 0, dst.length, eofSignalled);
- }
-
- @Override // TODO make this a default method in Java 8
- public int read(Handle handle, long fileOffset, byte[] dst, int dstOffset, int len) throws IOException {
- return read(handle, fileOffset, dst, dstOffset, len, null);
- }
-
@Override
public int read(Handle handle, long fileOffset, byte[] dst, int dstOffset, int len, AtomicReference<Boolean> eofSignalled) throws IOException {
if (eofSignalled != null) {
@@ -959,11 +859,6 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
return handle;
}
- @Override // TODO in JDK-8 make this a default method
- public List<DirEntry> readDir(Handle handle) throws IOException {
- return readDir(handle, null);
- }
-
@Override
public List<DirEntry> readDir(Handle handle, AtomicReference<Boolean> eolIndicator) throws IOException {
if (eolIndicator != null) {
@@ -998,7 +893,7 @@ public abstract class AbstractSftpClient extends AbstractSubsystemClient impleme
log.debug("checkDirResponse({}}[id={}] reading {} entries", channel, id, len);
}
- List<DirEntry> entries = new ArrayList<DirEntry>(len);
+ List<DirEntry> entries = new ArrayList<>(len);
for (int i = 0; i < len; i++) {
String name = buffer.getString();
String longName = (version == SftpConstants.SFTP_V3) ? buffer.getString() : null;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultSftpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultSftpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultSftpClient.java
index f60aca3..103773f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultSftpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/DefaultSftpClient.java
@@ -61,7 +61,7 @@ public class DefaultSftpClient extends AbstractSftpClient {
private final Map<Integer, Buffer> messages = new HashMap<>();
private final AtomicInteger cmdId = new AtomicInteger(100);
private final Buffer receiveBuffer = new ByteArrayBuffer();
- private final byte[] workBuf = new byte[Integer.SIZE / Byte.SIZE]; // TODO in JDK-8 use Integer.BYTES
+ private final byte[] workBuf = new byte[Integer.BYTES];
private final AtomicInteger versionHolder = new AtomicInteger(0);
private final AtomicBoolean closing = new AtomicBoolean(false);
private final Map<String, byte[]> extensions = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
@@ -253,7 +253,7 @@ public class DefaultSftpClient extends AbstractSftpClient {
}
OutputStream dos = channel.getInvertedIn();
- BufferUtils.writeInt(dos, 1 /* cmd */ + (Integer.SIZE / Byte.SIZE) /* id */ + len, workBuf);
+ BufferUtils.writeInt(dos, 1 /* cmd */ + Integer.BYTES /* id */ + len, workBuf);
dos.write(cmd & 0xFF);
BufferUtils.writeInt(dos, id, workBuf);
dos.write(buffer.array(), buffer.rpos(), len);
@@ -288,13 +288,11 @@ public class DefaultSftpClient extends AbstractSftpClient {
InputStream dis = channel.getInvertedOut();
int length = BufferUtils.readInt(dis, workBuf);
// must have at least command + length
- // TODO in jdk-8 use Integer.BYTES
- if (length < (1 + (Integer.SIZE / Byte.SIZE))) {
+ if (length < (1 + Integer.BYTES)) {
throw new IllegalArgumentException("Bad length: " + length);
}
- // TODO in jdk-8 use Integer.BYTES
- Buffer buffer = new ByteArrayBuffer(length + (Integer.SIZE / Byte.SIZE), false);
+ Buffer buffer = new ByteArrayBuffer(length + Integer.BYTES, false);
buffer.putInt(length);
int nb = length;
while (nb > 0) {
@@ -441,8 +439,8 @@ public class DefaultSftpClient extends AbstractSftpClient {
}
String verVal = String.valueOf(selected);
- Buffer buffer = new ByteArrayBuffer((Integer.SIZE / Byte.SIZE) + SftpConstants.EXT_VERSION_SELECT.length() // extension name
- + (Integer.SIZE / Byte.SIZE) + verVal.length() + Byte.SIZE, false);
+ Buffer buffer = new ByteArrayBuffer(Integer.BYTES + SftpConstants.EXT_VERSION_SELECT.length() // extension name
+ + Integer.BYTES + verVal.length() + Byte.SIZE, false);
buffer.putString(SftpConstants.EXT_VERSION_SELECT);
buffer.putString(verVal);
checkCommandStatus(SftpConstants.SSH_FXP_EXTENDED, buffer);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClient.java
index 3669882..1673ebb 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClient.java
@@ -48,7 +48,6 @@ import org.bouncycastle.util.Arrays;
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public interface SftpClient extends SubsystemClient {
-
enum OpenMode {
Read,
Write,
@@ -437,6 +436,10 @@ public interface SftpClient extends SubsystemClient {
*/
int getVersion();
+ @Override
+ default String getName() {
+ return SftpConstants.SFTP_SUBSYSTEM_NAME;
+ }
/**
* @return An (unmodifiable) {@link Map} of the reported server extensions.
*/
@@ -454,8 +457,11 @@ public interface SftpClient extends SubsystemClient {
* @param path The remote path
* @return The file's {@link CloseableHandle}
* @throws IOException If failed to open the remote file
+ * @see #open(String, Collection)
*/
- CloseableHandle open(String path) throws IOException;
+ default CloseableHandle open(String path) throws IOException {
+ return open(path, Collections.<OpenMode>emptySet());
+ }
/**
* Opens a remote file with the specified mode(s)
@@ -465,8 +471,11 @@ public interface SftpClient extends SubsystemClient {
* then {@link OpenMode#Read} is assumed
* @return The file's {@link CloseableHandle}
* @throws IOException If failed to open the remote file
+ * @see #open(String, Collection)
*/
- CloseableHandle open(String path, OpenMode... options) throws IOException;
+ default CloseableHandle open(String path, OpenMode... options) throws IOException {
+ return open(path, GenericUtils.of(options));
+ }
/**
* Opens a remote file with the specified mode(s)
@@ -493,9 +502,13 @@ public interface SftpClient extends SubsystemClient {
*/
void remove(String path) throws IOException;
- void rename(String oldPath, String newPath) throws IOException;
+ default void rename(String oldPath, String newPath) throws IOException {
+ rename(oldPath, newPath, Collections.<CopyMode>emptySet());
+ }
- void rename(String oldPath, String newPath, CopyMode... options) throws IOException;
+ default void rename(String oldPath, String newPath, CopyMode... options) throws IOException {
+ rename(oldPath, newPath, GenericUtils.of(options));
+ }
void rename(String oldPath, String newPath, Collection<CopyMode> options) throws IOException;
@@ -509,7 +522,9 @@ public interface SftpClient extends SubsystemClient {
* @throws IOException If failed to read the data
* @see #read(Handle, long, byte[], int, int)
*/
- int read(Handle handle, long fileOffset, byte[] dst) throws IOException;
+ default int read(Handle handle, long fileOffset, byte[] dst) throws IOException {
+ return read(handle, fileOffset, dst, null);
+ }
/**
* Reads data from the open (file) handle
@@ -525,9 +540,13 @@ public interface SftpClient extends SubsystemClient {
* @see #read(Handle, long, byte[], int, int, AtomicReference)
* @see <A HREF="https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-9.3">SFTP v6 - section 9.3</A>
*/
- int read(Handle handle, long fileOffset, byte[] dst, AtomicReference<Boolean> eofSignalled) throws IOException;
+ default int read(Handle handle, long fileOffset, byte[] dst, AtomicReference<Boolean> eofSignalled) throws IOException {
+ return read(handle, fileOffset, dst, 0, dst.length, eofSignalled);
+ }
- int read(Handle handle, long fileOffset, byte[] dst, int dstOffset, int len) throws IOException;
+ default int read(Handle handle, long fileOffset, byte[] dst, int dstOffset, int len) throws IOException {
+ return read(handle, fileOffset, dst, dstOffset, len, null);
+ }
/**
* Reads data from the open (file) handle
@@ -546,7 +565,9 @@ public interface SftpClient extends SubsystemClient {
*/
int read(Handle handle, long fileOffset, byte[] dst, int dstOffset, int len, AtomicReference<Boolean> eofSignalled) throws IOException;
- void write(Handle handle, long fileOffset, byte[] src) throws IOException;
+ default void write(Handle handle, long fileOffset, byte[] src) throws IOException {
+ write(handle, fileOffset, src, 0, src.length);
+ }
/**
* Write data to (open) file handle
@@ -595,7 +616,9 @@ public interface SftpClient extends SubsystemClient {
* {@link #readDir(String)}
* @throws IOException If failed to access the remote site
*/
- List<DirEntry> readDir(Handle handle) throws IOException;
+ default List<DirEntry> readDir(Handle handle) throws IOException {
+ return readDir(handle, null);
+ }
/**
* @param handle Directory {@link Handle} to read from
@@ -681,8 +704,11 @@ public interface SftpClient extends SubsystemClient {
* @param linkPath The link location
* @param targetPath The referenced target by the link
* @throws IOException If failed to execute
+ * @see #link(String, String, boolean)
*/
- void symLink(String linkPath, String targetPath) throws IOException;
+ default void symLink(String linkPath, String targetPath) throws IOException {
+ link(linkPath, targetPath, true);
+ }
/**
* Create a link
@@ -711,15 +737,25 @@ public interface SftpClient extends SubsystemClient {
*/
Iterable<DirEntry> readDir(String path) throws IOException;
- InputStream read(String path) throws IOException;
+ default InputStream read(String path) throws IOException {
+ return read(path, DEFAULT_READ_BUFFER_SIZE);
+ }
- InputStream read(String path, int bufferSize) throws IOException;
+ default InputStream read(String path, int bufferSize) throws IOException {
+ return read(path, bufferSize, EnumSet.of(OpenMode.Read));
+ }
- InputStream read(String path, OpenMode... mode) throws IOException;
+ default InputStream read(String path, OpenMode... mode) throws IOException {
+ return read(path, DEFAULT_READ_BUFFER_SIZE, mode);
+ }
- InputStream read(String path, int bufferSize, OpenMode... mode) throws IOException;
+ default InputStream read(String path, int bufferSize, OpenMode... mode) throws IOException {
+ return read(path, bufferSize, GenericUtils.of(mode));
+ }
- InputStream read(String path, Collection<OpenMode> mode) throws IOException;
+ default InputStream read(String path, Collection<OpenMode> mode) throws IOException {
+ return read(path, DEFAULT_READ_BUFFER_SIZE, mode);
+ }
/**
* Read a remote file's data via an input stream
@@ -732,15 +768,25 @@ public interface SftpClient extends SubsystemClient {
*/
InputStream read(String path, int bufferSize, Collection<OpenMode> mode) throws IOException;
- OutputStream write(String path) throws IOException;
+ default OutputStream write(String path) throws IOException {
+ return write(path, DEFAULT_WRITE_BUFFER_SIZE);
+ }
- OutputStream write(String path, int bufferSize) throws IOException;
+ default OutputStream write(String path, int bufferSize) throws IOException {
+ return write(path, bufferSize, EnumSet.of(OpenMode.Write, OpenMode.Create, OpenMode.Truncate));
+ }
- OutputStream write(String path, OpenMode... mode) throws IOException;
+ default OutputStream write(String path, OpenMode... mode) throws IOException {
+ return write(path, DEFAULT_WRITE_BUFFER_SIZE, mode);
+ }
- OutputStream write(String path, int bufferSize, OpenMode... mode) throws IOException;
+ default OutputStream write(String path, int bufferSize, OpenMode... mode) throws IOException {
+ return write(path, bufferSize, GenericUtils.of(mode));
+ }
- OutputStream write(String path, Collection<OpenMode> mode) throws IOException;
+ default OutputStream write(String path, Collection<OpenMode> mode) throws IOException {
+ return write(path, DEFAULT_WRITE_BUFFER_SIZE, mode);
+ }
/**
* Write to a remote file via an output stream
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClientCreator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClientCreator.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClientCreator.java
index 09b0843..2f93c90 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClientCreator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClientCreator.java
@@ -32,7 +32,9 @@ public interface SftpClientCreator {
* @return The created {@link SftpClient}
* @throws IOException if failed to create the client
*/
- SftpClient createSftpClient() throws IOException;
+ default SftpClient createSftpClient() throws IOException {
+ return createSftpClient(SftpVersionSelector.CURRENT);
+ }
/**
* Creates an SFTP client using the specified version
@@ -43,7 +45,9 @@ public interface SftpClientCreator {
* @return The created {@link SftpClient}
* @throws IOException If failed to create the client or use the specified version
*/
- SftpClient createSftpClient(int version) throws IOException;
+ default SftpClient createSftpClient(int version) throws IOException {
+ return createSftpClient(SftpVersionSelector.Utils.fixedVersionSelector(version));
+ }
/**
* Creates an SFTP client while allowing the selection of a specific version
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/BuiltinSftpClientExtensions.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/BuiltinSftpClientExtensions.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/BuiltinSftpClientExtensions.java
index c95d8fd..dda5e00 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/BuiltinSftpClientExtensions.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/BuiltinSftpClientExtensions.java
@@ -132,12 +132,6 @@ public enum BuiltinSftpClientExtensions implements SftpClientExtensionFactory {
return type;
}
- @Override
- public SftpClientExtension create(SftpClient client, RawSftpClient raw) {
- Map<String, byte[]> extensions = client.getServerExtensions();
- return create(client, raw, extensions, ParserUtils.parse(extensions));
- }
-
public static BuiltinSftpClientExtensions fromName(String n) {
return NamedResource.Utils.findByName(n, String.CASE_INSENSITIVE_ORDER, VALUES);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SftpClientExtensionFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SftpClientExtensionFactory.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SftpClientExtensionFactory.java
index f9257e6..0692a04 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SftpClientExtensionFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/SftpClientExtensionFactory.java
@@ -24,13 +24,16 @@ import java.util.Map;
import org.apache.sshd.client.subsystem.sftp.RawSftpClient;
import org.apache.sshd.client.subsystem.sftp.SftpClient;
import org.apache.sshd.common.NamedResource;
+import org.apache.sshd.common.subsystem.sftp.extensions.ParserUtils;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public interface SftpClientExtensionFactory extends NamedResource {
- // TODO make this a default method for JDK-8
- SftpClientExtension create(SftpClient client, RawSftpClient raw);
+ default SftpClientExtension create(SftpClient client, RawSftpClient raw) {
+ Map<String, byte[]> extensions = client.getServerExtensions();
+ return create(client, raw, extensions, ParserUtils.parse(extensions));
+ }
SftpClientExtension create(SftpClient client, RawSftpClient raw, Map<String, byte[]> extensions, Map<String, ?> parsed);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtension.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtension.java
index 62654dd..ee163e2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtension.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtension.java
@@ -39,7 +39,7 @@ public abstract class AbstractMD5HashExtension extends AbstractSftpClientExtensi
}
protected byte[] doGetHash(Object target, long offset, long length, byte[] quickHash) throws IOException {
- Buffer buffer = getCommandBuffer(target, Long.SIZE + 2 * (Long.SIZE / Byte.SIZE) + (Integer.SIZE / Byte.SIZE) + NumberUtils.length(quickHash));
+ Buffer buffer = getCommandBuffer(target, Long.SIZE + 2 * Long.BYTES + Integer.BYTES + NumberUtils.length(quickHash));
String opcode = getName();
putTarget(buffer, target);
buffer.putLong(offset);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractSftpClientExtension.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractSftpClientExtension.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractSftpClientExtension.java
index 95697e7..46a1235 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractSftpClientExtension.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractSftpClientExtension.java
@@ -145,11 +145,11 @@ public abstract class AbstractSftpClientExtension extends AbstractLoggingBean im
*/
protected Buffer getCommandBuffer(Object target, int extraSize) {
if (target instanceof CharSequence) {
- return getCommandBuffer((Integer.SIZE / Byte.SIZE) + ((CharSequence) target).length() + extraSize);
+ return getCommandBuffer(Integer.BYTES + ((CharSequence) target).length() + extraSize);
} else if (target instanceof byte[]) {
- return getCommandBuffer((Integer.SIZE / Byte.SIZE) + ((byte[]) target).length + extraSize);
+ return getCommandBuffer(Integer.BYTES + ((byte[]) target).length + extraSize);
} else if (target instanceof Handle) {
- return getCommandBuffer((Integer.SIZE / Byte.SIZE) + ((Handle) target).length() + extraSize);
+ return getCommandBuffer(Integer.BYTES + ((Handle) target).length() + extraSize);
} else {
return getCommandBuffer(extraSize);
}
@@ -161,7 +161,7 @@ public abstract class AbstractSftpClientExtension extends AbstractLoggingBean im
*/
protected Buffer getCommandBuffer(int extraSize) {
String opcode = getName();
- Buffer buffer = new ByteArrayBuffer((Integer.SIZE / Byte.SIZE) + GenericUtils.length(opcode) + extraSize + Byte.SIZE, false);
+ Buffer buffer = new ByteArrayBuffer(Integer.BYTES + GenericUtils.length(opcode) + extraSize + Byte.SIZE, false);
buffer.putString(opcode);
return buffer;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyDataExtensionImpl.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyDataExtensionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyDataExtensionImpl.java
index ac75a09..c56129f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyDataExtensionImpl.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyDataExtensionImpl.java
@@ -42,9 +42,9 @@ public class CopyDataExtensionImpl extends AbstractSftpClientExtension implement
public void copyData(Handle readHandle, long readOffset, long readLength, Handle writeHandle, long writeOffset) throws IOException {
byte[] srcId = readHandle.getIdentifier();
byte[] dstId = writeHandle.getIdentifier();
- Buffer buffer = getCommandBuffer((Integer.SIZE / Byte.SIZE) + NumberUtils.length(srcId)
- + (Integer.SIZE / Byte.SIZE) + NumberUtils.length(dstId)
- + (3 * (Long.SIZE + (Integer.SIZE / Byte.SIZE))));
+ Buffer buffer = getCommandBuffer(Integer.BYTES + NumberUtils.length(srcId)
+ + Integer.BYTES + NumberUtils.length(dstId)
+ + (3 * (Long.SIZE + Integer.BYTES)));
buffer.putBytes(srcId);
buffer.putLong(readOffset);
buffer.putLong(readLength);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyFileExtensionImpl.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyFileExtensionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyFileExtensionImpl.java
index bb32bb7..5ce5f9a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyFileExtensionImpl.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyFileExtensionImpl.java
@@ -39,8 +39,8 @@ public class CopyFileExtensionImpl extends AbstractSftpClientExtension implement
@Override
public void copyFile(String src, String dst, boolean overwriteDestination) throws IOException {
- Buffer buffer = getCommandBuffer((Integer.SIZE / Byte.SIZE) + GenericUtils.length(src)
- + (Integer.SIZE / Byte.SIZE) + GenericUtils.length(dst)
+ Buffer buffer = getCommandBuffer(Integer.BYTES + GenericUtils.length(src)
+ + Integer.BYTES + GenericUtils.length(dst)
+ 1 /* override destination */);
buffer.putString(src);
buffer.putString(dst);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/helpers/OpenSSHFsyncExtensionImpl.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/helpers/OpenSSHFsyncExtensionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/helpers/OpenSSHFsyncExtensionImpl.java
index cafb600..e83ea11 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/helpers/OpenSSHFsyncExtensionImpl.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/helpers/OpenSSHFsyncExtensionImpl.java
@@ -42,7 +42,7 @@ public class OpenSSHFsyncExtensionImpl extends AbstractSftpClientExtension imple
@Override
public void fsync(Handle fileHandle) throws IOException {
byte[] handle = fileHandle.getIdentifier();
- Buffer buffer = getCommandBuffer((Integer.SIZE / Byte.SIZE) + NumberUtils.length(handle));
+ Buffer buffer = getCommandBuffer(Integer.BYTES + NumberUtils.length(handle));
buffer.putBytes(handle);
sendAndCheckExtendedCommandStatus(buffer);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/Factory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/Factory.java b/sshd-core/src/main/java/org/apache/sshd/common/Factory.java
index 37d1a96..406eb5e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/Factory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/Factory.java
@@ -25,6 +25,7 @@ package org.apache.sshd.common;
* @param <T> type of objets this factory will create
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface Factory<T> {
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/FactoryManagerHolder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/FactoryManagerHolder.java b/sshd-core/src/main/java/org/apache/sshd/common/FactoryManagerHolder.java
index 810ac09..9b2f938 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/FactoryManagerHolder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/FactoryManagerHolder.java
@@ -22,6 +22,7 @@ package org.apache.sshd.common;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface FactoryManagerHolder {
/**
* @return The currently associated {@link FactoryManager}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/NamedResource.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/NamedResource.java b/sshd-core/src/main/java/org/apache/sshd/common/NamedResource.java
index 9427201..87b1e63 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/NamedResource.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/NamedResource.java
@@ -31,6 +31,7 @@ import org.apache.sshd.common.util.Transformer;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface NamedResource {
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/OptionalFeature.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/OptionalFeature.java b/sshd-core/src/main/java/org/apache/sshd/common/OptionalFeature.java
index 43497eb..54ec1b4 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/OptionalFeature.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/OptionalFeature.java
@@ -26,7 +26,8 @@ import org.apache.sshd.common.util.GenericUtils;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public interface OptionalFeature { // TODO define this as a @FunctionalInterface in Java 8
+@FunctionalInterface
+public interface OptionalFeature {
OptionalFeature TRUE = new OptionalFeature() {
@Override
public boolean isSupported() {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/SshConstants.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/SshConstants.java b/sshd-core/src/main/java/org/apache/sshd/common/SshConstants.java
index af46ab7..919ba40 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/SshConstants.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/SshConstants.java
@@ -23,9 +23,9 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.function.Predicate;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Predicate;
import org.apache.sshd.common.util.logging.LoggingUtils;
/**
@@ -130,7 +130,7 @@ public final class SshConstants {
private static class LazyAmbiguousOpcodesHolder {
private static final Set<Integer> AMBIGUOUS_OPCODES =
Collections.unmodifiableSet(
- new HashSet<Integer>(
+ new HashSet<>(
LoggingUtils.getAmbiguousMenmonics(SshConstants.class, "SSH_MSG_").values()));
}
@@ -155,7 +155,7 @@ public final class SshConstants {
private static final Map<Integer, String> MESSAGES_MAP =
LoggingUtils.generateMnemonicMap(SshConstants.class, new Predicate<Field>() {
@Override
- public boolean evaluate(Field f) {
+ public boolean test(Field f) {
String name = f.getName();
if (!name.startsWith("SSH_MSG_")) {
return false;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
index f6f5ddf..c99f6f3 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
@@ -332,7 +332,7 @@ public abstract class AbstractChannel
? SshConstants.SSH_MSG_CHANNEL_SUCCESS
: SshConstants.SSH_MSG_CHANNEL_FAILURE;
Session session = getSession();
- Buffer rsp = session.createBuffer(cmd, Integer.SIZE / Byte.SIZE);
+ Buffer rsp = session.createBuffer(cmd, Integer.BYTES);
rsp.putInt(recipient);
return session.writePacket(rsp);
}
@@ -664,7 +664,7 @@ public abstract class AbstractChannel
log.debug("handleExtendedData({}) SSH_MSG_CHANNEL_FAILURE - non STDERR type: {}", this, ex);
}
Session s = getSession();
- Buffer rsp = s.createBuffer(SshConstants.SSH_MSG_CHANNEL_FAILURE, Integer.SIZE / Byte.SIZE);
+ Buffer rsp = s.createBuffer(SshConstants.SSH_MSG_CHANNEL_FAILURE, Integer.BYTES);
rsp.putInt(getRecipient());
writePacket(rsp);
return;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncInputStream.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncInputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncInputStream.java
index 75ca78d..1e2a751 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncInputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncInputStream.java
@@ -146,7 +146,7 @@ public class ChannelAsyncInputStream extends AbstractCloseable implements IoInpu
return buffer;
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public IoReadFuture verify(long timeoutMillis) throws IOException {
long startTime = System.nanoTime();
Number result = verifyResult(Number.class, timeoutMillis);
@@ -158,7 +158,7 @@ public class ChannelAsyncInputStream extends AbstractCloseable implements IoInpu
return this;
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public int getRead() {
Object v = getValue();
if (v instanceof RuntimeException) {
@@ -174,7 +174,7 @@ public class ChannelAsyncInputStream extends AbstractCloseable implements IoInpu
}
}
- @Override // TODO for JDK-8 make this a default method
+ @Override
public Throwable getException() {
Object v = getValue();
if (v instanceof Throwable) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelHolder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelHolder.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelHolder.java
index 869dc9c..0016503 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelHolder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelHolder.java
@@ -22,6 +22,7 @@ package org.apache.sshd.common.channel;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface ChannelHolder {
/**
* @return The associated {@link Channel} instance
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/25bc715a/sshd-core/src/main/java/org/apache/sshd/common/channel/RequestHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/RequestHandler.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/RequestHandler.java
index 7883e7b..d7e796f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/RequestHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/RequestHandler.java
@@ -31,6 +31,7 @@ import org.apache.sshd.common.util.buffer.Buffer;
* @param <T> Request type
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+@FunctionalInterface
public interface RequestHandler<T> {
enum Result {
@@ -75,5 +76,4 @@ public interface RequestHandler<T> {
* value should be returned
*/
Result process(T t, String request, boolean wantReply, Buffer buffer) throws Exception;
-
}
[3/3] mina-sshd git commit: [SSHD-687] Provide indication of the
negotiated options before processing them
Posted by lg...@apache.org.
[SSHD-687] Provide indication of the negotiated options before processing them
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/997ae449
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/997ae449
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/997ae449
Branch: refs/heads/master
Commit: 997ae449f36fb90dd1e055b28decf4f089332646
Parents: 25bc715
Author: Lyor Goldstein <ly...@gmail.com>
Authored: Thu Aug 4 20:07:59 2016 +0300
Committer: Lyor Goldstein <ly...@gmail.com>
Committed: Thu Aug 4 20:07:59 2016 +0300
----------------------------------------------------------------------
.../java/org/apache/sshd/client/SshKeyScan.java | 17 +++
.../client/auth/keyboard/UserInteraction.java | 18 +--
.../sshd/common/channel/ChannelListener.java | 27 +++-
.../forward/PortForwardingEventListener.java | 48 +++++--
.../common/scp/ScpTransferEventListener.java | 40 +++---
.../sshd/common/session/SessionListener.java | 49 ++++++-
.../common/session/helpers/AbstractSession.java | 70 +++++-----
.../subsystem/sftp/SftpEventListener.java | 128 +++++++++++++------
.../java/org/apache/sshd/KeyReExchangeTest.java | 45 -------
.../client/ClientAuthenticationManagerTest.java | 76 +----------
.../sshd/client/ClientSessionListenerTest.java | 30 -----
.../java/org/apache/sshd/client/ClientTest.java | 10 --
.../client/simple/SimpleSessionClientTest.java | 15 ---
.../sshd/common/auth/AuthenticationTest.java | 55 --------
.../common/compression/CompressionTest.java | 15 ---
.../ReservedSessionMessagesHandlerTest.java | 15 ---
.../sshd/server/ServerProxyAcceptorTest.java | 10 --
.../sshd/server/ServerSessionListenerTest.java | 37 +-----
.../java/org/apache/sshd/server/ServerTest.java | 67 +---------
19 files changed, 272 insertions(+), 500 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/main/java/org/apache/sshd/client/SshKeyScan.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SshKeyScan.java b/sshd-core/src/main/java/org/apache/sshd/client/SshKeyScan.java
index 2d85c4a..dfd8977 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/SshKeyScan.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/SshKeyScan.java
@@ -360,6 +360,23 @@ public class SshKeyScan extends AbstractSimplifiedLog
logSessionEvent(session, "Closed");
}
+ @Override
+ public void sessionNegotiationStart(
+ Session session, Map<KexProposalOption, String> clientProposal, Map<KexProposalOption, String> serverProposal) {
+ logSessionEvent(session, "sessionNegotiationStart");
+ }
+
+ @Override
+ public void sessionNegotiationEnd(Session session, Map<KexProposalOption, String> clientProposal,
+ Map<KexProposalOption, String> serverProposal, Map<KexProposalOption, String> negotiatedOptions,
+ Throwable reason) {
+ if (reason == null) {
+ logSessionEvent(session, "sessionNegotiationStart");
+ } else {
+ logSessionEvent(session, reason);
+ }
+ }
+
protected void logSessionEvent(Session session, Object event) {
if (isEnabled(Level.FINEST)) {
IoSession ioSession = session.getIoSession();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/main/java/org/apache/sshd/client/auth/keyboard/UserInteraction.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/keyboard/UserInteraction.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/keyboard/UserInteraction.java
index 973bce4..a641243 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/keyboard/UserInteraction.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/keyboard/UserInteraction.java
@@ -41,16 +41,6 @@ public interface UserInteraction {
}
@Override
- public void serverVersionInfo(ClientSession session, List<String> lines) {
- // ignored
- }
-
- @Override
- public void welcome(ClientSession session, String banner, String lang) {
- // ignored
- }
-
- @Override
public String[] interactive(ClientSession session, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
throw new IllegalStateException("interactive(" + session + ")[" + name + "] unexpected call");
}
@@ -82,7 +72,9 @@ public interface UserInteraction {
* @param lines The sent extra lines - <U>without</U> the server version
* @see <A HREF="https://tools.ietf.org/html/rfc4253#section-4.2">RFC 4253 - section 4.2</A>
*/
- void serverVersionInfo(ClientSession session, List<String> lines);
+ default void serverVersionInfo(ClientSession session, List<String> lines) {
+ // do nothing
+ }
/**
* Displays the welcome banner to the user.
@@ -91,7 +83,9 @@ public interface UserInteraction {
* @param banner The welcome banner
* @param lang The banner language code - may be empty
*/
- void welcome(ClientSession session, String banner, String lang);
+ default void welcome(ClientSession session, String banner, String lang) {
+ // do nothing
+ }
/**
* Invoked when "keyboard-interactive" authentication mechanism
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelListener.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelListener.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelListener.java
index e965487..20eb29d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelListener.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelListener.java
@@ -30,6 +30,13 @@ import java.util.EventListener;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public interface ChannelListener extends EventListener {
+ ChannelListener EMPTY = new ChannelListener() {
+ @Override
+ public String toString() {
+ return "EMPTY";
+ }
+ };
+
/**
* Called to inform about initial setup of a channel via the
* {@link Channel#init(org.apache.sshd.common.session.ConnectionService, org.apache.sshd.common.session.Session, int)}
@@ -39,7 +46,9 @@ public interface ChannelListener extends EventListener {
*
* @param channel The initialized {@link Channel}
*/
- void channelInitialized(Channel channel);
+ default void channelInitialized(Channel channel) {
+ // ignored
+ }
/**
* Called to inform about a channel being successfully opened for a
@@ -48,7 +57,9 @@ public interface ChannelListener extends EventListener {
*
* @param channel The newly opened {@link Channel}
*/
- void channelOpenSuccess(Channel channel);
+ default void channelOpenSuccess(Channel channel) {
+ // ignored
+ }
/**
* Called to inform about the failure to open a channel
@@ -58,7 +69,9 @@ public interface ChannelListener extends EventListener {
* {@link #channelOpenSuccess(Channel)} notification throws an exception
* it will cause this method to be invoked
*/
- void channelOpenFailure(Channel channel, Throwable reason);
+ default void channelOpenFailure(Channel channel, Throwable reason) {
+ // ignored
+ }
/**
* Called to inform that the channel state may have changed - e.g.,
@@ -68,7 +81,9 @@ public interface ChannelListener extends EventListener {
* @param hint A "hint" as to the nature of the state change.
* it can be a request name or a {@code SSH_MSG_CHANNEL_XXX} command
*/
- void channelStateChanged(Channel channel, String hint);
+ default void channelStateChanged(Channel channel, String hint) {
+ // ignored
+ }
/**
* Called to inform about a channel being closed. <B>Note:</B> when the call
@@ -82,5 +97,7 @@ public interface ChannelListener extends EventListener {
* @param reason The reason why the channel is being closed - if {@code null}
* then normal closure
*/
- void channelClosed(Channel channel, Throwable reason);
+ default void channelClosed(Channel channel, Throwable reason) {
+ // ignored
+ }
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/main/java/org/apache/sshd/common/forward/PortForwardingEventListener.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/PortForwardingEventListener.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/PortForwardingEventListener.java
index d03dbd9..25211bb 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/PortForwardingEventListener.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/PortForwardingEventListener.java
@@ -29,6 +29,13 @@ import org.apache.sshd.common.util.net.SshdSocketAddress;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public interface PortForwardingEventListener extends EventListener {
+ PortForwardingEventListener EMPTY = new PortForwardingEventListener() {
+ @Override
+ public String toString() {
+ return "EMPTY";
+ }
+ };
+
/**
* Signals the attempt to establish a local/remote port forwarding
*
@@ -39,9 +46,11 @@ public interface PortForwardingEventListener extends EventListener {
* @throws IOException If failed to handle the event - in which case
* the attempt is aborted and the exception re-thrown to the caller
*/
- void establishingExplicitTunnel(
+ default void establishingExplicitTunnel(
Session session, SshdSocketAddress local, SshdSocketAddress remote, boolean localForwarding)
- throws IOException;
+ throws IOException {
+ // ignored
+ }
/**
* Signals a successful/failed attempt to establish a local/remote port forwarding
@@ -55,10 +64,12 @@ public interface PortForwardingEventListener extends EventListener {
* @throws IOException If failed to handle the event - in which case
* the established tunnel is aborted
*/
- void establishedExplicitTunnel(
+ default void establishedExplicitTunnel(
Session session, SshdSocketAddress local, SshdSocketAddress remote, boolean localForwarding,
SshdSocketAddress boundAddress, Throwable reason)
- throws IOException;
+ throws IOException {
+ // ignored
+ }
/**
* Signals a request to tear down a local/remote port forwarding
@@ -69,7 +80,10 @@ public interface PortForwardingEventListener extends EventListener {
* @throws IOException If failed to handle the event - in which case
* the request is aborted
*/
- void tearingDownExplicitTunnel(Session session, SshdSocketAddress address, boolean localForwarding) throws IOException;
+ default void tearingDownExplicitTunnel(Session session, SshdSocketAddress address, boolean localForwarding)
+ throws IOException {
+ // ignored
+ }
/**
* Signals a successful/failed request to tear down a local/remote port forwarding
@@ -82,7 +96,10 @@ public interface PortForwardingEventListener extends EventListener {
* the exception is propagated, but the port forwarding may have
* been torn down - no rollback
*/
- void tornDownExplicitTunnel(Session session, SshdSocketAddress address, boolean localForwarding, Throwable reason) throws IOException;
+ default void tornDownExplicitTunnel(Session session, SshdSocketAddress address, boolean localForwarding, Throwable reason)
+ throws IOException {
+ // ignored
+ }
/**
* Signals the attempt to establish a dynamic port forwarding
@@ -92,7 +109,9 @@ public interface PortForwardingEventListener extends EventListener {
* @throws IOException If failed to handle the event - in which case
* the attempt is aborted and the exception re-thrown to the caller
*/
- void establishingDynamicTunnel(Session session, SshdSocketAddress local) throws IOException;
+ default void establishingDynamicTunnel(Session session, SshdSocketAddress local) throws IOException {
+ // ignored
+ }
/**
* Signals a successful/failed attempt to establish a dynamic port forwarding
@@ -104,9 +123,11 @@ public interface PortForwardingEventListener extends EventListener {
* @throws IOException If failed to handle the event - in which case
* the established tunnel is aborted
*/
- void establishedDynamicTunnel(
+ default void establishedDynamicTunnel(
Session session, SshdSocketAddress local, SshdSocketAddress boundAddress, Throwable reason)
- throws IOException;
+ throws IOException {
+ // ignored
+ }
/**
* Signals a request to tear down a dynamic forwarding
@@ -116,7 +137,9 @@ public interface PortForwardingEventListener extends EventListener {
* @throws IOException If failed to handle the event - in which case
* the request is aborted
*/
- void tearingDownDynamicTunnel(Session session, SshdSocketAddress address) throws IOException;
+ default void tearingDownDynamicTunnel(Session session, SshdSocketAddress address) throws IOException {
+ // ignored
+ }
/**
* Signals a successful/failed request to tear down a dynamic port forwarding
@@ -128,6 +151,7 @@ public interface PortForwardingEventListener extends EventListener {
* the exception is propagated, but the port forwarding may have
* been torn down - no rollback
*/
- void tornDownDynamicTunnel(Session session, SshdSocketAddress address, Throwable reason) throws IOException;
-
+ default void tornDownDynamicTunnel(Session session, SshdSocketAddress address, Throwable reason) throws IOException {
+ // ignored
+ }
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpTransferEventListener.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpTransferEventListener.java b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpTransferEventListener.java
index ebe2787..95380cd 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpTransferEventListener.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpTransferEventListener.java
@@ -31,7 +31,6 @@ import java.util.Set;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public interface ScpTransferEventListener extends EventListener {
-
enum FileOperation {
SEND,
RECEIVE
@@ -41,26 +40,9 @@ public interface ScpTransferEventListener extends EventListener {
* An "empty" implementation to be used instead of {@code null}s
*/
ScpTransferEventListener EMPTY = new ScpTransferEventListener() {
- // TODO in JDK 8.0 implement all methods as default with empty body in the interface itself
-
- @Override
- public void startFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms) {
- // ignored
- }
-
- @Override
- public void endFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms, Throwable thrown) {
- // ignored
- }
-
@Override
- public void startFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms) {
- // ignored
- }
-
- @Override
- public void endFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms, Throwable thrown) {
- // ignored
+ public String toString() {
+ return "EMPTY";
}
};
@@ -72,7 +54,9 @@ public interface ScpTransferEventListener extends EventListener {
* once transfer is complete
* @throws IOException If failed to handle the event
*/
- void startFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms) throws IOException;
+ default void startFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms) throws IOException {
+ // ignored
+ }
/**
* @param op The {@link FileOperation}
@@ -84,7 +68,10 @@ public interface ScpTransferEventListener extends EventListener {
* reception was successful
* @throws IOException If failed to handle the event
*/
- void endFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms, Throwable thrown) throws IOException;
+ default void endFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms, Throwable thrown)
+ throws IOException {
+ // ignored
+ }
/**
* @param op The {@link FileOperation}
@@ -93,7 +80,9 @@ public interface ScpTransferEventListener extends EventListener {
* once transfer is complete
* @throws IOException If failed to handle the event
*/
- void startFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms) throws IOException;
+ default void startFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms) throws IOException {
+ // ignored
+ }
/**
* @param op The {@link FileOperation}
@@ -104,5 +93,8 @@ public interface ScpTransferEventListener extends EventListener {
* reception was successful
* @throws IOException If failed to handle the event
*/
- void endFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms, Throwable thrown) throws IOException;
+ default void endFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms, Throwable thrown)
+ throws IOException {
+ // ignored
+ }
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/main/java/org/apache/sshd/common/session/SessionListener.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/SessionListener.java b/sshd-core/src/main/java/org/apache/sshd/common/session/SessionListener.java
index 3a6fe18..e4267dc 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/SessionListener.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/SessionListener.java
@@ -19,6 +19,9 @@
package org.apache.sshd.common.session;
import java.util.EventListener;
+import java.util.Map;
+
+import org.apache.sshd.common.kex.KexProposalOption;
/**
* Represents an interface receiving session events.
@@ -26,7 +29,6 @@ import java.util.EventListener;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public interface SessionListener extends EventListener {
-
enum Event {
KeyEstablished, Authenticated, KexCompleted
}
@@ -36,7 +38,37 @@ public interface SessionListener extends EventListener {
*
* @param session The created {@link Session}
*/
- void sessionCreated(Session session);
+ default void sessionCreated(Session session) {
+ // ignored
+ }
+
+ /**
+ * Signals the start of the negotiation options handling
+ *
+ * @param session The referenced {@link Session}
+ * @param clientProposal The client proposal options (un-modifiable)
+ * @param serverProposal The server proposal options (un-modifiable)
+ */
+ default void sessionNegotiationStart(Session session,
+ Map<KexProposalOption, String> clientProposal, Map<KexProposalOption, String> serverProposal) {
+ // ignored
+ }
+
+ /**
+ * Signals the end of the negotiation options handling
+ *
+ * @param session The referenced {@link Session}
+ * @param clientProposal The client proposal options (un-modifiable)
+ * @param serverProposal The server proposal options (un-modifiable)
+ * @param negotiatedOptions The successfully negotiated options so far
+ * - even if exception occurred (un-modifiable)
+ * @param reason Negotiation end reason - {@code null} if successful
+ */
+ default void sessionNegotiationEnd(Session session,
+ Map<KexProposalOption, String> clientProposal, Map<KexProposalOption, String> serverProposal,
+ Map<KexProposalOption, String> negotiatedOptions, Throwable reason) {
+ // ignored
+ }
/**
* An event has been triggered
@@ -44,7 +76,9 @@ public interface SessionListener extends EventListener {
* @param session The referenced {@link Session}
* @param event The generated {@link Event}
*/
- void sessionEvent(Session session, Event event);
+ default void sessionEvent(Session session, Event event) {
+ // ignored
+ }
/**
* An exception was caught and the session will be closed
@@ -55,13 +89,16 @@ public interface SessionListener extends EventListener {
* @param session The referenced {@link Session}
* @param t The caught exception
*/
- void sessionException(Session session, Throwable t);
+ default void sessionException(Session session, Throwable t) {
+ // ignored
+ }
/**
* A session has been closed
*
* @param session The closed {@link Session}
*/
- void sessionClosed(Session session);
-
+ default void sessionClosed(Session session) {
+ // ignored
+ }
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
index 4b2af70..ad663e4 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
@@ -1857,47 +1857,59 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
* @return The negotiated options {@link Map}
*/
protected Map<KexProposalOption, String> negotiate() {
+ SessionListener listener = getSessionListenerProxy();
+ Map<KexProposalOption, String> c2sOptions = Collections.unmodifiableMap(clientProposal);
+ Map<KexProposalOption, String> s2cOptions = Collections.unmodifiableMap(serverProposal);
+ listener.sessionNegotiationStart(this, c2sOptions, s2cOptions);
+
Map<KexProposalOption, String> guess = new EnumMap<>(KexProposalOption.class);
- for (KexProposalOption paramType : KexProposalOption.VALUES) {
- String clientParamValue = clientProposal.get(paramType);
- String serverParamValue = serverProposal.get(paramType);
- String[] c = GenericUtils.split(clientParamValue, ',');
- String[] s = GenericUtils.split(serverParamValue, ',');
- for (String ci : c) {
- for (String si : s) {
- if (ci.equals(si)) {
- guess.put(paramType, ci);
+ Map<KexProposalOption, String> negotiatedGuess = Collections.unmodifiableMap(guess);
+ try {
+ for (KexProposalOption paramType : KexProposalOption.VALUES) {
+ String clientParamValue = c2sOptions.get(paramType);
+ String serverParamValue = s2cOptions.get(paramType);
+ String[] c = GenericUtils.split(clientParamValue, ',');
+ String[] s = GenericUtils.split(serverParamValue, ',');
+ for (String ci : c) {
+ for (String si : s) {
+ if (ci.equals(si)) {
+ guess.put(paramType, ci);
+ break;
+ }
+ }
+
+ String value = guess.get(paramType);
+ if (value != null) {
break;
}
}
+ // check if reached an agreement
String value = guess.get(paramType);
- if (value != null) {
- break;
- }
- }
-
- // check if reached an agreement
- String value = guess.get(paramType);
- if (value == null) {
- String message = "Unable to negotiate key exchange for " + paramType.getDescription()
- + " (client: " + clientParamValue + " / server: " + serverParamValue + ")";
- // OK if could not negotiate languages
- if (KexProposalOption.S2CLANG.equals(paramType) || KexProposalOption.C2SLANG.equals(paramType)) {
- if (log.isTraceEnabled()) {
- log.trace("negotiate({}) {}", this, message);
+ if (value == null) {
+ String message = "Unable to negotiate key exchange for " + paramType.getDescription()
+ + " (client: " + clientParamValue + " / server: " + serverParamValue + ")";
+ // OK if could not negotiate languages
+ if (KexProposalOption.S2CLANG.equals(paramType) || KexProposalOption.C2SLANG.equals(paramType)) {
+ if (log.isTraceEnabled()) {
+ log.trace("negotiate({}) {}", this, message);
+ }
+ } else {
+ throw new IllegalStateException(message);
}
} else {
- throw new IllegalStateException(message);
- }
- } else {
- if (log.isTraceEnabled()) {
- log.trace("negotiate(" + this + ")[" + paramType.getDescription() + "] guess=" + value
- + " (client: " + clientParamValue + " / server: " + serverParamValue + ")");
+ if (log.isTraceEnabled()) {
+ log.trace("negotiate(" + this + ")[" + paramType.getDescription() + "] guess=" + value
+ + " (client: " + clientParamValue + " / server: " + serverParamValue + ")");
+ }
}
}
+ } catch (RuntimeException | Error e) {
+ listener.sessionNegotiationEnd(this, c2sOptions, s2cOptions, negotiatedGuess, e);
+ throw e;
}
+ listener.sessionNegotiationEnd(this, c2sOptions, s2cOptions, negotiatedGuess, null);
return setNegotiationResult(guess);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpEventListener.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpEventListener.java b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpEventListener.java
index d026b4a..60a0d1f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpEventListener.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpEventListener.java
@@ -42,14 +42,18 @@ public interface SftpEventListener extends EventListener {
* @param session The {@link ServerSession} through which the request was handled
* @param version The negotiated SFTP version
*/
- void initialized(ServerSession session, int version);
+ default void initialized(ServerSession session, int version) {
+ // ignored
+ }
/**
* Called when subsystem is destroyed since it was closed
*
* @param session The associated {@link ServerSession}
*/
- void destroying(ServerSession session);
+ default void destroying(ServerSession session) {
+ // ignored
+ }
/**
* Specified file / directory has been opened
@@ -59,8 +63,10 @@ public interface SftpEventListener extends EventListener {
* @param localHandle The associated file / directory {@link Handle}
* @throws IOException If failed to handle the call
*/
- void open(ServerSession session, String remoteHandle, Handle localHandle)
- throws IOException;
+ default void open(ServerSession session, String remoteHandle, Handle localHandle)
+ throws IOException {
+ // ignored
+ }
/**
* Result of reading entries from a directory - <B>Note:</B> it may be a
@@ -74,8 +80,10 @@ public interface SftpEventListener extends EventListener {
* value = {@link Path} of the sub-entry
* @throws IOException If failed to handle the call
*/
- void read(ServerSession session, String remoteHandle, DirectoryHandle localHandle, Map<String, Path> entries)
- throws IOException;
+ default void read(ServerSession session, String remoteHandle, DirectoryHandle localHandle, Map<String, Path> entries)
+ throws IOException {
+ // ignored
+ }
/**
* Preparing to read from a file
@@ -89,8 +97,10 @@ public interface SftpEventListener extends EventListener {
* @param dataLen Requested read length
* @throws IOException If failed to handle the call
*/
- void reading(ServerSession session, String remoteHandle, FileHandle localHandle,
- long offset, byte[] data, int dataOffset, int dataLen) throws IOException;
+ default void reading(ServerSession session, String remoteHandle, FileHandle localHandle,
+ long offset, byte[] data, int dataOffset, int dataLen) throws IOException {
+ // ignored
+ }
/**
* Result of reading from a file
@@ -106,9 +116,11 @@ public interface SftpEventListener extends EventListener {
* @param thrown Non-{@code null} if read failed due to this exception
* @throws IOException If failed to handle the call
*/
- void read(ServerSession session, String remoteHandle, FileHandle localHandle,
+ default void read(ServerSession session, String remoteHandle, FileHandle localHandle,
long offset, byte[] data, int dataOffset, int dataLen, int readLen, Throwable thrown)
- throws IOException;
+ throws IOException {
+ // ignored
+ }
/**
* Preparing to write to file
@@ -122,9 +134,11 @@ public interface SftpEventListener extends EventListener {
* @param dataLen Requested write length
* @throws IOException If failed to handle the call
*/
- void writing(ServerSession session, String remoteHandle, FileHandle localHandle,
+ default void writing(ServerSession session, String remoteHandle, FileHandle localHandle,
long offset, byte[] data, int dataOffset, int dataLen)
- throws IOException;
+ throws IOException {
+ // ignored
+ }
/**
* Finished to writing to file
@@ -139,9 +153,11 @@ public interface SftpEventListener extends EventListener {
* @param thrown The reason for failing to write - {@code null} if successful
* @throws IOException If failed to handle the call
*/
- void written(ServerSession session, String remoteHandle, FileHandle localHandle,
+ default void written(ServerSession session, String remoteHandle, FileHandle localHandle,
long offset, byte[] data, int dataOffset, int dataLen, Throwable thrown)
- throws IOException;
+ throws IOException {
+ // ignored
+ }
/**
* Called <U>prior</U> to blocking a file section
@@ -155,8 +171,10 @@ public interface SftpEventListener extends EventListener {
* @throws IOException If failed to handle the call
* @see #blocked(ServerSession, String, FileHandle, long, long, int, Throwable)
*/
- void blocking(ServerSession session, String remoteHandle, FileHandle localHandle, long offset, long length, int mask)
- throws IOException;
+ default void blocking(ServerSession session, String remoteHandle, FileHandle localHandle, long offset, long length, int mask)
+ throws IOException {
+ // ignored
+ }
/**
* Called <U>after</U> blocking a file section
@@ -170,8 +188,10 @@ public interface SftpEventListener extends EventListener {
* @param thrown If not-{@code null} then the reason for the failure to execute
* @throws IOException If failed to handle the call
*/
- void blocked(ServerSession session, String remoteHandle, FileHandle localHandle, long offset, long length, int mask, Throwable thrown)
- throws IOException;
+ default void blocked(ServerSession session, String remoteHandle, FileHandle localHandle, long offset, long length, int mask, Throwable thrown)
+ throws IOException {
+ // ignored
+ }
/**
* Called <U>prior</U> to un-blocking a file section
@@ -183,8 +203,10 @@ public interface SftpEventListener extends EventListener {
* @param length Section size for un-locking
* @throws IOException If failed to handle the call
*/
- void unblocking(ServerSession session, String remoteHandle, FileHandle localHandle, long offset, long length)
- throws IOException;
+ default void unblocking(ServerSession session, String remoteHandle, FileHandle localHandle, long offset, long length)
+ throws IOException {
+ // ignored
+ }
/**
* Called <U>prior</U> to un-blocking a file section
@@ -197,8 +219,10 @@ public interface SftpEventListener extends EventListener {
* @param thrown If not-{@code null} then the reason for the failure to execute
* @throws IOException If failed to handle the call
*/
- void unblocked(ServerSession session, String remoteHandle, FileHandle localHandle, long offset, long length, Throwable thrown)
- throws IOException;
+ default void unblocked(ServerSession session, String remoteHandle, FileHandle localHandle, long offset, long length, Throwable thrown)
+ throws IOException {
+ // ignored
+ }
/**
* Specified file / directory has been closed
@@ -207,7 +231,9 @@ public interface SftpEventListener extends EventListener {
* @param remoteHandle The (opaque) assigned handle for the file / directory
* @param localHandle The associated file / directory {@link Handle}
*/
- void close(ServerSession session, String remoteHandle, Handle localHandle);
+ default void close(ServerSession session, String remoteHandle, Handle localHandle) {
+ // ignored
+ }
/**
* Called <U>prior</U> to creating a directory
@@ -218,8 +244,10 @@ public interface SftpEventListener extends EventListener {
* @throws IOException If failed to handle the call
* @see #created(ServerSession, Path, Map, Throwable)
*/
- void creating(ServerSession session, Path path, Map<String, ?> attrs)
- throws IOException;
+ default void creating(ServerSession session, Path path, Map<String, ?> attrs)
+ throws IOException {
+ // ignored
+ }
/**
* Called <U>after</U> creating a directory
@@ -230,8 +258,10 @@ public interface SftpEventListener extends EventListener {
* @param thrown If not-{@code null} then the reason for the failure to execute
* @throws IOException If failed to handle the call
*/
- void created(ServerSession session, Path path, Map<String, ?> attrs, Throwable thrown)
- throws IOException;
+ default void created(ServerSession session, Path path, Map<String, ?> attrs, Throwable thrown)
+ throws IOException {
+ // ignored
+ }
/**
* Called <U>prior</U> to renaming a file / directory
@@ -243,8 +273,10 @@ public interface SftpEventListener extends EventListener {
* @throws IOException If failed to handle the call
* @see #moved(ServerSession, Path, Path, Collection, Throwable)
*/
- void moving(ServerSession session, Path srcPath, Path dstPath, Collection<CopyOption> opts)
- throws IOException;
+ default void moving(ServerSession session, Path srcPath, Path dstPath, Collection<CopyOption> opts)
+ throws IOException {
+ // ignored
+ }
/**
* Called <U>after</U> renaming a file / directory
@@ -256,8 +288,10 @@ public interface SftpEventListener extends EventListener {
* @param thrown If not-{@code null} then the reason for the failure to execute
* @throws IOException If failed to handle the call
*/
- void moved(ServerSession session, Path srcPath, Path dstPath, Collection<CopyOption> opts, Throwable thrown)
- throws IOException;
+ default void moved(ServerSession session, Path srcPath, Path dstPath, Collection<CopyOption> opts, Throwable thrown)
+ throws IOException {
+ // ignored
+ }
/**
* Called <U>prior</U> to removing a file / directory
@@ -267,7 +301,9 @@ public interface SftpEventListener extends EventListener {
* @throws IOException If failed to handle the call
* @see #removed(ServerSession, Path, Throwable)
*/
- void removing(ServerSession session, Path path) throws IOException;
+ default void removing(ServerSession session, Path path) throws IOException {
+ // ignored
+ }
/**
* Called <U>after</U> a file / directory has been removed
@@ -277,7 +313,9 @@ public interface SftpEventListener extends EventListener {
* @param thrown If not-{@code null} then the reason for the failure to execute
* @throws IOException If failed to handle the call
*/
- void removed(ServerSession session, Path path, Throwable thrown) throws IOException;
+ default void removed(ServerSession session, Path path, Throwable thrown) throws IOException {
+ // ignored
+ }
/**
* Called <U>prior</U> to creating a link
@@ -289,8 +327,10 @@ public interface SftpEventListener extends EventListener {
* @throws IOException If failed to handle the call
* @see #linked(ServerSession, Path, Path, boolean, Throwable)
*/
- void linking(ServerSession session, Path source, Path target, boolean symLink)
- throws IOException;
+ default void linking(ServerSession session, Path source, Path target, boolean symLink)
+ throws IOException {
+ // ignored
+ }
/**
* Called <U>after</U> creating a link
@@ -302,8 +342,10 @@ public interface SftpEventListener extends EventListener {
* @param thrown If not-{@code null} then the reason for the failure to execute
* @throws IOException If failed to handle the call
*/
- void linked(ServerSession session, Path source, Path target, boolean symLink, Throwable thrown)
- throws IOException;
+ default void linked(ServerSession session, Path source, Path target, boolean symLink, Throwable thrown)
+ throws IOException {
+ // ignored
+ }
/**
* Called <U>prior</U> to modifying the attributes of a file / directory
@@ -315,8 +357,10 @@ public interface SftpEventListener extends EventListener {
* @throws IOException If failed to handle the call
* @see #modifiedAttributes(ServerSession, Path, Map, Throwable)
*/
- void modifyingAttributes(ServerSession session, Path path, Map<String, ?> attrs)
- throws IOException;
+ default void modifyingAttributes(ServerSession session, Path path, Map<String, ?> attrs)
+ throws IOException {
+ // ignored
+ }
/**
* Called <U>after</U> modifying the attributes of a file / directory
@@ -328,6 +372,8 @@ public interface SftpEventListener extends EventListener {
* @param thrown If not-{@code null} then the reason for the failure to execute
* @throws IOException If failed to handle the call
*/
- void modifiedAttributes(ServerSession session, Path path, Map<String, ?> attrs, Throwable thrown)
- throws IOException;
+ default void modifiedAttributes(ServerSession session, Path path, Map<String, ?> attrs, Throwable thrown)
+ throws IOException {
+ // ignored
+ }
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
index c86883a..4cffe5e 100644
--- a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
@@ -392,27 +392,12 @@ public class KeyReExchangeTest extends BaseTestSupport {
final AtomicInteger exchanges = new AtomicInteger();
session.addSessionListener(new SessionListener() {
@Override
- public void sessionCreated(Session session) {
- // ignored
- }
-
- @Override
public void sessionEvent(Session session, Event event) {
if (Event.KeyEstablished.equals(event)) {
int count = exchanges.incrementAndGet();
outputDebugMessage("Key established for %s - count=%d", session, count);
}
}
-
- @Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
- @Override
- public void sessionClosed(Session session) {
- // ignored
- }
});
byte[] data = sb.toString().getBytes(StandardCharsets.UTF_8);
@@ -509,27 +494,12 @@ public class KeyReExchangeTest extends BaseTestSupport {
final AtomicInteger exchanges = new AtomicInteger();
session.addSessionListener(new SessionListener() {
@Override
- public void sessionCreated(Session session) {
- // ignored
- }
-
- @Override
public void sessionEvent(Session session, Event event) {
if (Event.KeyEstablished.equals(event)) {
int count = exchanges.incrementAndGet();
outputDebugMessage("Key established for %s - count=%d", session, count);
}
}
-
- @Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
- @Override
- public void sessionClosed(Session session) {
- // ignored
- }
});
byte[] data = getCurrentTestName().getBytes(StandardCharsets.UTF_8);
@@ -654,27 +624,12 @@ public class KeyReExchangeTest extends BaseTestSupport {
final AtomicInteger exchanges = new AtomicInteger();
session.addSessionListener(new SessionListener() {
@Override
- public void sessionCreated(Session session) {
- // ignored
- }
-
- @Override
public void sessionEvent(Session session, Event event) {
if (Event.KeyEstablished.equals(event)) {
int count = exchanges.incrementAndGet();
outputDebugMessage("Key established for %s - count=%d", session, count);
}
}
-
- @Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
- @Override
- public void sessionClosed(Session session) {
- // ignored
- }
});
byte[] data = (getClass().getName() + "#" + getCurrentTestName() + "\n").getBytes(StandardCharsets.UTF_8);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/test/java/org/apache/sshd/client/ClientAuthenticationManagerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientAuthenticationManagerTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientAuthenticationManagerTest.java
index f42704a..a7e18fe 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/ClientAuthenticationManagerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientAuthenticationManagerTest.java
@@ -38,7 +38,6 @@ import org.apache.sshd.client.session.ClientSessionImpl;
import org.apache.sshd.common.Factory;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.NamedResource;
-import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.common.channel.ChannelListener;
import org.apache.sshd.common.forward.DefaultTcpipForwarderFactory;
import org.apache.sshd.common.forward.PortForwardingEventListener;
@@ -51,7 +50,6 @@ import org.apache.sshd.common.random.SingletonRandomFactory;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.session.SessionListener;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.net.SshdSocketAddress;
import org.apache.sshd.util.test.BaseTestSupport;
import org.junit.FixMethodOrder;
import org.junit.Test;
@@ -260,78 +258,8 @@ public class ClientAuthenticationManagerTest extends BaseTestSupport {
// ignored
}
});
- Mockito.when(client.getChannelListenerProxy()).thenReturn(new ChannelListener() {
- @Override
- public void channelOpenSuccess(Channel channel) {
- // ignored
- }
-
- @Override
- public void channelOpenFailure(Channel channel, Throwable reason) {
- // ignored
- }
-
- @Override
- public void channelInitialized(Channel channel) {
- // ignored
- }
-
- @Override
- public void channelStateChanged(Channel channel, String hint) {
- // ignored
- }
-
- @Override
- public void channelClosed(Channel channel, Throwable reason) {
- // ignored
- }
- });
- Mockito.when(client.getPortForwardingEventListenerProxy()).thenReturn(new PortForwardingEventListener() {
- @Override
- public void tornDownExplicitTunnel(Session session, SshdSocketAddress address, boolean localForwarding,
- Throwable reason) throws IOException {
- // ignored
- }
-
- @Override
- public void tornDownDynamicTunnel(Session session, SshdSocketAddress address, Throwable reason) throws IOException {
- // ignored
- }
-
- @Override
- public void tearingDownExplicitTunnel(Session session, SshdSocketAddress address, boolean localForwarding)
- throws IOException {
- // ignored
- }
-
- @Override
- public void tearingDownDynamicTunnel(Session session, SshdSocketAddress address) throws IOException {
- // ignored
- }
-
- @Override
- public void establishingExplicitTunnel(Session session, SshdSocketAddress local, SshdSocketAddress remote,
- boolean localForwarding) throws IOException {
- // ignored
- }
-
- @Override
- public void establishingDynamicTunnel(Session session, SshdSocketAddress local) throws IOException {
- // ignored
- }
-
- @Override
- public void establishedExplicitTunnel(Session session, SshdSocketAddress local, SshdSocketAddress remote,
- boolean localForwarding, SshdSocketAddress boundAddress, Throwable reason) throws IOException {
- // ignored
- }
-
- @Override
- public void establishedDynamicTunnel(Session session, SshdSocketAddress local, SshdSocketAddress boundAddress,
- Throwable reason) throws IOException {
- // ignored
- }
- });
+ Mockito.when(client.getChannelListenerProxy()).thenReturn(ChannelListener.EMPTY);
+ Mockito.when(client.getPortForwardingEventListenerProxy()).thenReturn(PortForwardingEventListener.EMPTY);
Factory<Random> randomFactory = new SingletonRandomFactory(JceRandomFactory.INSTANCE);
Mockito.when(client.getRandomFactory()).thenReturn(randomFactory);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/test/java/org/apache/sshd/client/ClientSessionListenerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientSessionListenerTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientSessionListenerTest.java
index 6df2a69..a1cd3dc 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/ClientSessionListenerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientSessionListenerTest.java
@@ -95,21 +95,6 @@ public class ClientSessionListenerTest extends BaseTestSupport {
session.setCipherFactories(Collections.singletonList((NamedFactory<Cipher>) kexParams.get(KexProposalOption.C2SENC)));
session.setMacFactories(Collections.singletonList((NamedFactory<Mac>) kexParams.get(KexProposalOption.C2SMAC)));
}
-
- @Override
- public void sessionEvent(Session session, Event event) {
- // ignored
- }
-
- @Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
- @Override
- public void sessionClosed(Session session) {
- // ignored
- }
});
client.start();
@@ -138,11 +123,6 @@ public class ClientSessionListenerTest extends BaseTestSupport {
client.addSessionListener(new SessionListener() {
@Override
- public void sessionCreated(Session session) {
- // ignored
- }
-
- @Override
public void sessionEvent(Session session, Event event) {
if ((!session.isAuthenticated()) && (session instanceof ClientSession) && Event.KexCompleted.equals(event)) {
ClientSession clientSession = (ClientSession) session;
@@ -150,16 +130,6 @@ public class ClientSessionListenerTest extends BaseTestSupport {
clientSession.setUserInteraction(UserInteraction.NONE);
}
}
-
- @Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
- @Override
- public void sessionClosed(Session session) {
- // ignored
- }
});
client.start();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
index 7ac8825..97142f1 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
@@ -259,11 +259,6 @@ public class ClientTest extends BaseTestSupport {
updateSessionConfigProperty(session, "sessionClosed");
}
- @Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
private void updateSessionConfigProperty(Session session, Object value) {
PropertyResolverUtils.updateProperty(session, sessionPropName, value);
sessionConfigValueHolder.set(value);
@@ -293,11 +288,6 @@ public class ClientTest extends BaseTestSupport {
updateChannelConfigProperty(channel, "channelClosed");
}
- @Override
- public void channelStateChanged(Channel channel, String hint) {
- // ignored
- }
-
private void updateChannelConfigProperty(Channel channel, Object value) {
PropertyResolverUtils.updateProperty(channel, channelPropName, value);
channelConfigValueHolder.set(value);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java
index bafd8aa..929e377 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java
@@ -89,11 +89,6 @@ public class SimpleSessionClientTest extends BaseSimpleClientTestSupport {
public void testConnectionTimeout() throws Exception {
client.addSessionListener(new SessionListener() {
@Override
- public void sessionEvent(Session session, Event event) {
- // ignored
- }
-
- @Override
public void sessionCreated(Session session) {
try {
Thread.sleep(CONNECT_TIMEOUT + 150L);
@@ -101,16 +96,6 @@ public class SimpleSessionClientTest extends BaseSimpleClientTestSupport {
// ignored
}
}
-
- @Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
- @Override
- public void sessionClosed(Session session) {
- // ignored
- }
});
client.start();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java b/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
index 3fea9c2..8e29598 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
@@ -202,16 +202,6 @@ public class AuthenticationTest extends BaseTestSupport {
}
@Override
- public void serverVersionInfo(ClientSession session, List<String> lines) {
- // ignored
- }
-
- @Override
- public void welcome(ClientSession session, String banner, String lang) {
- // ignored
- }
-
- @Override
public String[] interactive(ClientSession session, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
throw new UnsupportedOperationException("Unexpected call");
}
@@ -443,16 +433,6 @@ public class AuthenticationTest extends BaseTestSupport {
}
@Override
- public void serverVersionInfo(ClientSession session, List<String> lines) {
- // ignored
- }
-
- @Override
- public void welcome(ClientSession session, String banner, String lang) {
- // ignored
- }
-
- @Override
public String[] interactive(ClientSession session, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
assertEquals("Unexpected multiple calls", 1, interactiveCount.incrementAndGet());
assertEquals("Mismatched name", challenge.getInteractionName(), name);
@@ -520,16 +500,6 @@ public class AuthenticationTest extends BaseTestSupport {
}
@Override
- public void serverVersionInfo(ClientSession session, List<String> lines) {
- // ignored
- }
-
- @Override
- public void welcome(ClientSession session, String banner, String lang) {
- // ignored
- }
-
- @Override
public String[] interactive(ClientSession session, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
throw new UnsupportedOperationException("Unexpected call");
}
@@ -564,25 +534,10 @@ public class AuthenticationTest extends BaseTestSupport {
final AtomicInteger invocations = new AtomicInteger(0);
client.addSessionListener(new SessionListener() {
@Override
- public void sessionCreated(Session session) {
- // ignored
- }
-
- @Override
public void sessionEvent(Session session, Event event) {
assertEquals("Mismatched invocations count", 1, invocations.incrementAndGet());
throw expected;
}
-
- @Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
- @Override
- public void sessionClosed(Session session) {
- // ignored
- }
});
client.start();
@@ -855,16 +810,6 @@ public class AuthenticationTest extends BaseTestSupport {
final String[] response = {pswd};
s.setUserInteraction(new UserInteraction() {
@Override
- public void welcome(ClientSession session, String banner, String lang) {
- // ignored
- }
-
- @Override
- public void serverVersionInfo(ClientSession session, List<String> lines) {
- // ignored
- }
-
- @Override
public boolean isInteractionAllowed(ClientSession session) {
return true;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java b/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java
index 2319c31..4ded562 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java
@@ -83,11 +83,6 @@ public class CompressionTest extends BaseTestSupport {
sshd.setCompressionFactories(Arrays.<NamedFactory<org.apache.sshd.common.compression.Compression>>asList(factory));
sshd.addSessionListener(new SessionListener() {
@Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
- @Override
@SuppressWarnings("synthetic-access")
public void sessionEvent(Session session, Event event) {
if (Event.KeyEstablished.equals(event)) {
@@ -98,16 +93,6 @@ public class CompressionTest extends BaseTestSupport {
}
}
}
-
- @Override
- public void sessionCreated(Session session) {
- // ignored
- }
-
- @Override
- public void sessionClosed(Session session) {
- // ignored
- }
});
sshd.start();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java b/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java
index 22f8cb3..6ece5e7 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java
@@ -97,11 +97,6 @@ public class ReservedSessionMessagesHandlerTest extends BaseTestSupport {
final Semaphore signal = new Semaphore(0);
sshd.addSessionListener(new SessionListener() {
@Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
- @Override
public void sessionEvent(final Session session, Event event) {
if (Event.Authenticated.equals(event)) {
service.execute(new Runnable() {
@@ -120,16 +115,6 @@ public class ReservedSessionMessagesHandlerTest extends BaseTestSupport {
});
}
}
-
- @Override
- public void sessionCreated(Session session) {
- // ignored
- }
-
- @Override
- public void sessionClosed(Session session) {
- // ignored
- }
});
client.start();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/test/java/org/apache/sshd/server/ServerProxyAcceptorTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/ServerProxyAcceptorTest.java b/sshd-core/src/test/java/org/apache/sshd/server/ServerProxyAcceptorTest.java
index 4effede..8b37999 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/ServerProxyAcceptorTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/ServerProxyAcceptorTest.java
@@ -109,11 +109,6 @@ public class ServerProxyAcceptorTest extends BaseTestSupport {
final Semaphore sessionSignal = new Semaphore(0);
sshd.addSessionListener(new SessionListener() {
@Override
- public void sessionException(Session session, Throwable t) {
- // do nothing
- }
-
- @Override
public void sessionEvent(Session session, Event event) {
verifyClientAddress(event.name(), session);
if (Event.KeyEstablished.equals(event)) {
@@ -122,11 +117,6 @@ public class ServerProxyAcceptorTest extends BaseTestSupport {
}
@Override
- public void sessionCreated(Session session) {
- // do nothing - no proxy yet
- }
-
- @Override
public void sessionClosed(Session session) {
verifyClientAddress("sessionClosed", session);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java b/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java
index 8357be5..4b13e8a 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java
@@ -88,7 +88,7 @@ public class ServerSessionListenerTest extends BaseTestSupport {
@Test // see https://issues.apache.org/jira/browse/SSHD-456
public void testServerStillListensIfSessionListenerThrowsException() throws Exception {
- final Map<String, SocketAddress> eventsMap = new TreeMap<String, SocketAddress>(String.CASE_INSENSITIVE_ORDER);
+ final Map<String, SocketAddress> eventsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
final Logger log = LoggerFactory.getLogger(getClass());
sshd.addSessionListener(new SessionListener() {
@Override
@@ -106,11 +106,6 @@ public class ServerSessionListenerTest extends BaseTestSupport {
throwException("SessionClosed", session);
}
- @Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
private void throwException(String phase, Session session) {
IoSession ioSession = session.getIoSession();
SocketAddress addr = ioSession.getRemoteAddress();
@@ -172,21 +167,6 @@ public class ServerSessionListenerTest extends BaseTestSupport {
session.setCipherFactories(Collections.singletonList((NamedFactory<Cipher>) kexParams.get(KexProposalOption.S2CENC)));
session.setMacFactories(Collections.singletonList((NamedFactory<Mac>) kexParams.get(KexProposalOption.S2CMAC)));
}
-
- @Override
- public void sessionEvent(Session session, Event event) {
- // ignored
- }
-
- @Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
- @Override
- public void sessionClosed(Session session) {
- // ignored
- }
});
client.start();
@@ -224,21 +204,6 @@ public class ServerSessionListenerTest extends BaseTestSupport {
ServerAuthenticationManager.Utils.DEFAULT_USER_AUTH_PASSWORD_FACTORY));
}
}
-
- @Override
- public void sessionEvent(Session session, Event event) {
- // ignored
- }
-
- @Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
- @Override
- public void sessionClosed(Session session) {
- // ignored
- }
});
client.start();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/997ae449/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java b/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
index 1d5fd4f..957c0a6 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
@@ -486,52 +486,22 @@ public class ServerTest extends BaseTestSupport {
final AtomicInteger serverEventCount = new AtomicInteger(0);
sshd.addSessionListener(new SessionListener() {
@Override
- public void sessionCreated(Session session) {
- // ignored
- }
-
- @Override
public void sessionEvent(Session session, Event event) {
if (event == Event.KexCompleted) {
serverEventCount.incrementAndGet();
}
}
-
- @Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
- @Override
- public void sessionClosed(Session session) {
- // ignored
- }
});
sshd.start();
final AtomicInteger clientEventCount = new AtomicInteger(0);
client.addSessionListener(new SessionListener() {
@Override
- public void sessionCreated(Session session) {
- // ignored
- }
-
- @Override
public void sessionEvent(Session session, Event event) {
if (event == Event.KexCompleted) {
clientEventCount.incrementAndGet();
}
}
-
- @Override
- public void sessionException(Session session, Throwable t) {
- // ignored
- }
-
- @Override
- public void sessionClosed(Session session) {
- // ignored
- }
});
client.start();
@@ -601,26 +571,6 @@ public class ServerTest extends BaseTestSupport {
outputDebugMessage("channelStateChanged(%s): %s", channel, hint);
stateChangeHints.add(hint);
}
-
- @Override
- public void channelOpenSuccess(Channel channel) {
- // ignored
- }
-
- @Override
- public void channelOpenFailure(Channel channel, Throwable reason) {
- // ignored
- }
-
- @Override
- public void channelInitialized(Channel channel) {
- // ignored
- }
-
- @Override
- public void channelClosed(Channel channel, Throwable reason) {
- // ignored
- }
});
shell.open().verify(9L, TimeUnit.SECONDS);
@@ -642,7 +592,7 @@ public class ServerTest extends BaseTestSupport {
@Test
public void testEnvironmentVariablesPropagationToServer() throws Exception {
- final AtomicReference<Environment> envHolder = new AtomicReference<Environment>(null);
+ final AtomicReference<Environment> envHolder = new AtomicReference<>(null);
sshd.setCommandFactory(new CommandFactory() {
@Override
public Command createCommand(final String command) {
@@ -814,16 +764,6 @@ public class ServerTest extends BaseTestSupport {
final String[] replies = {getCurrentTestName()};
client.setUserInteraction(new UserInteraction() {
@Override
- public void welcome(ClientSession session, String banner, String lang) {
- // ignored
- }
-
- @Override
- public void serverVersionInfo(ClientSession clientSession, List<String> lines) {
- // ignored
- }
-
- @Override
public boolean isInteractionAllowed(ClientSession session) {
return true;
}
@@ -917,11 +857,6 @@ public class ServerTest extends BaseTestSupport {
final Semaphore signal = new Semaphore(0);
client.setUserInteraction(new UserInteraction() {
@Override
- public void welcome(ClientSession session, String banner, String lang) {
- // ignored
- }
-
- @Override
public void serverVersionInfo(ClientSession session, List<String> lines) {
assertNull("Unexpected extra call", actualHolder.getAndSet(lines));
signal.release();