311 } while ((s == IOStatus.INTERRUPTED) && isOpen());
312 return IOStatus.normalize(s);
313 } finally {
314 threads.remove(ti);
315 end(s > -1);
316 assert IOStatus.check(s);
317 }
318 }
319 }
320
321 public FileChannel truncate(long newSize) throws IOException {
322 ensureOpen();
323 if (newSize < 0)
324 throw new IllegalArgumentException("Negative size");
325 if (!writable)
326 throw new NonWritableChannelException();
327 synchronized (positionLock) {
328 int rv = -1;
329 long p = -1;
330 int ti = -1;
331 try {
332 begin();
333 ti = threads.add();
334 if (!isOpen())
335 return null;
336
337 // get current size
338 long size;
339 do {
340 size = nd.size(fd);
341 } while ((size == IOStatus.INTERRUPTED) && isOpen());
342 if (!isOpen())
343 return null;
344
345 // get current position
346 do {
347 p = position0(fd, -1);
348 } while ((p == IOStatus.INTERRUPTED) && isOpen());
349 if (!isOpen())
350 return null;
351 assert p >= 0;
352
353 // truncate file if given size is less than the current size
354 if (newSize < size) {
355 do {
356 rv = nd.truncate(fd, newSize);
357 } while ((rv == IOStatus.INTERRUPTED) && isOpen());
358 if (!isOpen())
359 return null;
360 }
361
362 // if position is beyond new size then adjust it
363 if (p > newSize)
364 p = newSize;
365 do {
366 rv = (int)position0(fd, p);
367 } while ((rv == IOStatus.INTERRUPTED) && isOpen());
368 return this;
369 } finally {
370 threads.remove(ti);
371 end(rv > -1);
372 assert IOStatus.check(rv);
373 }
374 }
375 }
376
377 public void force(boolean metaData) throws IOException {
378 ensureOpen();
379 int rv = -1;
380 int ti = -1;
381 try {
382 begin();
383 ti = threads.add();
384 if (!isOpen())
385 return;
386 do {
387 rv = nd.force(fd, metaData);
|
311 } while ((s == IOStatus.INTERRUPTED) && isOpen());
312 return IOStatus.normalize(s);
313 } finally {
314 threads.remove(ti);
315 end(s > -1);
316 assert IOStatus.check(s);
317 }
318 }
319 }
320
321 public FileChannel truncate(long newSize) throws IOException {
322 ensureOpen();
323 if (newSize < 0)
324 throw new IllegalArgumentException("Negative size");
325 if (!writable)
326 throw new NonWritableChannelException();
327 synchronized (positionLock) {
328 int rv = -1;
329 long p = -1;
330 int ti = -1;
331 long rl = -1;
332 try {
333 begin();
334 ti = threads.add();
335 if (!isOpen())
336 return null;
337
338 // get current size
339 long size;
340 do {
341 size = nd.size(fd);
342 } while ((size == IOStatus.INTERRUPTED) && isOpen());
343 if (!isOpen())
344 return null;
345
346 // get current position
347 do {
348 p = position0(fd, -1);
349 } while ((p == IOStatus.INTERRUPTED) && isOpen());
350 if (!isOpen())
351 return null;
352 assert p >= 0;
353
354 // truncate file if given size is less than the current size
355 if (newSize < size) {
356 do {
357 rv = nd.truncate(fd, newSize);
358 } while ((rv == IOStatus.INTERRUPTED) && isOpen());
359 if (!isOpen())
360 return null;
361 }
362
363 // if position is beyond new size then adjust it
364 if (p > newSize)
365 p = newSize;
366 do {
367 rl = position0(fd, p);
368 } while ((rl == IOStatus.INTERRUPTED) && isOpen());
369 return this;
370 } finally {
371 threads.remove(ti);
372 end(rv > -1);
373 assert IOStatus.check(rv);
374 }
375 }
376 }
377
378 public void force(boolean metaData) throws IOException {
379 ensureOpen();
380 int rv = -1;
381 int ti = -1;
382 try {
383 begin();
384 ti = threads.add();
385 if (!isOpen())
386 return;
387 do {
388 rv = nd.force(fd, metaData);
|