harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r375581 - /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PushbackReader.java
Date Tue, 07 Feb 2006 11:40:57 GMT
Author: tellison
Date: Tue Feb  7 03:40:31 2006
New Revision: 375581

URL: http://svn.apache.org/viewcvs?rev=375581&view=rev
Log:
Implement missing skip(long) method.

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PushbackReader.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PushbackReader.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PushbackReader.java?rev=375581&r1=375580&r2=375581&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PushbackReader.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PushbackReader.java
Tue Feb  7 03:40:31 2006
@@ -304,4 +304,47 @@
 				throw new IOException();
 		}
 	}
+	
+	/**
+	 * Skips <code>count</code> number of characters in this Reader.
+	 * Subsequent <code>read()</code>'s will not return these characters
+	 * unless <code>reset()</code> is used.
+	 * 
+	 * @param count
+	 *            the maximum number of characters to skip.
+	 * @return the number of characters actually skipped.
+	 * 
+	 * @throws IOException
+	 *             If the Reader is already closed or some other IO error
+	 *             occurs.
+	 * @throws IllegalArgumentException
+	 *             If count is negative.
+	 */
+	public long skip(long count) throws IOException {
+		if (count < 0) {
+			throw new IllegalArgumentException();
+		}
+		synchronized (lock) {
+			if (buf != null) {
+				if (count == 0) {
+					return 0;
+				}
+				long inSkipped;
+				int availableFromBuffer = buf.length - pos;
+				if (availableFromBuffer > 0) {
+					long requiredFromIn = count - availableFromBuffer;
+					if (requiredFromIn <= 0) {
+						pos += count;
+						return count;
+					}
+					pos += availableFromBuffer;
+					inSkipped = in.skip(requiredFromIn);
+				} else {
+					inSkipped = in.skip(count);
+				}
+				return inSkipped + availableFromBuffer;
+			}
+			throw new IOException();
+		}
+	}
 }



Mime
View raw message