jdk/src/share/classes/sun/nio/ch/IOUtil.java
changeset 9237 cbb5753e87e7
parent 7668 d4a77089c587
child 11823 ee83ae88512d
equal deleted inserted replaced
9029:e92fcf58f684 9237:cbb5753e87e7
    48         // Substitute a native buffer
    48         // Substitute a native buffer
    49         int pos = src.position();
    49         int pos = src.position();
    50         int lim = src.limit();
    50         int lim = src.limit();
    51         assert (pos <= lim);
    51         assert (pos <= lim);
    52         int rem = (pos <= lim ? lim - pos : 0);
    52         int rem = (pos <= lim ? lim - pos : 0);
    53         ByteBuffer bb = null;
    53         ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
    54         try {
    54         try {
    55             bb = Util.getTemporaryDirectBuffer(rem);
       
    56             bb.put(src);
    55             bb.put(src);
    57             bb.flip();
    56             bb.flip();
    58             // Do not update src until we see how many bytes were written
    57             // Do not update src until we see how many bytes were written
    59             src.position(pos);
    58             src.position(pos);
    60 
    59 
   185             throw new IllegalArgumentException("Read-only buffer");
   184             throw new IllegalArgumentException("Read-only buffer");
   186         if (dst instanceof DirectBuffer)
   185         if (dst instanceof DirectBuffer)
   187             return readIntoNativeBuffer(fd, dst, position, nd, lock);
   186             return readIntoNativeBuffer(fd, dst, position, nd, lock);
   188 
   187 
   189         // Substitute a native buffer
   188         // Substitute a native buffer
   190         ByteBuffer bb = null;
   189         ByteBuffer bb = Util.getTemporaryDirectBuffer(dst.remaining());
   191         try {
   190         try {
   192             bb = Util.getTemporaryDirectBuffer(dst.remaining());
       
   193             int n = readIntoNativeBuffer(fd, bb, position, nd, lock);
   191             int n = readIntoNativeBuffer(fd, bb, position, nd, lock);
   194             bb.flip();
   192             bb.flip();
   195             if (n > 0)
   193             if (n > 0)
   196                 dst.put(bb);
   194                 dst.put(bb);
   197             return n;
   195             return n;