1 package org.apache.maven.shared.utils;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.FileInputStream;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.util.Properties;
27
28 import javax.annotation.Nonnull;
29 import javax.annotation.Nullable;
30
31 import org.apache.maven.shared.utils.io.IOUtil;
32
33
34
35
36 public class PropertyUtils
37 {
38
39
40
41
42 public PropertyUtils()
43 {
44
45 }
46
47
48
49
50
51 public static java.util.Properties loadProperties( @Nonnull java.net.URL url )
52 {
53 try
54 {
55 return loadProperties( url.openStream() );
56 }
57 catch ( Exception e )
58 {
59
60 }
61 return null;
62 }
63
64
65
66
67
68 public static Properties loadProperties( @Nonnull File file )
69 {
70 try
71 {
72 return loadProperties( new FileInputStream( file ) );
73 }
74 catch ( Exception e )
75 {
76
77 }
78 return null;
79 }
80
81
82
83
84
85 public static Properties loadProperties( @Nullable InputStream is )
86 {
87 try
88 {
89
90 Properties result = new Properties();
91 if ( is != null )
92 {
93 try
94 {
95 result.load( is );
96 }
97 catch ( IOException e )
98 {
99
100 }
101 }
102 return result;
103 }
104 catch ( Exception e )
105 {
106
107 }
108 finally
109 {
110 IOUtil.close( is );
111 }
112 return null;
113 }
114
115 }