/** * Construct a new instance with the given output file. * * @param file the file * @throws FileNotFoundException if the file could not be found on open */ public FileHandler(final File file) throws FileNotFoundException { setFile(file); }
/** * Construct a new instance with the given output file and append setting. * * @param fileName the file name * @param append {@code true} to append, {@code false} to overwrite * @throws FileNotFoundException if the file could not be found on open */ public FileHandler(final String fileName, final boolean append) throws FileNotFoundException { this.append = append; setFileName(fileName); }
if (file == null) { this.file = null; setOutputStream(null); return; final OutputStream bos = new BufferedOutputStream(fos); try { setOutputStream(bos); this.file = file; ok = true; } finally { if (! ok) { safeClose(bos); safeClose(fos);
/** {@inheritDoc} */ public void setOutputStream(final OutputStream outputStream) { synchronized (outputLock) { this.outputStream = outputStream == null ? null : new CountingOutputStream(outputStream); super.setOutputStream(this.outputStream); } }
/** * Construct a new instance with the given formatter, output file, and append setting. * * @param formatter the formatter * @param file the file * @param append {@code true} to append, {@code false} to overwrite * @throws FileNotFoundException if the file could not be found on open */ public FileHandler(final Formatter formatter, final File file, final boolean append) throws FileNotFoundException { super(formatter); this.append = append; setFile(file); }
/** * Construct a new instance with the given output file. * * @param fileName the file name * @throws FileNotFoundException if the file could not be found on open */ public FileHandler(final String fileName) throws FileNotFoundException { setFileName(fileName); }
/** * Construct a new instance with the given formatter and output file. * * @param formatter the formatter * @param file the file * @throws FileNotFoundException if the file could not be found on open */ public FileHandler(final Formatter formatter, final File file) throws FileNotFoundException { super(formatter); setFile(file); }
/** * Construct a new instance with the given output file and append setting. * * @param file the file * @param append {@code true} to append, {@code false} to overwrite * @throws FileNotFoundException if the file could not be found on open */ public FileHandler(final File file, final boolean append) throws FileNotFoundException { this.append = append; setFile(file); }
/** * Set the output file by name. * * @param fileName the file name * @throws FileNotFoundException if an error occurs opening the file */ public void setFileName(String fileName) throws FileNotFoundException { setFile(fileName == null ? null : new File(fileName)); } }
@Override public void setFile(final File file) throws FileNotFoundException { synchronized (outputLock) { super.setFile(file); if (format != null && file != null && file.lastModified() > 0) { calcNextRollover(file.lastModified()); } } }
/** * {@inheritDoc} * * @throws RuntimeException if there is an attempt to rotate file and the rotation fails */ public void setFile(final File file) throws FileNotFoundException { synchronized (outputLock) { // Check for a rotate if (rotateOnBoot && maxBackupIndex > 0 && file != null && file.exists() && file.length() > 0L) { suffixRotator.rotate(getErrorManager(), file.toPath(), maxBackupIndex); } super.setFile(file); if (outputStream != null) outputStream.currentSize = file == null ? 0L : file.length(); } }