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 import java.io.FileInputStream;
23 import java.io.IOException;
24 import java.util.Properties;
25 import org.apache.maven.shared.utils.io.IOUtil;
26
27 import javax.annotation.Nonnull;
28 import javax.annotation.Nullable;
29
30 /**
31 *
32 */
33 public class PropertyUtils
34 {
35
36 public PropertyUtils()
37 {
38 // should throw new IllegalAccessError( "Utility class" );
39 }
40
41 public static java.util.Properties loadProperties( @Nonnull java.net.URL url )
42 {
43 try
44 {
45 return loadProperties( url.openStream() );
46 }
47 catch ( Exception e )
48 {
49 // ignore
50 }
51 return null;
52 }
53
54 public static java.util.Properties loadProperties( @Nonnull java.io.File file )
55 {
56 try
57 {
58 return loadProperties( new FileInputStream( file ) );
59 }
60 catch ( Exception e )
61 {
62 // ignore
63 }
64 return null;
65 }
66
67 public static java.util.Properties loadProperties( @Nullable java.io.InputStream is )
68 {
69 try
70 {
71 // to make this the same behaviour as the others we should really return null on any error
72 Properties result = new Properties();
73 if ( is != null )
74 {
75 try
76 {
77 result.load( is );
78 }
79 catch ( IOException e )
80 {
81 // ignore
82 }
83 }
84 return result;
85 }
86 catch ( Exception e )
87 {
88 // ignore
89 }
90 finally
91 {
92 IOUtil.close( is );
93 }
94 return null;
95 }
96
97 }