/** * Returns the name of the File being managed. * @return The name of the File being managed. */ public String getFileName() { return getName(); } /**
@Override protected synchronized void write(final byte[] bytes, final int offset, final int length, final boolean immediateFlush) { if (isLocking) { try { @SuppressWarnings("resource") final FileChannel channel = ((FileOutputStream) getOutputStream()).getChannel(); /* * Lock the whole file. This could be optimized to only lock from the current file position. Note that * locking may be advisory on some systems and mandatory on others, so locking just from the current * position would allow reading on systems where locking is mandatory. Also, Java 6 will throw an * exception if the region of the file is already locked by another FileChannel in the same JVM. * Hopefully, that will be avoided since every file should have a single file manager - unless two * different files strings are configured that somehow map to the same file. */ try (final FileLock lock = channel.lock(0, Long.MAX_VALUE, false)) { super.write(bytes, offset, length, immediateFlush); } } catch (final IOException ex) { throw new AppenderLoggingException("Unable to obtain lock on " + getName(), ex); } } else { super.write(bytes, offset, length, immediateFlush); } }
throw new AppenderLoggingException("Unable to obtain lock on " + getName(), ex);