commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Not Telling (JIRA)" <j...@apache.org>
Subject [jira] Created: (VFS-218) .skip() always returns the same number as given as parameter while the stream itself may or may not skip to given position
Date Thu, 04 Sep 2008 11:23:44 GMT
.skip() always returns the same number as given as parameter while the stream itself may or
may not skip to given position
--------------------------------------------------------------------------------------------------------------------------

                 Key: VFS-218
                 URL: https://issues.apache.org/jira/browse/VFS-218
             Project: Commons VFS
          Issue Type: Bug
    Affects Versions: 1.0
         Environment: Java 5, using jdk1.6.0_06 on Windows XP SP3
            Reporter: Not Telling


The code below should reproduce the bug, so far I've tested this with file: and res: file
systems and at least those two expose this bug. As you may notice from the source, you should
have file called "bla.txt" containing "blabla" (6 characters) in your C:\temp\ folder for
this.


{code:title=VFSStreamSkipping.java}
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.VFS;

/**
 * This class demonstrates buggy behaviour of .skip() when using VFS.
 * The bug is that no matter how many bytes were actually skipped, .skip()
 * always returns the same number as the user tried to skip. The stream itself
 * may get skipped though, if one tries to read the stream in this example
 * after .skip(), it will return -1 indicating that .skip() was executed
 * properly.
 */
public class VFSStreamSkipping {
	
	public static void main(String[] args) {
		FileObject file;
		FileSystemManager fsm;
		try {
			fsm = VFS.getManager();
		} catch (FileSystemException e) {
			fsm = null;
		}
		
		InputStream is = null;
		
		try {
			file = fsm.resolveFile("file:C:/temp/bla.txt");
			// file content is simply "blabla" with no \n or \r
			is = file.getContent().getInputStream();
		} catch (FileSystemException e) {}
		
		try {
			long skipped = is.skip(9L);
			System.out.println(skipped+" <= prints 9, this should be 6 as per javadoc's specification;
"+
					"http://java.sun.com/j2se/1.5.0/docs/api/java/io/InputStream.html#skip(long)");
			
			System.out.println(is.read());
		} catch (IOException e) {}
	}
}
{code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message