karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [2/4] karaf git commit: Reformat
Date Wed, 02 Aug 2017 08:14:19 GMT
Reformat


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/851dc904
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/851dc904
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/851dc904

Branch: refs/heads/master
Commit: 851dc904cba472fb2f5e5f8a006059dd7aead69e
Parents: ae75fee
Author: Christian Schneider <chris@die-schneider.net>
Authored: Tue Aug 1 14:35:18 2017 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Wed Aug 2 10:14:10 2017 +0200

----------------------------------------------------------------------
 .../karaf/shell/ssh/KnownHostsManager.java      | 187 +++++++++----------
 1 file changed, 93 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/851dc904/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KnownHostsManager.java
----------------------------------------------------------------------
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KnownHostsManager.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KnownHostsManager.java
index ad0ed29..2c73b6d 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KnownHostsManager.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KnownHostsManager.java
@@ -38,105 +38,104 @@ import org.slf4j.LoggerFactory;
 import java.util.Base64;
 
 public class KnownHostsManager {
-	Logger LOG = LoggerFactory.getLogger(KnownHostsManager.class);
-	
-	private final File knownHosts;
+    Logger LOG = LoggerFactory.getLogger(KnownHostsManager.class);
 
-	public KnownHostsManager(File knownHosts) {
-		this.knownHosts = knownHosts;
-		this.knownHosts.getParentFile().mkdirs();
-		if (!this.knownHosts.exists()) {
-			try {
-				knownHosts.createNewFile();
-			} catch (IOException e) {
-				throw new RuntimeException("Error creating file for known hosts at: " + knownHosts);
-			}
-		}
-	}
-	
-	public PublicKey getKnownKey(SocketAddress remoteAddress, String checkAlgorithm) throws
InvalidKeySpecException {
-		FileReader fr = null;
-		BufferedReader reader = null;
-		try {
-			fr = new FileReader(knownHosts);
-			reader = new BufferedReader(fr);
-			return getKnownKeyInternal(remoteAddress, checkAlgorithm, reader);
-		} catch (IOException e) {
-			throw new RuntimeException("Error reading known_hosts " + knownHosts, e);
-		} catch (NoSuchAlgorithmException e) {
-			throw new RuntimeException(e);
-		} finally {
-			close(reader);
-			close(fr);
-		}
-	}
+    private final File knownHosts;
 
-	private PublicKey getKnownKeyInternal(SocketAddress remoteAddress,
-			String checkAlgorithm, BufferedReader reader) throws IOException,
-			NoSuchAlgorithmException, InvalidKeySpecException {
-		String checkServerAddress = getAddressString(remoteAddress);
+    public KnownHostsManager(File knownHosts) {
+        this.knownHosts = knownHosts;
+        this.knownHosts.getParentFile().mkdirs();
+        if (!this.knownHosts.exists()) {
+            try {
+                knownHosts.createNewFile();
+            } catch (IOException e) {
+                throw new RuntimeException("Error creating file for known hosts at: " + knownHosts);
+            }
+        }
+    }
 
-		String line = reader.readLine();
-		while (line != null) {
-			String[] lineParts = line.split(" ");
-			String serverAddress = lineParts[0];
-			String algorithm = lineParts[1];
-			if (checkServerAddress.equals(serverAddress) && checkAlgorithm.equals(algorithm))
{
-				byte[] key = Base64.getDecoder().decode(lineParts[2].getBytes());
-				KeyFactory keyFactory = KeyFactory.getInstance(algorithm);
-				X509EncodedKeySpec keySpec = new X509EncodedKeySpec(key);
-				return keyFactory.generatePublic(keySpec);
-			}
-			line = reader.readLine();
-		}
-		return null;
-	}
-	
-	public void storeKeyForHost(SocketAddress remoteAddress,
-			PublicKey serverKey) {
-		FileWriter ps = null;
-		BufferedWriter bw = null;
-		try {
-			ps = new FileWriter(knownHosts, true);
-			bw = new BufferedWriter(ps);
-			writeKey(bw, remoteAddress, serverKey);
-		} catch (Exception e) {
-			throw new RuntimeException("Error storing key for host" + remoteAddress, e);
-		} finally {
-			close(bw);
-			close(ps);
-		}
-	}
+    public PublicKey getKnownKey(SocketAddress remoteAddress, String checkAlgorithm)
+        throws InvalidKeySpecException {
+        FileReader fr = null;
+        BufferedReader reader = null;
+        try {
+            fr = new FileReader(knownHosts);
+            reader = new BufferedReader(fr);
+            return getKnownKeyInternal(remoteAddress, checkAlgorithm, reader);
+        } catch (IOException e) {
+            throw new RuntimeException("Error reading known_hosts " + knownHosts, e);
+        } catch (NoSuchAlgorithmException e) {
+            throw new RuntimeException(e);
+        } finally {
+            close(reader);
+            close(fr);
+        }
+    }
 
-	private void writeKey(BufferedWriter bw, SocketAddress remoteAddress,
-			PublicKey serverKey) throws IOException {
-		bw.append(getAddressString(remoteAddress));
-		bw.append(" ");
-		bw.append(serverKey.getAlgorithm());
-		bw.append(" ");
-		serverKey.getEncoded();
-		bw.append(new String(Base64.getEncoder().encode(serverKey.getEncoded()), "UTF-8"));
+    private PublicKey getKnownKeyInternal(SocketAddress remoteAddress, String checkAlgorithm,
+                                          BufferedReader reader)
+        throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
+        String checkServerAddress = getAddressString(remoteAddress);
+
+        String line = reader.readLine();
+        while (line != null) {
+            String[] lineParts = line.split(" ");
+            String serverAddress = lineParts[0];
+            String algorithm = lineParts[1];
+            if (checkServerAddress.equals(serverAddress) && checkAlgorithm.equals(algorithm))
{
+                byte[] key = Base64.getDecoder().decode(lineParts[2].getBytes());
+                KeyFactory keyFactory = KeyFactory.getInstance(algorithm);
+                X509EncodedKeySpec keySpec = new X509EncodedKeySpec(key);
+                return keyFactory.generatePublic(keySpec);
+            }
+            line = reader.readLine();
+        }
+        return null;
+    }
+
+    public void storeKeyForHost(SocketAddress remoteAddress, PublicKey serverKey) {
+        FileWriter ps = null;
+        BufferedWriter bw = null;
+        try {
+            ps = new FileWriter(knownHosts, true);
+            bw = new BufferedWriter(ps);
+            writeKey(bw, remoteAddress, serverKey);
+        } catch (Exception e) {
+            throw new RuntimeException("Error storing key for host" + remoteAddress, e);
+        } finally {
+            close(bw);
+            close(ps);
+        }
+    }
+
+    private void writeKey(BufferedWriter bw, SocketAddress remoteAddress, PublicKey serverKey)
+        throws IOException {
+        bw.append(getAddressString(remoteAddress));
+        bw.append(" ");
+        bw.append(serverKey.getAlgorithm());
+        bw.append(" ");
+        serverKey.getEncoded();
+        bw.append(new String(Base64.getEncoder().encode(serverKey.getEncoded()), "UTF-8"));
         bw.append("\n");
-	}
+    }
+
+    String getAddressString(SocketAddress address) {
+        if (address instanceof InetSocketAddress) {
+            InetSocketAddress inetAddress = (InetSocketAddress)address;
+            return String.format("%s,%s:%s", inetAddress.getHostName(),
+                                 inetAddress.getAddress().getHostAddress(), inetAddress.getPort());
+        }
+        return "";
+    }
 
-	String getAddressString(SocketAddress address) {
-		if (address instanceof InetSocketAddress) {
-			InetSocketAddress inetAddress = (InetSocketAddress) address;
-			return String.format("%s,%s:%s", inetAddress.getHostName(),
-					inetAddress.getAddress().getHostAddress(),
-					inetAddress.getPort());
-		}
-		return "";
-	}
-	
-	private void close(Closeable closeable) {
-		if (closeable != null) {
-			try {
-				closeable.close();
-			} catch (IOException e) {
-				LOG.warn("Error closing: " + e.getMessage(), e);
-			}
-		}
-	}
+    private void close(Closeable closeable) {
+        if (closeable != null) {
+            try {
+                closeable.close();
+            } catch (IOException e) {
+                LOG.warn("Error closing: " + e.getMessage(), e);
+            }
+        }
+    }
 
 }


Mime
View raw message