Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 828 invoked from network); 28 Sep 2005 21:12:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 28 Sep 2005 21:12:18 -0000 Received: (qmail 34510 invoked by uid 500); 28 Sep 2005 21:12:17 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 33980 invoked by uid 500); 28 Sep 2005 21:12:15 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 33967 invoked by uid 500); 28 Sep 2005 21:12:15 -0000 Received: (qmail 33964 invoked by uid 99); 28 Sep 2005 21:12:14 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 28 Sep 2005 14:12:14 -0700 Received: (qmail 751 invoked by uid 65534); 28 Sep 2005 21:11:54 -0000 Message-ID: <20050928211154.750.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r292298 - /jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/LockableFileWriter.java Date: Wed, 28 Sep 2005 21:11:54 -0000 To: commons-cvs@jakarta.apache.org From: scolebourne@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: scolebourne Date: Wed Sep 28 14:11:47 2005 New Revision: 292298 URL: http://svn.apache.org/viewcvs?rev=292298&view=rev Log: Javadoc Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/LockableFileWriter.java Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/LockableFileWriter.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/LockableFileWriter.java?rev=292298&r1=292297&r2=292298&view=diff ============================================================================== --- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/LockableFileWriter.java (original) +++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/LockableFileWriter.java Wed Sep 28 14:11:47 2005 @@ -31,81 +31,86 @@ * @author Michael Salmon * @author Jon S. Stevens * @author Daniel Rall + * @author Stephen Colebourne * @version $Id$ */ public class LockableFileWriter extends Writer { + /** The extension for the lock file. */ private static final String LCK = ".lck"; - private File lockFile = null; - - private FileWriter writer = null; - - private boolean append = false; + /** The lock file. */ + private File lockFile; + /** The write used to write to the file. */ + private Writer writer; + /** Should we append to the file or not. */ + private boolean append; /** - * Constructs a LockableFileWriter. If the file exists, it is overwritten. - * @param fileName file to write to + * Constructs a LockableFileWriter. + * If the file exists, it is overwritten. + * + * @param fileName the file to write to * @throws IOException in case of an I/O error */ - public LockableFileWriter(String fileName) - throws IOException { + public LockableFileWriter(String fileName) throws IOException { this(fileName, false, null); } /** * Constructs a LockableFileWriter. - * @param fileName file to write to - * @param append true if content should be appended (default is to overwrite). + * + * @param fileName file to write to + * @param append true if content should be appended, false to overwrite * @throws IOException in case of an I/O error */ - public LockableFileWriter(String fileName, boolean append) - throws IOException { + public LockableFileWriter(String fileName, boolean append) throws IOException { this(fileName, append, null); } /** * Constructs a LockableFileWriter. - * @param fileName file to write to - * @param append true if content should be appended (default is to overwrite). - * @param lockDir Specifies the directory in which the lock file should be held. + * + * @param fileName the file to write to + * @param append true if content should be appended, false to overwrite + * @param lockDir the directory in which the lock file should be held * @throws IOException in case of an I/O error */ - public LockableFileWriter(String fileName, boolean append, String lockDir) - throws IOException { + public LockableFileWriter(String fileName, boolean append, String lockDir) throws IOException { this(new File(fileName), append, lockDir); } /** - * Constructs a LockableFileWriter. If the file exists, it is overwritten. - * @param file file to write to + * Constructs a LockableFileWriter. + * If the file exists, it is overwritten. + * + * @param file the file to write to * @throws IOException in case of an I/O error */ - public LockableFileWriter(File file) - throws IOException { + public LockableFileWriter(File file) throws IOException { this(file, false, null); } /** * Constructs a LockableFileWriter. - * @param file file to write to - * @param append true if content should be appended (default is to overwrite). + * + * @param file the file to write to + * @param append true if content should be appended, false to overwrite * @throws IOException in case of an I/O error */ - public LockableFileWriter(File file, boolean append) - throws IOException { + public LockableFileWriter(File file, boolean append) throws IOException { this(file, append, null); } /** * Constructs a LockableFileWriter. - * @param file file to write to - * @param append true if content should be appended (default is to overwrite). - * @param lockDir Specifies the directory in which the lock file should be held. + * + * @param file the file to write to + * @param append true if content should be appended, false to overwrite + * @param lockDir the directory in which the lock file should be held * @throws IOException in case of an I/O error */ - public LockableFileWriter(File file, boolean append, String lockDir) - throws IOException { + public LockableFileWriter(File file, boolean append, String lockDir) throws IOException { this.append = append; if (lockDir == null) { @@ -118,8 +123,15 @@ this.writer = new FileWriter(file.getAbsolutePath(), this.append); } - private void testLockDir(File lockDir) - throws IOException { + //----------------------------------------------------------------------- + /** + * Tests that we can write to the lock directory. + * + * @param lockDir the File representing the lock directory + * @throws IOException if we cannot write to the lock directory + * @throws IOException if we cannot find the lock file + */ + private void testLockDir(File lockDir) throws IOException { if (!lockDir.exists()) { throw new IOException( "Could not find lockDir: " + lockDir.getAbsolutePath()); @@ -130,8 +142,12 @@ } } - private void createLock() - throws IOException { + /** + * Creates the lock file. + * + * @throws IOException if we cannot create the file + */ + private void createLock() throws IOException { synchronized (LockableFileWriter.class) { if (!lockFile.createNewFile()) { throw new IOException("Can't write file, lock " + @@ -141,9 +157,12 @@ } } - /** @see java.io.Writer#close() */ - public void close() - throws IOException { + /** + * Closes the file writer. + * + * @throws IOException if an I/O error occurs + */ + public void close() throws IOException { try { writer.close(); } finally { @@ -151,15 +170,25 @@ } } - /** @see java.io.Writer#write(char[], int, int) */ - public void write(char[] cbuf, int off, int len) - throws IOException { + //----------------------------------------------------------------------- + /** + * Write a portion of a string. + * + * @param cbuf The characters to write + * @param off Offset from which to start writing characters + * @param len Number of characters to write + * + * @exception IOException If an I/O error occurs + */ + public void write(char[] cbuf, int off, int len) throws IOException { writer.write(cbuf, off, len); } - /** @see java.io.Writer#flush() */ - public void flush() - throws IOException { + /** + * Flushes the file writer. + */ + public void flush() throws IOException { writer.flush(); } + } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org