Subversion Repositories XServices

Rev

Rev 150 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 150 Rev 170
1
/*
1
/*
2
 *   Copyright 2014 Brian Rosenberger (Brutex Network)
2
 *   Copyright 2014 Brian Rosenberger (Brutex Network)
3
 *
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
6
 *   You may obtain a copy of the License at
7
 *
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
14
 *   limitations under the License.
15
 */
15
 */
16
package net.brutex.emitter.util;
16
package net.brutex.emitter.util;
17
 
17
 
18
import java.io.File;
18
import java.io.File;
19
 
19
 
20
import org.apache.log4j.Logger;
20
import org.apache.log4j.Logger;
21
 
21
 
22
/**
22
/**
23
 * The Class EmitterUtil.
23
 * The Class EmitterUtil.
24
 *
24
 *
25
 * @author Brian Rosenberger, bru(at)brutex.de
25
 * @author Brian Rosenberger, bru(at)brutex.de
26
 */
26
 */
27
public final class EmitterUtil {
27
public final class EmitterUtil {
28
	
28
	
29
 
29
 
30
	private static Logger logger = Logger.getLogger(EmitterUtil.class);
30
	private static Logger logger = Logger.getLogger(EmitterUtil.class);
31
 
31
 
32
	
32
	
33
	/**
33
	/**
34
	 * Check if the file exists and is readable. 
34
	 * Check if the file exists and is readable. 
35
	 * 
35
	 * 
36
	 * @param file The file to check
36
	 * @param file The file to check
37
	 * @param isWritable also check if file is writable
37
	 * @param isWritable also check if file is writable
38
	 * @param isExecutable also check if file is executable 
38
	 * @param isExecutable also check if file is executable 
39
	 * @return 
39
	 * @return 
40
	 */
40
	 */
41
	public static boolean verifyFile(String file, boolean isWritable, boolean isExecutable) {
41
	public static boolean verifyFile(String file, boolean isWritable, boolean isExecutable) {
42
		logger.debug(String.format("Verifying file '%s'.", file));
42
		logger.debug(String.format("Verifying file '%s'.", file));
43
		File f = new File(file);
43
		File f = new File(file);
44
		String fn = f.getAbsolutePath();
44
		String fn = f.getAbsolutePath();
45
		if(f.exists() && f.isFile()) {
45
		if(f.exists() && f.isFile()) {
46
			if(isWritable && !f.canWrite()) {
46
			if(isWritable && !f.canWrite()) {
47
				logger.error(String.format("Cannot write to file '%s'.", fn));
47
				logger.error(String.format("Cannot write to file '%s'.", fn));
48
				return false;
48
				return false;
49
			}
49
			}
50
			if(isExecutable && !f.canExecute()) {
50
			if(isExecutable && !f.canExecute()) {
51
				logger.error(String.format("Cannot execute file '%s'.", fn));
51
				logger.error(String.format("Cannot execute file '%s'.", fn));
52
				return false;
52
				return false;
53
			}
53
			}
54
		return true;
54
		return true;
55
		}
55
		}
56
		logger.error(String.format("Cannot read file '%s'.", fn));
56
		logger.error(String.format("Cannot read file '%s'.", fn));
57
		return false;
57
		return false;
58
	}
58
	}
-
 
59
	
59
 
60
 
60
}
61
}