copyTo() without any copy option copies the alternate data streams to the target file(win)

Rajendra Gutupalli Rajendra.Gutupalli at Sun.COM
Wed Jun 11 01:25:08 PDT 2008


Hi Alan,

1)
Spec for Path.copyTo() says "File attributes are not required to be 
copied to the target file".
I observed in Windows vista it copies the alternate data stream (named 
attribute) associated with file.
Could you please tell me whether the observed behavior is expected in 
Windows. If it is expected
then how can I copy the file discarding the associated data streams to 
another volume using copyTo method.

Please see the following result and program.

<Windows Vista>
stream written to path C:\testfile : stream file
stream written to file F:\testfile : stream file
</Windows Vista>

<Solaris>
bash-3.00$ $jdk/java NamedTest4
stream written to path testfile : stream file
Exception in thread "main" java.nio.file.FileSystemException: 
TestDir/testfile: Unable to get read extended attribute 'txt': No such 
file or directory
        at 
sun.nio.fs.SolarisNamedAttributeView.read(SolarisNamedAttributeView.java:166)
        at NamedTest4.main(NamedTest4.java:23)
</Solaris>

<code>
import java.nio.ByteBuffer;
import java.nio.file.*;
import java.nio.file.attribute.*;

public class NamedTest {

    public static void main(String... args) throws Exception {
        Path path = Path.get("C:\\testfile");
        NamedAttributeView nav = 
path.newFileAttributeView(NamedAttributeView.class, false);
        ByteBuffer bb = ByteBuffer.wrap("stream file".getBytes());
        nav.write("txt", bb);
        ByteBuffer bb1 = ByteBuffer.allocate(15);
        nav.read("txt", bb1);
        System.out.println("stream written to path "+path + " : " +new 
String(bb1.array()));
        Path target = Path.get("F:\\testfile");
        path.copyTo(target);
        nav.bind(target);
        ByteBuffer bb2 = ByteBuffer.allocate(15);
        nav.read("txt", bb2);
        System.out.println("stream written to file "+target + " : " +new 
String(bb2.array()));
    }
}
</code>

2) Could you please tell me is there any restrictions for naming a 
alternate data streams. I am able to name nul, LP1 and all other 
characters that are forbidden for naming a file which are mentioned in 
the msdn site:
http://msdn.microsoft.com/en-us/library/aa365247.aspx

Thanks
Rajendra.



More information about the nio-dev mailing list