NamedAttributeView#write does not replace the value for an existing subfile(named attr) instead it overwrites?

Rajendra Gutupalli Rajendra.Gutupalli at Sun.COM
Mon Jun 9 00:38:06 PDT 2008


Hi Alan,

The spec for NamedAttributeView#write says
"If an attribute of the given name already exists then its value is 
replaced. If the attribute does not exist then it is created."
But I observed if an attribute of the given name already exists then its 
value is overwriting on the previous value instead of replacing entire 
value.
First I have written "stream file" value to the subfile "txt" for a file 
c:\testf, again I tried adding value "r" to the subfile "txt" which 
already exists.
Instead of chainging the subfile value to "r" it overwrites as "rtream 
file".  Please see the following result and program.
Please tell me what is the expected output for this scenario.

Tried in Windows XP.


<output when ran the following code>
rtream file
</output>

<output when tried in command line>
C:\>cat "testf:txt file"
stream file
C:\>cat > "testf:txt file"
r
^Z
C:\>cat "testf:txt file"
r
</output>

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

public class NameTest1 {

    public static void main(String... args) throws Exception {
        Path path = Path.get("C:\\testf");       
        NamedAttributeView nav = 
path.newFileAttributeView(NamedAttributeView.class, false);       
        ByteBuffer bb = ByteBuffer.wrap("stream 
file".getBytes());               
        nav.write("txt", bb);
        ByteBuffer bb1 = ByteBuffer.wrap("r".getBytes());
        nav.write("txt", bb1);
        ByteBuffer rb = ByteBuffer.allocate(20);
        nav.read("txt", rb);
        System.out.println(new String(rb.array()));
    }
}

</code>

Thanks
Rajendra.



More information about the nio-dev mailing list