Skip to content

Commit

Permalink
Read the cached XSD, DTD grammar file with lazy mode
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed May 12, 2020
1 parent 811cb64 commit 25cf8e4
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.lemminx.extensions.contentmodel.uriresolver;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;

Expand All @@ -32,6 +33,30 @@
*/
public class XMLCacheResolverExtension implements URIResolverExtension {

private static class XMLFileInputSource extends XMLInputSource {

private final Path file;

public XMLFileInputSource(XMLResourceIdentifier resourceIdentifier, Path file) {
super(resourceIdentifier);
this.file = file;
}

@Override
public InputStream getByteStream() {
// Load the file input stream only if it is used
InputStream input = super.getByteStream();
if (input == null) {
try {
super.setByteStream(Files.newInputStream(file));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return super.getByteStream();
}
}

private final CacheResourcesManager cacheResourcesManager;

public XMLCacheResolverExtension() {
Expand All @@ -53,9 +78,7 @@ public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) th
Path file = getCachedResource(url);
if (file != null) {
// The resource was downloaded locally, use it.
XMLInputSource source = new XMLInputSource(resourceIdentifier);
source.setByteStream(Files.newInputStream(file));
return source;
return new XMLFileInputSource(resourceIdentifier, file);
}
return null;
}
Expand Down

0 comments on commit 25cf8e4

Please sign in to comment.