Make Java-6 compatible.

This commit is contained in:
David A. Solin
2016-08-26 13:26:01 -05:00
parent 71498ad961
commit f2bfe9bfcf
3 changed files with 35 additions and 13 deletions

View File

@@ -212,7 +212,7 @@ public class SSHClient
public void auth(String username, Iterable<AuthMethod> methods) public void auth(String username, Iterable<AuthMethod> methods)
throws UserAuthException, TransportException { throws UserAuthException, TransportException {
checkConnected(); checkConnected();
final Deque<UserAuthException> savedEx = new LinkedList<>(); final Deque<UserAuthException> savedEx = new LinkedList<UserAuthException>();
for (AuthMethod method: methods) { for (AuthMethod method: methods) {
method.setLoggerFactory(loggerFactory); method.setLoggerFactory(loggerFactory);
try { try {
@@ -334,7 +334,7 @@ public class SSHClient
*/ */
public void authPublickey(String username, Iterable<KeyProvider> keyProviders) public void authPublickey(String username, Iterable<KeyProvider> keyProviders)
throws UserAuthException, TransportException { throws UserAuthException, TransportException {
final List<AuthMethod> am = new LinkedList<>(); final List<AuthMethod> am = new LinkedList<AuthMethod>();
for (KeyProvider kp : keyProviders) for (KeyProvider kp : keyProviders)
am.add(new AuthPublickey(kp)); am.add(new AuthPublickey(kp));
auth(username, am); auth(username, am);
@@ -377,7 +377,7 @@ public class SSHClient
*/ */
public void authPublickey(String username, String... locations) public void authPublickey(String username, String... locations)
throws UserAuthException, TransportException { throws UserAuthException, TransportException {
final List<KeyProvider> keyProviders = new LinkedList<>(); final List<KeyProvider> keyProviders = new LinkedList<KeyProvider>();
for (String loc : locations) { for (String loc : locations) {
try { try {
log.debug("Attempting to load key from: {}", loc); 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) public void authGssApiWithMic(String username, LoginContext context, Oid supportedOid, Oid... supportedOids)
throws UserAuthException, TransportException { throws UserAuthException, TransportException {
// insert supportedOid to the front of the list since ordering matters // insert supportedOid to the front of the list since ordering matters
List<Oid> oids = new ArrayList<>(Arrays.asList(supportedOids)); List<Oid> oids = new ArrayList<Oid>(Arrays.asList(supportedOids));
oids.add(0, supportedOid); oids.add(0, supportedOid);
auth(username, new AuthGssApiWithMic(context, oids)); auth(username, new AuthGssApiWithMic(context, oids));

View File

@@ -86,7 +86,7 @@ public class SFTPClient
public void mkdirs(String path) public void mkdirs(String path)
throws IOException { throws IOException {
final Deque<String> dirsToMake = new LinkedList<>(); final Deque<String> dirsToMake = new LinkedList<String>();
for (PathComponents current = engine.getPathHelper().getComponents(path); ; for (PathComponents current = engine.getPathHelper().getComponents(path); ;
current = engine.getPathHelper().getComponents(current.getParent())) { current = engine.getPathHelper().getComponents(current.getParent())) {
final FileAttributes attrs = statExistence(current.getPath()); final FileAttributes attrs = statExistence(current.getPath());

View File

@@ -229,14 +229,36 @@ public class SFTPFileTransfer
final String remote) final String remote)
throws IOException { throws IOException {
final String adjusted = prepareFile(local, remote); final String adjusted = prepareFile(local, remote);
try (RemoteFile rf = engine.open(adjusted, EnumSet.of(OpenMode.WRITE, OpenMode.CREAT, OpenMode.TRUNC))) { RemoteFile rf = null;
try (InputStream fis = local.getInputStream(); InputStream fis = null;
RemoteFile.RemoteFileOutputStream rfos = rf.new RemoteFileOutputStream(0, 16)) { RemoteFile.RemoteFileOutputStream rfos = null;
new StreamCopier(fis, rfos, engine.getLoggerFactory()) try {
.bufSize(engine.getSubsystem().getRemoteMaxPacketSize() - rf.getOutgoingPacketOverhead()) rf = engine.open(adjusted, EnumSet.of(OpenMode.WRITE, OpenMode.CREAT, OpenMode.TRUNC));
.keepFlushing(false) fis = local.getInputStream();
.listener(listener) rfos = rf.new RemoteFileOutputStream(0, 16);
.copy(); 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; return adjusted;