summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2004-04-29 21:21:10 +0000
committerMark Wielaard <mark@klomp.org>2004-04-29 21:21:10 +0000
commit2e214f4154b62745fd7541bbc07c5b0579d9ad69 (patch)
treec1c7666b12bdecd8b21e51079ba3f8c1f09eae76
parent4f61ee51db568b5ed0e1198185e607ed744a4007 (diff)
downloadclasspath-2e214f4154b62745fd7541bbc07c5b0579d9ad69.tar.gz
* java/io/RandomAccessFile.java (setLength): Set position to new
length when new length is smaller then current position.
-rw-r--r--ChangeLog5
-rw-r--r--java/io/RandomAccessFile.java18
2 files changed, 17 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 592deffb1..d83405f77 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-04-29 Mark Wielaard <mark@klomp.org>
+
+ * java/io/RandomAccessFile.java (setLength): Set position to new
+ length when new length is smaller then current position.
+
2004-04-29 Michael Koch <konqueror@gmx.de>
* java/net/InetAddress.java
diff --git a/java/io/RandomAccessFile.java b/java/io/RandomAccessFile.java
index c20549c12..b6133d0d6 100644
--- a/java/io/RandomAccessFile.java
+++ b/java/io/RandomAccessFile.java
@@ -194,12 +194,14 @@ public class RandomAccessFile implements DataOutput, DataInput
}
/**
- * 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 class RandomAccessFile implements DataOutput, DataInput
public void setLength (long newLen) throws IOException
{
ch.truncate (newLen);
+
+ long position = getFilePointer();
+ if (position > newLen)
+ seek(newLen);
}
/**