OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 180
Line 51... Line 51...
51
        }
51
        }
52
        return res;
52
        return res;
53
    }
53
    }
54
 
54
 
55
    public static final Properties createFromFile(final File f) throws IOException {
55
    public static final Properties createFromFile(final File f) throws IOException {
56
        return create(new BufferedInputStream(new FileInputStream(f)));
56
        try (final InputStream stream = new BufferedInputStream(new FileInputStream(f))) {
-
 
57
            return create(stream);
-
 
58
        }
57
    }
59
    }
58
 
60
 
59
    public static final Properties createFromResource(final Class<?> ctxt, final String rsrc) throws IOException {
61
    public static final Properties createFromResource(final Class<?> ctxt, final String rsrc) throws IOException {
60
        return create(ctxt.getResourceAsStream(rsrc));
62
        try (final InputStream stream = ctxt.getResourceAsStream(rsrc)) {
-
 
63
            return create(stream);
61
    }
64
        }
62
 
-
 
63
    protected static final Properties create(final InputStream stream) throws IOException {
-
 
64
        return create(stream, true);
-
 
65
    }
65
    }
66
 
66
 
67
    public static final Properties create(final InputStream stream, final boolean close) throws IOException {
67
    public static final Properties create(final InputStream stream) throws IOException {
68
        if (stream != null) {
68
        if (stream != null) {
69
            try {
-
 
70
                final Properties res = new Properties();
69
            final Properties res = new Properties();
71
                res.load(stream);
70
            res.load(stream);
72
                return res;
71
            return res;
73
            } finally {
-
 
74
                if (close)
-
 
75
                    stream.close();
-
 
76
            }
-
 
77
        } else {
72
        } else {
78
            return null;
73
            return null;
79
        }
74
        }
80
    }
75
    }
81
 
76