| 116 | } |
| 117 | |
| 118 | private @NotNull FileOutputStream today() throws IOException { |
| 119 | var nowDays = System.currentTimeMillis() / (24 * 60 * 60 * 1000); |
| 120 | // 第一次执行时,如果nowDays等于0(即days的初始值),会返回null。 |
| 121 | // 这种情况就不处理了。 |
| 122 | if (todayDays != nowDays) { |
| 123 | lock(); |
| 124 | try { |
| 125 | if (todayDays != nowDays) { |
| 126 | todayDays = nowDays; |
| 127 | if (todayFile != null) |
| 128 | todayFile.close(); |
| 129 | todayFile = new FileOutputStream(Paths.get(name, "days_" + todayDays).toFile()); |
| 130 | } |
| 131 | return todayFile; |
| 132 | } finally { |
| 133 | unlock(); |
| 134 | } |
| 135 | } |
| 136 | return todayFile; |
| 137 | } |
| 138 | |
| 139 | private void tryRemove() throws IOException, RocksDBException { |
| 140 | var prefix = "days_"; |