commit-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fwd: FYI: Fix RandomAccessFile.setLenght (truncation file, updates file


From: Mark Wielaard
Subject: [Fwd: FYI: Fix RandomAccessFile.setLenght (truncation file, updates file position).]
Date: Thu, 29 Apr 2004 23:48:56 +0200

It is address@hidden, not address@hidden Oops.
--- Begin Message --- Subject: FYI: Fix RandomAccessFile.setLenght (truncation file, updates file position). Date: Thu, 29 Apr 2004 23:17:36 +0200
Hi,

This fixes a buglet in RandomAccessFile. When we set the new length of a
file we need to make sure to also set the new file postition to the new
length (end of file) when the new length is smaller then the current
file position.

2004-04-29  Mark Wielaard  <address@hidden>

    * java/io/RandomAccessFile.java (setLength): Set position to new
    length when new length is smaller then current position.

There is now also an explicit Mauve test for this, which passes with
this patch (but fails without it). Committed.

Cheers,

Mark
Index: java/io/RandomAccessFile.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/RandomAccessFile.java,v
retrieving revision 1.38
diff -u -r1.38 RandomAccessFile.java
--- java/io/RandomAccessFile.java       17 Apr 2004 17:29:18 -0000      1.38
+++ java/io/RandomAccessFile.java       29 Apr 2004 21:17:00 -0000
@@ -194,12 +194,14 @@
   }
 
   /**
-   * This method sets the length of the file to the specified length.  If
-   * the currently length of the file is longer than the specified length,
-   * then the file is truncated to the specified length.  If the current
-   * length of the file is shorter than the specified length, the file
-   * is extended with bytes of an undefined value.
-   *  <p>
+   * This method sets the length of the file to the specified length.
+   * If the currently length of the file is longer than the specified
+   * length, then the file is truncated to the specified length (the
+   * file position is set to the end of file in this case).  If the
+   * current length of the file is shorter than the specified length,
+   * the file is extended with bytes of an undefined value (the file
+   * position is unchanged in this case).
+   * <p>
    * The file must be open for write access for this operation to succeed.
    *
    * @param newlen The new length of the file
@@ -209,6 +211,10 @@
   public void setLength (long newLen) throws IOException
   {
     ch.truncate (newLen);
+
+    long position = getFilePointer();
+    if (position > newLen)
+      seek(newLen);
   }
 
   /**

Attachment: signature.asc
Description: This is a digitally signed message part


--- End Message ---

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]