Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


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

markpos ==0 ?


  • From: gdb@xxxxxxxxxxxxxxxxx (Geraldo de Bem)
  • Subject: markpos ==0 ?
  • Date: Tue, 30 Nov 1999 20:12:03 -0200

This is a multi-part message in MIME format.
--------------84F93D554D33C11BD8BAD96E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

The documentation says the following about protected int markpos: "The
value of the pos field at the time the last mark method was called. The
value of this field is -1 if there is no current mark."

I'd expect from the above that the value of markpos is EITHER pos, when
mark() is called, OR -1, when it's no longer valid.

But it happens that passing from 10 to -1 markpos is 0 for a while!

What's the cause of this strange behavior?

Attached is the redirected (>) J289.txt of a run. See 10, 0, and -1 at
the end of the file.

Notice that the file correspondent to a[0] should be greater than 2048
bytes or else it will loop forever since markpos will never be -1.

import java.io.*;

class J289 extends BufferedInputStream {

J289(FileInputStream f) {super(f);}

public static void main(String[] a) {

try {
J289 o=new J289(new FileInputStream(a[0]));

for (int i=0; i<10; i++) o.read(); // 10 bytes from the beginning

o.mark(20); // markposition is 10

while (o.markpos != -1) {
o.read();
System.out.println("Current position "+o.pos+" Mark position "+
o.markpos);
}
}

catch(Exception e) {}

}
}

Geraldo
--------------84F93D554D33C11BD8BAD96E
Content-Type: text/plain; charset=us-ascii;
 name="J289.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="J289.txt"

Current position 11 Mark position 10
Current position 12 Mark position 10
Current position 13 Mark position 10
Current position 14 Mark position 10
Current position 15 Mark position 10
...
Current position 2044 Mark position 10
Current position 2045 Mark position 10
Current position 2046 Mark position 10
Current position 2047 Mark position 10
Current position 2048 Mark position 10
Current position 2039 Mark position 0
Current position 2040 Mark position 0
Current position 2041 Mark position 0
Current position 2042 Mark position 0
Current position 2043 Mark position 0
Current position 2044 Mark position 0
Current position 2045 Mark position 0
Current position 2046 Mark position 0
Current position 2047 Mark position 0
Current position 2048 Mark position 0
Current position 1 Mark position -1


--------------84F93D554D33C11BD8BAD96E--


---
To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx
To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx