From ffca7f9d6bc38f101c22a80acafea04f18c5119b Mon Sep 17 00:00:00 2001 From: Greg Watson Date: Wed, 17 Aug 2011 12:27:48 +0200 Subject: [PATCH] Bug 349730: Content for non-local files --- .../core/parser/InternalParserUtil.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/InternalParserUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/InternalParserUtil.java index 76688c442ce..bc2f1d5a5d9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/InternalParserUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/InternalParserUtil.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.parser; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -154,6 +155,20 @@ public class InternalParserUtil extends ParserFactory { InputStream in; try { in= file.getContents(true); + if (!(in instanceof FileInputStream)) { + /* + * In general, non-local file-systems will not use FileInputStream. Instead make a + * cached copy of the file and open an input stream to that. + */ + IFileStore store = EFS.getStore(file.getLocationURI()); + File fileCache = store.toLocalFile(EFS.CACHE, null); + try { + in = new FileInputStream(fileCache); + } catch (FileNotFoundException e) { + CCorePlugin.log(e); + return null; + } + } try { return createFileContent(path, file.getCharset(), in); } finally { @@ -221,6 +236,9 @@ public class InternalParserUtil extends ParserFactory { private static InternalFileContent createFileContent(String path, String charset, InputStream in) { try { AbstractCharArray chars= FileCharArray.create(path, charset, in); + if (chars == null) + return null; + return new InternalFileContent(path, chars); } catch (IOException e) { CCorePlugin.log(e);