Lines 61-66
Link Here
|
61 |
import java.nio.file.Path; |
61 |
import java.nio.file.Path; |
62 |
import java.nio.file.Paths; |
62 |
import java.nio.file.Paths; |
63 |
import java.util.Random; |
63 |
import java.util.Random; |
|
|
64 |
import java.util.concurrent.Callable; |
64 |
import java.util.logging.Level; |
65 |
import java.util.logging.Level; |
65 |
import org.openide.util.NbBundle; |
66 |
import org.openide.util.NbBundle; |
66 |
import org.openide.util.BaseUtilities; |
67 |
import org.openide.util.BaseUtilities; |
Lines 423-449
Link Here
|
423 |
// Begin of the original part |
424 |
// Begin of the original part |
424 |
protected InputStream inputStream(String name) throws java.io.FileNotFoundException { |
425 |
protected InputStream inputStream(String name) throws java.io.FileNotFoundException { |
425 |
InputStream fis; |
426 |
InputStream fis; |
426 |
File file = null; |
427 |
final File file = getFile(name); |
427 |
|
428 |
|
428 |
try { |
429 |
try { |
429 |
fis = new BufferedInputStream(new FileInputStream(file = getFile(name))); |
430 |
fis = tryGetStream(new Callable<InputStream>() { |
|
|
431 |
@Override |
432 |
public InputStream call() throws Exception { |
433 |
return new BufferedInputStream(new FileInputStream(file)); |
434 |
} |
435 |
}, 10, 100); |
430 |
} catch (FileNotFoundException exc) { |
436 |
} catch (FileNotFoundException exc) { |
431 |
if ((file == null) || !file.exists()) { |
437 |
if ((file == null) || !file.exists()) { |
432 |
ExternalUtil.annotate(exc, NbBundle.getMessage(LocalFileSystem.class, "EXC_FileOutsideModified", getFile(name))); |
438 |
ExternalUtil.annotate(exc, NbBundle.getMessage(LocalFileSystem.class, "EXC_FileOutsideModified", getFile(name))); |
433 |
} |
439 |
} |
434 |
|
440 |
|
435 |
throw exc; |
441 |
throw exc; |
|
|
442 |
} catch (IOException ex) { |
443 |
// Should not happen, only FileNotFoundException is expected. |
444 |
throw new IllegalStateException(ex); |
436 |
} |
445 |
} |
437 |
|
446 |
|
438 |
return fis; |
447 |
return fis; |
439 |
} |
448 |
} |
440 |
|
449 |
|
441 |
protected OutputStream outputStream(final String name) throws java.io.IOException { |
450 |
protected OutputStream outputStream(final String name) throws java.io.IOException { |
442 |
File f = getFile(name); |
451 |
final File f = getFile(name); |
443 |
if (!f.exists()) { |
452 |
if (!f.exists()) { |
444 |
f.getParentFile().mkdirs(); |
453 |
f.getParentFile().mkdirs(); |
445 |
} |
454 |
} |
446 |
OutputStream retVal = new BufferedOutputStream(new FileOutputStream(f)); |
455 |
OutputStream retVal = tryGetStream(new Callable<OutputStream>() { |
|
|
456 |
@Override |
457 |
public OutputStream call() throws Exception { |
458 |
return new BufferedOutputStream(new FileOutputStream(f)); |
459 |
} |
460 |
}, 10, 100); |
447 |
|
461 |
|
448 |
// workaround for #42624 |
462 |
// workaround for #42624 |
449 |
if (BaseUtilities.isMac()) { |
463 |
if (BaseUtilities.isMac()) { |
Lines 453-458
Link Here
|
453 |
return retVal; |
467 |
return retVal; |
454 |
} |
468 |
} |
455 |
|
469 |
|
|
|
470 |
/** |
471 |
* Try getting input or output stream, possibly several times, with defined |
472 |
* wait time between tries. |
473 |
* <p> |
474 |
* See bug 204226. |
475 |
* </p> |
476 |
* <p> |
477 |
* Note: Number of tries should not be too high because of very high wait |
478 |
* times and danger of stack overflows. |
479 |
* </p> |
480 |
* |
481 |
* @param <T> Type of result, input or output stream. |
482 |
* @param call Operation that retrieves the stream or throws exception. |
483 |
* @param triesLeft Number of tries remaining. |
484 |
* @param wait Actual time to wait before next try. |
485 |
* |
486 |
* @return The input or output stream. |
487 |
* @throws IOException if something went wrong in the last try. |
488 |
*/ |
489 |
private <T> T tryGetStream(Callable<T> call, int triesLeft, int wait) |
490 |
throws IOException { |
491 |
|
492 |
try { |
493 |
return call.call(); |
494 |
} catch (FileNotFoundException e) { // #204226 |
495 |
if (triesLeft <= 1) { |
496 |
throw e; |
497 |
} else { |
498 |
try { |
499 |
Thread.sleep(wait); |
500 |
} catch (InterruptedException ex) { |
501 |
Thread.currentThread().interrupt(); |
502 |
} |
503 |
return tryGetStream(call, triesLeft - 1, wait); |
504 |
} |
505 |
} catch (RuntimeException e) { |
506 |
throw e; |
507 |
} catch (Exception e) { |
508 |
if (e instanceof IOException) { |
509 |
throw (IOException) e; |
510 |
} else { |
511 |
// Should not happen, runtime or I/O exceptions expected. |
512 |
throw new IllegalStateException(e); |
513 |
} |
514 |
} |
515 |
} |
516 |
|
456 |
private OutputStream getOutputStreamForMac42624(final OutputStream originalStream, final String name) { |
517 |
private OutputStream getOutputStreamForMac42624(final OutputStream originalStream, final String name) { |
457 |
final File f = getFile(name); |
518 |
final File f = getFile(name); |
458 |
final long lModified = f.lastModified(); |
519 |
final long lModified = f.lastModified(); |