1 package org.apache.maven.shared.utils;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22
23 import java.io.FileInputStream;
24 import java.io.IOException;
25 import java.util.Properties;
26 import org.apache.maven.shared.utils.io.IOUtil;
27
28 import javax.annotation.Nonnull;
29 import javax.annotation.Nullable;
30
31 public class PropertyUtils
32 {
33
34 public PropertyUtils()
35 {
36 // should throw new IllegalAccessError( "Utility class" );
37 }
38
39 public static java.util.Properties loadProperties( @Nonnull java.net.URL url )
40 {
41 try
42 {
43 return loadProperties( url.openStream() );
44 }
45 catch ( Exception e )
46 {
47 // ignore
48 }
49 return null;
50 }
51
52 public static java.util.Properties loadProperties( @Nonnull java.io.File file )
53 {
54 try
55 {
56 return loadProperties( new FileInputStream( file ) );
57 }
58 catch ( Exception e )
59 {
60 // ignore
61 }
62 return null;
63 }
64
65 public static java.util.Properties loadProperties( @Nullable java.io.InputStream is )
66 {
67 try
68 {
69 // to make this the same behaviour as the others we should really return null on any error
70 Properties result = new Properties();
71 if ( is != null )
72 {
73 try
74 {
75 result.load( is );
76 }
77 catch ( IOException e )
78 {
79 // ignore
80 }
81 }
82 return result;
83 }
84 catch ( Exception e )
85 {
86 // ignore
87 }
88 finally
89 {
90 IOUtil.close( is );
91 }
92 return null;
93 }
94
95 }