110 * Thus if three processes were all trying to log to fred%u.%g.txt then
111 * they might end up using fred0.0.txt, fred1.0.txt, fred2.0.txt as
112 * the first file in their rotating sequences.
113 * <p>
114 * Note that the use of unique ids to avoid conflicts is only guaranteed
115 * to work reliably when using a local disk file system.
116 *
117 * @since 1.4
118 */
119
120 public class FileHandler extends StreamHandler {
121 private MeteredStream meter;
122 private boolean append;
123 private int limit; // zero => no limit.
124 private int count;
125 private String pattern;
126 private String lockFileName;
127 private FileOutputStream lockStream;
128 private File files[];
129 private static final int MAX_LOCKS = 100;
130 private static java.util.HashMap<String, String> locks = new java.util.HashMap<String, String>();
131
132 // A metered stream is a subclass of OutputStream that
133 // (a) forwards all its output to a target stream
134 // (b) keeps track of how many bytes have been written
135 private class MeteredStream extends OutputStream {
136 OutputStream out;
137 int written;
138
139 MeteredStream(OutputStream out, int written) {
140 this.out = out;
141 this.written = written;
142 }
143
144 public void write(int b) throws IOException {
145 out.write(b);
146 written++;
147 }
148
149 public void write(byte buff[]) throws IOException {
150 out.write(buff);
|
110 * Thus if three processes were all trying to log to fred%u.%g.txt then
111 * they might end up using fred0.0.txt, fred1.0.txt, fred2.0.txt as
112 * the first file in their rotating sequences.
113 * <p>
114 * Note that the use of unique ids to avoid conflicts is only guaranteed
115 * to work reliably when using a local disk file system.
116 *
117 * @since 1.4
118 */
119
120 public class FileHandler extends StreamHandler {
121 private MeteredStream meter;
122 private boolean append;
123 private int limit; // zero => no limit.
124 private int count;
125 private String pattern;
126 private String lockFileName;
127 private FileOutputStream lockStream;
128 private File files[];
129 private static final int MAX_LOCKS = 100;
130 private static java.util.HashMap<String, String> locks = new java.util.HashMap<>();
131
132 // A metered stream is a subclass of OutputStream that
133 // (a) forwards all its output to a target stream
134 // (b) keeps track of how many bytes have been written
135 private class MeteredStream extends OutputStream {
136 OutputStream out;
137 int written;
138
139 MeteredStream(OutputStream out, int written) {
140 this.out = out;
141 this.written = written;
142 }
143
144 public void write(int b) throws IOException {
145 out.write(b);
146 written++;
147 }
148
149 public void write(byte buff[]) throws IOException {
150 out.write(buff);
|