Mercurial Hosting > luan
annotate src/goodjava/io/IoUtils.java @ 1506:d80395468b4e
ssl security in code
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 15 May 2020 18:29:47 -0600 |
parents | e66e3d50b289 |
children | 86c5e7000ecf |
rev | line source |
---|---|
1473 | 1 package goodjava.io; |
2 | |
3 import java.io.File; | |
1493 | 4 import java.io.InputStream; |
5 import java.io.OutputStream; | |
1473 | 6 import java.io.IOException; |
7 import java.nio.file.Files; | |
1506
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
8 import java.security.Security; |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
9 import javax.net.ssl.SSLSocketFactory; |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
10 import javax.net.ssl.SSLServerSocketFactory; |
1473 | 11 |
12 | |
13 public final class IoUtils { | |
14 private IoUtils() {} // never | |
15 | |
16 public static void move( File from, File to ) throws IOException { | |
17 Files.move( from.toPath(), to.toPath() ); | |
18 } | |
19 | |
20 public static void delete(File file) throws IOException { | |
21 Files.deleteIfExists( file.toPath() ); | |
22 } | |
1475 | 23 |
1501 | 24 public static void mkdirs(File file) throws IOException { |
25 Files.createDirectories( file.toPath() ); | |
26 } | |
27 | |
1475 | 28 public static boolean isSymbolicLink(File file) { |
29 return Files.isSymbolicLink(file.toPath()); | |
30 } | |
31 | |
32 public static void deleteRecursively(File file) throws IOException { | |
33 if( file.isDirectory() && !isSymbolicLink(file) ) { | |
34 for( File f : file.listFiles() ) { | |
35 deleteRecursively(f); | |
36 } | |
37 } | |
38 delete(file); | |
39 } | |
40 | |
1497 | 41 public static void link(File existing,File link) throws IOException { |
42 Files.createLink( link.toPath(), existing.toPath() ); | |
43 } | |
44 | |
45 public static void symlink(File existing,File link) throws IOException { | |
46 Files.createSymbolicLink( link.toPath(), existing.toPath() ); | |
1488 | 47 } |
48 | |
1494 | 49 public static void copyAll(InputStream in,OutputStream out) |
1493 | 50 throws IOException |
51 { | |
52 byte[] a = new byte[8192]; | |
53 int n; | |
54 while( (n=in.read(a)) != -1 ) { | |
55 out.write(a,0,n); | |
56 } | |
1499 | 57 in.close(); |
1493 | 58 } |
59 | |
1506
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
60 |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
61 static { |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
62 // undo restrictions of modern scum |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
63 Security.setProperty("jdk.tls.disabledAlgorithms","SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC"); |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
64 } |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
65 |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
66 public static SSLSocketFactory getSSLSocketFactory() { |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
67 return (SSLSocketFactory)SSLSocketFactory.getDefault(); |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
68 } |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
69 |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
70 public static SSLServerSocketFactory getSSLServerSocketFactory() { |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
71 return (SSLServerSocketFactory)SSLServerSocketFactory.getDefault(); |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
72 } |
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1501
diff
changeset
|
73 |
1473 | 74 } |