12// maxFileSize more bytes are written
13nextRollover = size + maxFileSize;
14}
15LogLog.debug("maxBackupIndex=" + maxBackupIndex);
16
17boolean renameSucceeded = true;
18// If maxBackups <= 0, then there is no file renaming to be done.
19if (maxBackupIndex > 0) {
20// Delete the oldest file, to keep Windows happy.
21file = new File(fileName + '.' + maxBackupIndex);
22if (file.exists())
23renameSucceeded = file.delete();
24
25// Map {(maxBackupIndex - 1), , 2, 1} to {maxBackupIndex, , 3,
26// 2}
27for (int i = maxBackupIndex - 1; i >= 1 && renameSucceeded; i--) {
28file = new File(fileName + "." + i);
29if (file.exists()) {
30target = new File(fileName + '.' + (i + 1));
31LogLog.debug("Renaming file " + file + " to " + target);
32renameSucceeded = file.renameTo(target);
33}
34}
35
36if (renameSucceeded) {
37// Rename fileName to fileName.1
38target = new File(fileName + "." + 1);
39this.closeFile(); // keep windows happy.
40file = new File(fileName);
41LogLog.debug("Renaming file " + file + " to " + target);
42renameSucceeded = file.renameTo(target);
43//
44// if file rename failed, reopen file with append = true
45//
46if (!renameSucceeded) {
47try {
48this.setFile(fileName, true, bufferedIO, bufferSize);
49} catch (IOException e) {
50if (e instanceof InterruptedIOException) {
51Thread.currentThread().interrupt();
52}
53LogLog.error("setFile(" + fileName
54+ ", true) call failed.", e);
55}
56}
57}
58}
59
60//
61// if all renames were successful, then
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-29497-5.html
阿拉斯加12海里范围内玩一玩
让人敬佩