4062 |
25 Aug 16 |
nicklas |
1 |
package net.sf.basedb.opengrid; |
4062 |
25 Aug 16 |
nicklas |
2 |
|
4067 |
02 Sep 16 |
nicklas |
3 |
import java.io.Closeable; |
4067 |
02 Sep 16 |
nicklas |
4 |
import java.io.IOException; |
4067 |
02 Sep 16 |
nicklas |
5 |
|
4062 |
25 Aug 16 |
nicklas |
6 |
/** |
4067 |
02 Sep 16 |
nicklas |
Global constants and utility functions for the Open Grid Scheduler |
4067 |
02 Sep 16 |
nicklas |
service package. |
4067 |
02 Sep 16 |
nicklas |
9 |
|
4062 |
25 Aug 16 |
nicklas |
@since 1.0 |
4062 |
25 Aug 16 |
nicklas |
11 |
*/ |
4067 |
02 Sep 16 |
nicklas |
12 |
public final class OpenGrid |
4062 |
25 Aug 16 |
nicklas |
13 |
{ |
4062 |
25 Aug 16 |
nicklas |
14 |
|
4062 |
25 Aug 16 |
nicklas |
15 |
/** |
4062 |
25 Aug 16 |
nicklas |
The current version of this package. |
4062 |
25 Aug 16 |
nicklas |
17 |
*/ |
7385 |
24 Oct 23 |
nicklas |
18 |
public static final String VERSION = "1.13-dev"; |
4062 |
25 Aug 16 |
nicklas |
19 |
|
4067 |
02 Sep 16 |
nicklas |
20 |
/** |
4067 |
02 Sep 16 |
nicklas |
Exception-safe method for closing closeable object. |
4067 |
02 Sep 16 |
nicklas |
Swallows all exceptions and allows a null paramater. |
4067 |
02 Sep 16 |
nicklas |
23 |
*/ |
4067 |
02 Sep 16 |
nicklas |
24 |
public static void close(Closeable closeable) |
4067 |
02 Sep 16 |
nicklas |
25 |
{ |
4067 |
02 Sep 16 |
nicklas |
26 |
if (closeable != null) |
4067 |
02 Sep 16 |
nicklas |
27 |
{ |
4067 |
02 Sep 16 |
nicklas |
28 |
try |
4067 |
02 Sep 16 |
nicklas |
29 |
{ |
4067 |
02 Sep 16 |
nicklas |
30 |
closeable.close(); |
4067 |
02 Sep 16 |
nicklas |
31 |
} |
4067 |
02 Sep 16 |
nicklas |
32 |
catch (IOException ex) |
4067 |
02 Sep 16 |
nicklas |
33 |
{} |
4067 |
02 Sep 16 |
nicklas |
34 |
} |
4067 |
02 Sep 16 |
nicklas |
35 |
} |
4062 |
25 Aug 16 |
nicklas |
36 |
|
4130 |
26 Sep 16 |
nicklas |
37 |
/** |
4130 |
26 Sep 16 |
nicklas |
Checks that a value is allowed as a file/directory name. |
4130 |
26 Sep 16 |
nicklas |
We only allow letters, numbers, dot, hyphen and underscore. |
4130 |
26 Sep 16 |
nicklas |
It may not contain a double dot (..). |
4130 |
26 Sep 16 |
nicklas |
@return The given filename if it is valid |
4130 |
26 Sep 16 |
nicklas |
@throws IllegalArgumentException If the filename is not valid |
4130 |
26 Sep 16 |
nicklas |
43 |
*/ |
4130 |
26 Sep 16 |
nicklas |
44 |
public static String checkValidFilename(String filename) |
4130 |
26 Sep 16 |
nicklas |
45 |
{ |
4130 |
26 Sep 16 |
nicklas |
46 |
if (filename == null) |
4130 |
26 Sep 16 |
nicklas |
47 |
{ |
4130 |
26 Sep 16 |
nicklas |
48 |
throw new NullPointerException("filename"); |
4130 |
26 Sep 16 |
nicklas |
49 |
} |
4130 |
26 Sep 16 |
nicklas |
50 |
if (!filename.matches("[a-zA-Z0-9._\\-]+")) |
4130 |
26 Sep 16 |
nicklas |
51 |
{ |
4130 |
26 Sep 16 |
nicklas |
52 |
throw new IllegalArgumentException("File name may only contain [a-zA-Z0-9._-]: " + filename); |
4130 |
26 Sep 16 |
nicklas |
53 |
} |
4130 |
26 Sep 16 |
nicklas |
// Not allowed to move up to parent directory |
4130 |
26 Sep 16 |
nicklas |
55 |
if (filename.contains("..")) |
4130 |
26 Sep 16 |
nicklas |
56 |
{ |
4130 |
26 Sep 16 |
nicklas |
57 |
throw new IllegalArgumentException("File name may not contain '..': " + filename); |
4130 |
26 Sep 16 |
nicklas |
58 |
} |
4130 |
26 Sep 16 |
nicklas |
59 |
return filename; |
4130 |
26 Sep 16 |
nicklas |
60 |
} |
4130 |
26 Sep 16 |
nicklas |
61 |
|
4062 |
25 Aug 16 |
nicklas |
62 |
} |