diff --git a/src/main/java/net/schmizz/sshj/SSHClient.java b/src/main/java/net/schmizz/sshj/SSHClient.java index deef70c4..4c84cdde 100644 --- a/src/main/java/net/schmizz/sshj/SSHClient.java +++ b/src/main/java/net/schmizz/sshj/SSHClient.java @@ -212,7 +212,7 @@ public class SSHClient public void auth(String username, Iterable methods) throws UserAuthException, TransportException { checkConnected(); - final Deque savedEx = new LinkedList<>(); + final Deque savedEx = new LinkedList(); for (AuthMethod method: methods) { method.setLoggerFactory(loggerFactory); try { @@ -334,7 +334,7 @@ public class SSHClient */ public void authPublickey(String username, Iterable keyProviders) throws UserAuthException, TransportException { - final List am = new LinkedList<>(); + final List am = new LinkedList(); for (KeyProvider kp : keyProviders) am.add(new AuthPublickey(kp)); auth(username, am); @@ -377,7 +377,7 @@ public class SSHClient */ public void authPublickey(String username, String... locations) throws UserAuthException, TransportException { - final List keyProviders = new LinkedList<>(); + final List keyProviders = new LinkedList(); for (String loc : locations) { try { log.debug("Attempting to load key from: {}", loc); @@ -407,7 +407,7 @@ public class SSHClient public void authGssApiWithMic(String username, LoginContext context, Oid supportedOid, Oid... supportedOids) throws UserAuthException, TransportException { // insert supportedOid to the front of the list since ordering matters - List oids = new ArrayList<>(Arrays.asList(supportedOids)); + List oids = new ArrayList(Arrays.asList(supportedOids)); oids.add(0, supportedOid); auth(username, new AuthGssApiWithMic(context, oids)); diff --git a/src/main/java/net/schmizz/sshj/sftp/SFTPClient.java b/src/main/java/net/schmizz/sshj/sftp/SFTPClient.java index a8539318..03ae541a 100644 --- a/src/main/java/net/schmizz/sshj/sftp/SFTPClient.java +++ b/src/main/java/net/schmizz/sshj/sftp/SFTPClient.java @@ -86,7 +86,7 @@ public class SFTPClient public void mkdirs(String path) throws IOException { - final Deque dirsToMake = new LinkedList<>(); + final Deque dirsToMake = new LinkedList(); for (PathComponents current = engine.getPathHelper().getComponents(path); ; current = engine.getPathHelper().getComponents(current.getParent())) { final FileAttributes attrs = statExistence(current.getPath()); diff --git a/src/main/java/net/schmizz/sshj/sftp/SFTPFileTransfer.java b/src/main/java/net/schmizz/sshj/sftp/SFTPFileTransfer.java index f23314e9..e84094b5 100644 --- a/src/main/java/net/schmizz/sshj/sftp/SFTPFileTransfer.java +++ b/src/main/java/net/schmizz/sshj/sftp/SFTPFileTransfer.java @@ -229,14 +229,36 @@ public class SFTPFileTransfer final String remote) throws IOException { final String adjusted = prepareFile(local, remote); - try (RemoteFile rf = engine.open(adjusted, EnumSet.of(OpenMode.WRITE, OpenMode.CREAT, OpenMode.TRUNC))) { - try (InputStream fis = local.getInputStream(); - RemoteFile.RemoteFileOutputStream rfos = rf.new RemoteFileOutputStream(0, 16)) { - new StreamCopier(fis, rfos, engine.getLoggerFactory()) - .bufSize(engine.getSubsystem().getRemoteMaxPacketSize() - rf.getOutgoingPacketOverhead()) - .keepFlushing(false) - .listener(listener) - .copy(); + RemoteFile rf = null; + InputStream fis = null; + RemoteFile.RemoteFileOutputStream rfos = null; + try { + rf = engine.open(adjusted, EnumSet.of(OpenMode.WRITE, OpenMode.CREAT, OpenMode.TRUNC)); + fis = local.getInputStream(); + rfos = rf.new RemoteFileOutputStream(0, 16); + new StreamCopier(fis, rfos, engine.getLoggerFactory()) + .bufSize(engine.getSubsystem().getRemoteMaxPacketSize() - rf.getOutgoingPacketOverhead()) + .keepFlushing(false) + .listener(listener) + .copy(); + } finally { + if (rf != null) { + try { + rf.close(); + } catch (IOException e) { + } + } + if (fis != null) { + try { + fis.close(); + } catch (IOException e) { + } + } + if (rfos != null) { + try { + rfos.close(); + } catch (IOException e) { + } } } return adjusted;