EMMA Coverage Report (generated Fri Jan 30 13:20:29 EST 2009)
[all classes][org.springframework.batch.item.util]

COVERAGE SUMMARY FOR SOURCE FILE [FileUtils.java]

nameclass, %method, %block, %line, %
FileUtils.java100% (1/1)50%  (1/2)96%  (81/84)94%  (16/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FileUtils100% (1/1)50%  (1/2)96%  (81/84)94%  (16/17)
FileUtils (): void 0%   (0/1)0%   (0/3)0%   (0/1)
setUpOutputFile (File, boolean, boolean): void 100% (1/1)100% (81/81)100% (16/16)

1package org.springframework.batch.item.util;
2 
3import java.io.File;
4import java.io.IOException;
5 
6import org.springframework.batch.item.ItemStreamException;
7import org.springframework.dao.DataAccessResourceFailureException;
8import org.springframework.util.Assert;
9 
10/**
11 * Utility methods for files used in batch processing.
12 *
13 * @author Peter Zozom
14 */
15public class FileUtils {
16 
17        // forbids instantiation
18        private FileUtils() {}
19 
20        /**
21         * Set up output file for batch processing. This method implements common logic for
22         * handling output files when starting or restarting job/step.
23         * When starting output file processing, method creates/overwrites new file.
24         * When restarting output file processing, method checks whether file is writable.
25         *
26         * @param file file to be set up
27         * @param restarted TRUE signalizes that we are restarting output file processing
28         * @param overwriteOutputFile If set to TRUE, output file will be overwritten
29         * (this flag is ignored when processing is restart)
30         *
31         * @throws IllegalArgumentException when file is NULL
32         * @throws IllegalStateException when staring output file processing, file exists and
33         * flag "shouldDeleteExisting" is set to FALSE
34         * @throws DataAccessResourceFailureException when unable to create file or file is not writable
35         */
36        public static void setUpOutputFile(File file, boolean restarted,
37                        boolean overwriteOutputFile) {
38 
39                Assert.notNull(file);
40 
41                try {
42                        if (!restarted) {
43                                if (file.exists()) {
44                                        if(!overwriteOutputFile){
45                                                throw new  ItemStreamException("File already exists: ["
46                                                + file.getAbsolutePath() + "]");
47                                        }
48                                        file.delete();
49                                }
50 
51                                if (file.getParent() != null ) {
52                                        new File(file.getParent()).mkdirs();
53                                }
54                                file.createNewFile();
55                                Assert.state(file.exists(), "Output file must exist");
56                        }
57                } catch (IOException ioe) {
58                        throw new ItemStreamException(
59                                        "Unable to create file: [" + file.getAbsolutePath() + "]",
60                                        ioe);
61                }
62 
63                if (!file.canWrite()) {
64                        throw new ItemStreamException(
65                                        "File is not writable: [" + file.getAbsolutePath() + "]");
66                }
67        }
68}

[all classes][org.springframework.batch.item.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov