01: /*
02: * Copyright (C) The Apache Software Foundation. All rights reserved.
03: *
04: * This software is published under the terms of the Apache Software License
05: * version 1.1, a copy of which has been included with this distribution in
06: * the LICENSE file.
07: */
08: package org.jivesoftware.util.log.output.io.rotate;
09:
10: import java.io.File;
11:
12: /**
13: * strategy for naming log files based on appending revolving suffix.
14: * <p/>
15: * Heavily odified by Bruce Ritchie (Jive Software) to rotate along
16: * the following strategy:
17: * <p/>
18: * current log file will always be the base File name
19: * the next oldest file will be the _1 file
20: * the next oldest file will be the _2 file
21: * etc.
22: *
23: * @author <a href="mailto:bh22351@i-one.at">Bernhard Huber</a>
24: */
25: public class ExpandingFileStrategy implements FileStrategy {
26:
27: ///the base file name.
28: private String baseFileName;
29:
30: public ExpandingFileStrategy(final String baseFileName) {
31:
32: this .baseFileName = baseFileName;
33: }
34:
35: public File currentFile() {
36: return new File(baseFileName);
37: }
38:
39: /**
40: * Calculate the real file name from the base filename.
41: *
42: * @return File the calculated file name
43: */
44: public File nextFile() {
45: // go through all the possible filenames and delete/rename as necessary
46: for (int i = 0; true; i++) {
47: File test = new File(baseFileName.substring(0, baseFileName
48: .lastIndexOf('.'))
49: + "_"
50: + i
51: + baseFileName.substring(baseFileName
52: .lastIndexOf('.')));
53:
54: if (test.exists()) {
55: continue;
56: } else {
57: return test;
58: }
59: }
60: }
61: }
|