src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java
changeset 49897 117501815bed
parent 48748 4d716bc7ed54
child 50784 57f5cba78093
equal deleted inserted replaced
49896:ec2dd30adbc1 49897:117501815bed
   332                 if (!isOpen())
   332                 if (!isOpen())
   333                     return 0;
   333                     return 0;
   334                 boolean append = fdAccess.getAppend(fd);
   334                 boolean append = fdAccess.getAppend(fd);
   335                 do {
   335                 do {
   336                     // in append-mode then position is advanced to end before writing
   336                     // in append-mode then position is advanced to end before writing
   337                     p = (append) ? nd.size(fd) : position0(fd, -1);
   337                     p = (append) ? nd.size(fd) : nd.seek(fd, -1);
   338                 } while ((p == IOStatus.INTERRUPTED) && isOpen());
   338                 } while ((p == IOStatus.INTERRUPTED) && isOpen());
   339                 return IOStatus.normalize(p);
   339                 return IOStatus.normalize(p);
   340             } finally {
   340             } finally {
   341                 threads.remove(ti);
   341                 threads.remove(ti);
   342                 end(p > -1);
   342                 end(p > -1);
   356                 begin();
   356                 begin();
   357                 ti = threads.add();
   357                 ti = threads.add();
   358                 if (!isOpen())
   358                 if (!isOpen())
   359                     return null;
   359                     return null;
   360                 do {
   360                 do {
   361                     p = position0(fd, newPosition);
   361                     p = nd.seek(fd, newPosition);
   362                 } while ((p == IOStatus.INTERRUPTED) && isOpen());
   362                 } while ((p == IOStatus.INTERRUPTED) && isOpen());
   363                 return this;
   363                 return this;
   364             } finally {
   364             } finally {
   365                 threads.remove(ti);
   365                 threads.remove(ti);
   366                 end(p > -1);
   366                 end(p > -1);
   416                 if (!isOpen())
   416                 if (!isOpen())
   417                     return null;
   417                     return null;
   418 
   418 
   419                 // get current position
   419                 // get current position
   420                 do {
   420                 do {
   421                     p = position0(fd, -1);
   421                     p = nd.seek(fd, -1);
   422                 } while ((p == IOStatus.INTERRUPTED) && isOpen());
   422                 } while ((p == IOStatus.INTERRUPTED) && isOpen());
   423                 if (!isOpen())
   423                 if (!isOpen())
   424                     return null;
   424                     return null;
   425                 assert p >= 0;
   425                 assert p >= 0;
   426 
   426 
   435 
   435 
   436                 // if position is beyond new size then adjust it
   436                 // if position is beyond new size then adjust it
   437                 if (p > newSize)
   437                 if (p > newSize)
   438                     p = newSize;
   438                     p = newSize;
   439                 do {
   439                 do {
   440                     rp = position0(fd, p);
   440                     rp = nd.seek(fd, p);
   441                 } while ((rp == IOStatus.INTERRUPTED) && isOpen());
   441                 } while ((rp == IOStatus.INTERRUPTED) && isOpen());
   442                 return this;
   442                 return this;
   443             } finally {
   443             } finally {
   444                 threads.remove(ti);
   444                 threads.remove(ti);
   445                 end(rv > -1);
   445                 end(rv > -1);
   983                         throw new IOException("Channel not open for writing " +
   983                         throw new IOException("Channel not open for writing " +
   984                             "- cannot extend file to required size");
   984                             "- cannot extend file to required size");
   985                     }
   985                     }
   986                     int rv;
   986                     int rv;
   987                     do {
   987                     do {
   988                         rv = nd.allocate(fd, position + size);
   988                         rv = nd.truncate(fd, position + size);
   989                     } while ((rv == IOStatus.INTERRUPTED) && isOpen());
   989                     } while ((rv == IOStatus.INTERRUPTED) && isOpen());
   990                     if (!isOpen())
   990                     if (!isOpen())
   991                         return null;
   991                         return null;
   992                 }
   992                 }
   993 
   993 
  1210 
  1210 
  1211     // Transfers from src to dst, or returns -2 if kernel can't do that
  1211     // Transfers from src to dst, or returns -2 if kernel can't do that
  1212     private native long transferTo0(FileDescriptor src, long position,
  1212     private native long transferTo0(FileDescriptor src, long position,
  1213                                     long count, FileDescriptor dst);
  1213                                     long count, FileDescriptor dst);
  1214 
  1214 
  1215     // Sets or reports this file's position
       
  1216     // If offset is -1, the current position is returned
       
  1217     // otherwise the position is set to offset
       
  1218     private native long position0(FileDescriptor fd, long offset);
       
  1219 
       
  1220     // Caches fieldIDs
  1215     // Caches fieldIDs
  1221     private static native long initIDs();
  1216     private static native long initIDs();
  1222 
  1217 
  1223     static {
  1218     static {
  1224         IOUtil.load();
  1219         IOUtil.load();