@Override public OutputStream getCacheOutputStream(SourceId sourceId) { if (sourceId.getSourceSupplier() != this) return null; if (sourceId.source1 != null) { return mySup1.getCacheOutputStream(sourceId.source1); } else { return mySup2.getCacheOutputStream(sourceId.source2); } }
@Override public boolean isAvailable(SourceId sourceId) { if (sourceId.getStorage() != this) return false; Path file = sourceFileForSource(sourceId); try { return Files.exists(file) && Files.getLastModifiedTime(file).equals(sourceId.myMtime); } catch (IOException ignored) { } return false; }
@Override public OutputStream getCacheOutputStream(SourceId sourceId) { if (sourceId.getStorage() != this) return null; Path file = cacheFileForSource(sourceId); try { Files.createDirectories(file.getParent()); return Files.newOutputStream(file); } catch (IOException ignored) { } return null; }
@Override public Abstract.ClassDefinition loadSource(SourceId sourceId, ErrorReporter errorReporter) throws IOException { if (sourceId.getStorage() != this) return null; if (!isAvailable(sourceId)) return null; Path file = sourceFileForSource(sourceId); FileSource fileSource = new FileSource(sourceId, file); Abstract.ClassDefinition definition = fileSource.load(errorReporter); // Make sure we loaded the right revision return Files.getLastModifiedTime(file).equals(sourceId.myMtime) ? definition : null; }
@Override public InputStream getCacheInputStream(SourceId sourceId) { if (sourceId.getStorage() != this) return null; Path file = cacheFileForSource(sourceId); if (Files.isReadable(file)) { try { return Files.newInputStream(file); } catch (IOException ignored) { } } return null; }
private Path cacheFileForSource(SourceId sourceId) { return cacheFile(baseFile(sourceId.getModulePath()), sourceId.myMtime.toMillis()); }
private Path sourceFileForSource(SourceId sourceId) { return sourceFile(baseFile(sourceId.getModulePath())); }