< prev index next >

jdk/src/java.logging/share/classes/java/util/logging/FileHandler.java

Print this page




 406      * <p>
 407      * The {@code FileHandler} is configured based on {@code LogManager}
 408      * properties (or their default values) except that the given pattern
 409      * argument is used as the filename pattern, the file limit is
 410      * set to the limit argument, and the file count is set to the
 411      * given count argument, and the append mode is set to the given
 412      * {@code append} argument.
 413      * <p>
 414      * The count must be at least 1.
 415      *
 416      * @param pattern  the pattern for naming the output file
 417      * @param limit  the maximum number of bytes to write to any one file
 418      * @param count  the number of files to use
 419      * @param append  specifies append mode
 420      * @exception  IOException if there are IO problems opening the files.
 421      * @exception  SecurityException  if a security manager exists and if
 422      *             the caller does not have {@code LoggingPermission("control")}.
 423      * @exception  IllegalArgumentException if {@code limit < 0}, or {@code count < 1}.
 424      * @exception  IllegalArgumentException if pattern is an empty string
 425      *
 426      * @since 1.9
 427      *
 428      */
 429     public FileHandler(String pattern, long limit, int count, boolean append)
 430                                         throws IOException {
 431         if (limit < 0 || count < 1 || pattern.length() < 1) {
 432             throw new IllegalArgumentException();
 433         }
 434         checkPermission();
 435         configure();
 436         this.pattern = pattern;
 437         this.limit = limit;
 438         this.count = count;
 439         this.append = append;
 440         openFiles();
 441     }
 442 
 443     private  boolean isParentWritable(Path path) {
 444         Path parent = path.getParent();
 445         if (parent == null) {
 446             parent = path.toAbsolutePath().getParent();


 622             if (ch == '/') {
 623                 if (file == null) {
 624                     file = new File(word);
 625                 } else {
 626                     file = new File(file, word);
 627                 }
 628                 word = "";
 629                 continue;
 630             } else  if (ch == '%') {
 631                 if (ch2 == 't') {
 632                     String tmpDir = System.getProperty("java.io.tmpdir");
 633                     if (tmpDir == null) {
 634                         tmpDir = System.getProperty("user.home");
 635                     }
 636                     file = new File(tmpDir);
 637                     ix++;
 638                     word = "";
 639                     continue;
 640                 } else if (ch2 == 'h') {
 641                     file = new File(System.getProperty("user.home"));
 642                     if (jdk.internal.misc.VM.isSetUID()) {
 643                         // Ok, we are in a set UID program.  For safety's sake
 644                         // we disallow attempts to open files relative to %h.
 645                         throw new IOException("can't use %h in set UID program");
 646                     }
 647                     ix++;
 648                     word = "";
 649                     continue;
 650                 } else if (ch2 == 'g') {
 651                     word = word + generation;
 652                     sawg = true;
 653                     ix++;
 654                     continue;
 655                 } else if (ch2 == 'u') {
 656                     word = word + unique;
 657                     sawu = true;
 658                     ix++;
 659                     continue;
 660                 } else if (ch2 == '%') {
 661                     word = word + "%";
 662                     ix++;




 406      * <p>
 407      * The {@code FileHandler} is configured based on {@code LogManager}
 408      * properties (or their default values) except that the given pattern
 409      * argument is used as the filename pattern, the file limit is
 410      * set to the limit argument, and the file count is set to the
 411      * given count argument, and the append mode is set to the given
 412      * {@code append} argument.
 413      * <p>
 414      * The count must be at least 1.
 415      *
 416      * @param pattern  the pattern for naming the output file
 417      * @param limit  the maximum number of bytes to write to any one file
 418      * @param count  the number of files to use
 419      * @param append  specifies append mode
 420      * @exception  IOException if there are IO problems opening the files.
 421      * @exception  SecurityException  if a security manager exists and if
 422      *             the caller does not have {@code LoggingPermission("control")}.
 423      * @exception  IllegalArgumentException if {@code limit < 0}, or {@code count < 1}.
 424      * @exception  IllegalArgumentException if pattern is an empty string
 425      *
 426      * @since 9
 427      *
 428      */
 429     public FileHandler(String pattern, long limit, int count, boolean append)
 430                                         throws IOException {
 431         if (limit < 0 || count < 1 || pattern.length() < 1) {
 432             throw new IllegalArgumentException();
 433         }
 434         checkPermission();
 435         configure();
 436         this.pattern = pattern;
 437         this.limit = limit;
 438         this.count = count;
 439         this.append = append;
 440         openFiles();
 441     }
 442 
 443     private  boolean isParentWritable(Path path) {
 444         Path parent = path.getParent();
 445         if (parent == null) {
 446             parent = path.toAbsolutePath().getParent();


 622             if (ch == '/') {
 623                 if (file == null) {
 624                     file = new File(word);
 625                 } else {
 626                     file = new File(file, word);
 627                 }
 628                 word = "";
 629                 continue;
 630             } else  if (ch == '%') {
 631                 if (ch2 == 't') {
 632                     String tmpDir = System.getProperty("java.io.tmpdir");
 633                     if (tmpDir == null) {
 634                         tmpDir = System.getProperty("user.home");
 635                     }
 636                     file = new File(tmpDir);
 637                     ix++;
 638                     word = "";
 639                     continue;
 640                 } else if (ch2 == 'h') {
 641                     file = new File(System.getProperty("user.home"));
 642                     if (sun.misc.VM.isSetUID()) {
 643                         // Ok, we are in a set UID program.  For safety's sake
 644                         // we disallow attempts to open files relative to %h.
 645                         throw new IOException("can't use %h in set UID program");
 646                     }
 647                     ix++;
 648                     word = "";
 649                     continue;
 650                 } else if (ch2 == 'g') {
 651                     word = word + generation;
 652                     sawg = true;
 653                     ix++;
 654                     continue;
 655                 } else if (ch2 == 'u') {
 656                     word = word + unique;
 657                     sawu = true;
 658                     ix++;
 659                     continue;
 660                 } else if (ch2 == '%') {
 661                     word = word + "%";
 662                     ix++;


< prev index next >