Skip to content

Commit ff83120

Browse files
committed
Remove deprecated calls
1 parent dbaf6dc commit ff83120

File tree

12 files changed

+87
-88
lines changed

12 files changed

+87
-88
lines changed

build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ val gitHubUrl = "https://github.com/connectbot/sshlib"
4040
apply(from = "$rootDir/config/quality.gradle.kts")
4141

4242
dependencies {
43-
implementation("com.jcraft:jzlib:1.1.3")
4443
implementation("org.connectbot:simplesocks:1.0.1")
4544
implementation("com.google.crypto.tink:tink:1.19.0") {
4645
isTransitive = false

src/main/java/com/trilead/ssh2/SFTPv3Client.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import java.io.OutputStream;
88
import java.io.PrintStream;
99
import java.nio.charset.Charset;
10+
import java.util.ArrayList;
1011
import java.util.HashMap;
11-
import java.util.Vector;
12+
import java.util.List;
13+
import java.util.Map;
1214

1315
import com.trilead.ssh2.packets.TypesReader;
1416
import com.trilead.ssh2.packets.TypesWriter;
@@ -89,7 +91,7 @@ public class SFTPv3Client
8991
OutputStream os;
9092

9193
int protocol_version = 0;
92-
HashMap server_extensions = new HashMap();
94+
Map<String, byte[]> server_extensions = new HashMap<>();
9395

9496
int next_request_id = 1000;
9597

@@ -317,30 +319,30 @@ private SFTPv3FileAttributes readAttrs(TypesReader tr) throws IOException
317319
{
318320
if (debug != null)
319321
debug.println("SSH_FILEXFER_ATTR_SIZE");
320-
fa.size = new Long(tr.readUINT64());
322+
fa.size = Long.valueOf(tr.readUINT64());
321323
}
322324

323325
if ((flags & AttribFlags.SSH_FILEXFER_ATTR_V3_UIDGID) != 0)
324326
{
325327
if (debug != null)
326328
debug.println("SSH_FILEXFER_ATTR_V3_UIDGID");
327-
fa.uid = new Integer(tr.readUINT32());
328-
fa.gid = new Integer(tr.readUINT32());
329+
fa.uid = Integer.valueOf(tr.readUINT32());
330+
fa.gid = Integer.valueOf(tr.readUINT32());
329331
}
330332

331333
if ((flags & AttribFlags.SSH_FILEXFER_ATTR_PERMISSIONS) != 0)
332334
{
333335
if (debug != null)
334336
debug.println("SSH_FILEXFER_ATTR_PERMISSIONS");
335-
fa.permissions = new Integer(tr.readUINT32());
337+
fa.permissions = Integer.valueOf(tr.readUINT32());
336338
}
337339

338340
if ((flags & AttribFlags.SSH_FILEXFER_ATTR_V3_ACMODTIME) != 0)
339341
{
340342
if (debug != null)
341343
debug.println("SSH_FILEXFER_ATTR_V3_ACMODTIME");
342-
fa.atime = new Long(((long) tr.readUINT32()) & 0xffffffffl);
343-
fa.mtime = new Long(((long) tr.readUINT32()) & 0xffffffffl);
344+
fa.atime = Long.valueOf(((long) tr.readUINT32()) & 0xffffffffl);
345+
fa.mtime = Long.valueOf(((long) tr.readUINT32()) & 0xffffffffl);
344346

345347
}
346348

@@ -723,9 +725,9 @@ public String canonicalPath(String path) throws IOException
723725
throw new SFTPException(tr.readString(), errorCode);
724726
}
725727

726-
private final Vector scanDirectory(byte[] handle) throws IOException
728+
private final List<SFTPv3DirectoryEntry> scanDirectory(byte[] handle) throws IOException
727729
{
728-
Vector files = new Vector();
730+
List<SFTPv3DirectoryEntry> files = new ArrayList<>();
729731

730732
while (true)
731733
{
@@ -776,7 +778,7 @@ private final Vector scanDirectory(byte[] handle) throws IOException
776778
dirEnt.longEntry = tr.readString(charsetName);
777779

778780
dirEnt.attributes = readAttrs(tr);
779-
files.addElement(dirEnt);
781+
files.add(dirEnt);
780782

781783
if (debug != null)
782784
debug.println("File: '" + dirEnt.filename + "'");
@@ -942,13 +944,13 @@ public void close()
942944
* List the contents of a directory.
943945
*
944946
* @param dirName See the {@link SFTPv3Client comment} for the class for more details.
945-
* @return A Vector containing {@link SFTPv3DirectoryEntry} objects.
947+
* @return A List containing {@link SFTPv3DirectoryEntry} objects.
946948
* @throws IOException on error
947949
*/
948-
public Vector ls(String dirName) throws IOException
950+
public List<SFTPv3DirectoryEntry> ls(String dirName) throws IOException
949951
{
950952
byte[] handle = openDirectory(dirName);
951-
Vector result = scanDirectory(handle);
953+
List<SFTPv3DirectoryEntry> result = scanDirectory(handle);
952954
closeHandle(handle);
953955
return result;
954956
}

src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
import java.security.interfaces.DSAPublicKey;
1313
import java.security.interfaces.ECPublicKey;
1414
import java.security.interfaces.RSAPublicKey;
15+
import java.util.ArrayList;
16+
import java.util.List;
1517
import java.util.Set;
16-
import java.util.Vector;
1718

1819
import com.trilead.ssh2.InteractiveCallback;
1920
import com.trilead.ssh2.crypto.PEMDecoder;
@@ -48,7 +49,7 @@ public class AuthenticationManager implements MessageHandler
4849
{
4950
TransportManager tm;
5051

51-
Vector packets = new Vector();
52+
List<byte[]> packets = new ArrayList<>();
5253
boolean connectionClosed = false;
5354

5455
String banner;
@@ -94,9 +95,8 @@ byte[] deQueue() throws IOException
9495
{
9596
}
9697
}
97-
/* This sequence works with J2ME */
98-
byte[] res = (byte[]) packets.firstElement();
99-
packets.removeElementAt(0);
98+
byte[] res = packets.get(0);
99+
packets.remove(0);
100100
return res;
101101
}
102102
}
@@ -462,7 +462,7 @@ public void handleMessage(byte[] msg, int msglen) throws IOException
462462
{
463463
byte[] tmp = new byte[msglen];
464464
System.arraycopy(msg, 0, tmp, 0, msglen);
465-
packets.addElement(tmp);
465+
packets.add(tmp);
466466
}
467467

468468
packets.notifyAll();

src/main/java/com/trilead/ssh2/compression/Zlib.java

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
package com.trilead.ssh2.compression;
3131

32-
import com.jcraft.jzlib.JZlib;
33-
import com.jcraft.jzlib.ZStream;
32+
import java.util.zip.Deflater;
33+
import java.util.zip.Inflater;
3434

3535
/**
3636
* @author Kenny Root
@@ -40,19 +40,16 @@ public class Zlib implements ICompressor {
4040
static private final int DEFAULT_BUF_SIZE = 4096;
4141
static private final int LEVEL = 5;
4242

43-
private ZStream deflate;
43+
private Deflater deflate;
4444
private byte[] deflate_tmpbuf;
4545

46-
private ZStream inflate;
46+
private Inflater inflate;
4747
private byte[] inflate_tmpbuf;
4848
private byte[] inflated_buf;
4949

5050
public Zlib() {
51-
deflate = new ZStream();
52-
inflate = new ZStream();
53-
54-
deflate.deflateInit(LEVEL);
55-
inflate.inflateInit();
51+
deflate = new Deflater(LEVEL);
52+
inflate = new Inflater();
5653

5754
deflate_tmpbuf = new byte[DEFAULT_BUF_SIZE];
5855
inflate_tmpbuf = new byte[DEFAULT_BUF_SIZE];
@@ -68,28 +65,22 @@ public int getBufferSize() {
6865
}
6966

7067
public int compress(byte[] buf, int start, int len, byte[] output) {
71-
deflate.next_in = buf;
72-
deflate.next_in_index = start;
73-
deflate.avail_in = len - start;
68+
deflate.setInput(buf, start, len - start);
7469

7570
if ((buf.length + 1024) > deflate_tmpbuf.length) {
7671
deflate_tmpbuf = new byte[buf.length + 1024];
7772
}
7873

79-
deflate.next_out = deflate_tmpbuf;
80-
deflate.next_out_index = 0;
81-
deflate.avail_out = output.length;
74+
int outputlen = deflate.deflate(deflate_tmpbuf, 0, output.length, Deflater.SYNC_FLUSH);
8275

83-
if (deflate.deflate(JZlib.Z_PARTIAL_FLUSH) != JZlib.Z_OK) {
76+
if (deflate.getAdler() == 0) {
8477
System.err.println("compress: compression failure");
8578
}
8679

87-
if (deflate.avail_in > 0) {
80+
if (!deflate.finished() && deflate.getTotalIn() < len - start) {
8881
System.err.println("compress: deflated data too large");
8982
}
9083

91-
int outputlen = output.length - deflate.avail_out;
92-
9384
System.arraycopy(deflate_tmpbuf, 0, output, 0, outputlen);
9485

9586
return outputlen;
@@ -98,45 +89,48 @@ public int compress(byte[] buf, int start, int len, byte[] output) {
9889
public byte[] uncompress(byte[] buffer, int start, int[] length) {
9990
int inflated_end = 0;
10091

101-
inflate.next_in = buffer;
102-
inflate.next_in_index = start;
103-
inflate.avail_in = length[0];
104-
105-
while (true) {
106-
inflate.next_out = inflate_tmpbuf;
107-
inflate.next_out_index = 0;
108-
inflate.avail_out = DEFAULT_BUF_SIZE;
109-
int status = inflate.inflate(JZlib.Z_PARTIAL_FLUSH);
110-
switch (status) {
111-
case JZlib.Z_OK:
112-
if (inflated_buf.length < inflated_end + DEFAULT_BUF_SIZE
113-
- inflate.avail_out) {
114-
byte[] foo = new byte[inflated_end + DEFAULT_BUF_SIZE
115-
- inflate.avail_out];
116-
System.arraycopy(inflated_buf, 0, foo, 0, inflated_end);
117-
inflated_buf = foo;
118-
}
119-
System.arraycopy(inflate_tmpbuf, 0, inflated_buf, inflated_end,
120-
DEFAULT_BUF_SIZE - inflate.avail_out);
121-
inflated_end += (DEFAULT_BUF_SIZE - inflate.avail_out);
122-
length[0] = inflated_end;
123-
break;
124-
case JZlib.Z_BUF_ERROR:
125-
if (inflated_end > buffer.length - start) {
126-
byte[] foo = new byte[inflated_end + start];
127-
System.arraycopy(buffer, 0, foo, 0, start);
128-
System.arraycopy(inflated_buf, 0, foo, start, inflated_end);
129-
buffer = foo;
130-
} else {
131-
System.arraycopy(inflated_buf, 0, buffer, start,
132-
inflated_end);
92+
inflate.setInput(buffer, start, length[0]);
93+
94+
while (!inflate.needsInput()) {
95+
try {
96+
int decompressed = inflate.inflate(inflate_tmpbuf, 0, DEFAULT_BUF_SIZE);
97+
98+
if (decompressed > 0) {
99+
if (inflated_buf.length < inflated_end + decompressed) {
100+
byte[] foo = new byte[inflated_end + decompressed];
101+
System.arraycopy(inflated_buf, 0, foo, 0, inflated_end);
102+
inflated_buf = foo;
103+
}
104+
System.arraycopy(inflate_tmpbuf, 0, inflated_buf, inflated_end, decompressed);
105+
inflated_end += decompressed;
106+
length[0] = inflated_end;
107+
} else if (decompressed == 0) {
108+
if (inflated_end > buffer.length - start) {
109+
byte[] foo = new byte[inflated_end + start];
110+
System.arraycopy(buffer, 0, foo, 0, start);
111+
System.arraycopy(inflated_buf, 0, foo, start, inflated_end);
112+
buffer = foo;
113+
} else {
114+
System.arraycopy(inflated_buf, 0, buffer, start, inflated_end);
115+
}
116+
length[0] = inflated_end;
117+
return buffer;
133118
}
134-
length[0] = inflated_end;
135-
return buffer;
136-
default:
137-
System.err.println("uncompress: inflate returnd " + status);
119+
} catch (java.util.zip.DataFormatException e) {
120+
System.err.println("uncompress: inflate error: " + e.getMessage());
138121
return null;
139122
}
140123
}
124+
125+
if (inflated_end > buffer.length - start) {
126+
byte[] foo = new byte[inflated_end + start];
127+
System.arraycopy(buffer, 0, foo, 0, start);
128+
System.arraycopy(inflated_buf, 0, foo, start, inflated_end);
129+
buffer = foo;
130+
} else {
131+
System.arraycopy(inflated_buf, 0, buffer, start, inflated_end);
132+
}
133+
length[0] = inflated_end;
134+
return buffer;
141135
}
142136
}

src/main/java/com/trilead/ssh2/crypto/cipher/BlockCipherFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public static BlockCipher createCipher(String type, boolean encrypt, byte[] key,
6868
try
6969
{
7070
CipherEntry ce = getEntry(type);
71-
Class cc = Class.forName(ce.cipherClass);
72-
Constructor<BlockCipher> constructor = cc.getConstructor();
73-
BlockCipher bc = constructor.newInstance();
71+
Class<?> cc = Class.forName(ce.cipherClass);
72+
Constructor<?> constructor = cc.getConstructor();
73+
BlockCipher bc = (BlockCipher) constructor.newInstance();
7474
bc.init(encrypt, key, iv);
7575
return bc;
7676
}

src/main/java/com/trilead/ssh2/crypto/keys/Ed25519Provider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Ed25519Provider extends Provider {
2121
private static boolean sInitialized = false;
2222

2323
public Ed25519Provider() {
24-
super(NAME, 1.0, "Not for use elsewhere");
24+
super(NAME, "1.0", "Not for use elsewhere");
2525
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
2626
setup();
2727
return null;

src/main/java/com/trilead/ssh2/util/TimeoutService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class TimeoutService
2727
/**
2828
* A token that represents a timeout request.
2929
*/
30-
public static class TimeoutToken implements Comparable
30+
public static class TimeoutToken implements Comparable<TimeoutToken>
3131
{
3232
private long runTime;
3333
private Runnable handler;
@@ -38,9 +38,8 @@ private TimeoutToken(long runTime, Runnable handler)
3838
this.handler = handler;
3939
}
4040

41-
public int compareTo(Object o)
41+
public int compareTo(TimeoutToken t)
4242
{
43-
TimeoutToken t = (TimeoutToken) o;
4443
if (runTime > t.runTime)
4544
return 1;
4645
if (runTime == t.runTime)
@@ -105,7 +104,7 @@ public void run()
105104
}
106105

107106
/* The list object is also used for locking purposes */
108-
private static final LinkedList todolist = new LinkedList();
107+
private static final LinkedList<TimeoutToken> todolist = new LinkedList<>();
109108

110109
private static Thread timeoutThread = null;
111110

src/test/java/com/trilead/ssh2/AsyncSSHCompatibilityTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class AsyncSSHCompatibilityTest {
5454
@NotNull
5555
@Contract("_ -> new")
5656
private Connection withServer(@NotNull GenericContainer container) {
57-
return new Connection(container.getContainerIpAddress(), container.getMappedPort(8022));
57+
return new Connection(container.getHost(), container.getMappedPort(8022));
5858
}
5959

6060
private ConnectionInfo assertCanPasswordAuthenticate(GenericContainer server) throws IOException {

src/test/java/com/trilead/ssh2/DropbearCompatibilityTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public class DropbearCompatibilityTest {
5353
@NotNull
5454
@Contract("_ -> new")
5555
private Connection withServer(@NotNull GenericContainer container) {
56-
return new Connection(container.getContainerIpAddress(), container.getMappedPort(22));
56+
return new Connection(container.getHost(), container.getMappedPort(22));
5757
}
5858

5959
private static GenericContainer getBaseContainer() {
60-
return new GenericContainer(baseImage)
60+
return new GenericContainer<>(baseImage)
6161
.withExposedPorts(22)
6262
.withLogConsumer(logConsumer)
6363
.waitingFor(new LogMessageWaitStrategy()

src/test/java/com/trilead/ssh2/OpenSSHCompatibilityTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class OpenSSHCompatibilityTest {
4848
@NotNull
4949
@Contract("_ -> new")
5050
private Connection withServer(@NotNull GenericContainer<?> container) {
51-
return new Connection(container.getContainerIpAddress(), container.getMappedPort(22));
51+
return new Connection(container.getHost(), container.getMappedPort(22));
5252
}
5353

5454
private static GenericContainer<?> getBaseContainer() {

0 commit comments

Comments
 (0)