diff options
author | 2017-11-06 19:49:16 +0100 | |
---|---|---|
committer | 2017-11-06 20:20:32 +0100 | |
commit | 67c84b1036ad02ba2384fa75fb28e779a488f3d4 (patch) | |
tree | c70665241fab2a4947f0941659b8e6421eabb44c /src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java | |
parent | 11517396816697ad1c48a71e47f37d9206225741 (diff) |
Break dependency on vfs from the interface of syntax and cmdline.
These libs are exposed externally, implying that the vfs is also exposed externally.
We break out PathFragment from vfs to still use this in their interface. This class is a much smaller dependency than the entire vfs.
PiperOrigin-RevId: 174729373
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java b/src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java index 5f2ce3fa66..05663e2960 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java @@ -13,10 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.syntax; -import com.google.devtools.build.lib.vfs.FileSystemUtils; -import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; - import java.io.IOException; /** @@ -38,20 +35,9 @@ public abstract class ParserInputSource { */ public abstract PathFragment getPath(); - /** - * Create an input source instance by (eagerly) reading from the file at - * path. The file is assumed to be ISO-8859-1 encoded and smaller than - * 2 Gigs - these assumptions are reasonable for BUILD files, which is - * all we care about here. - */ - public static ParserInputSource create(Path path) throws IOException { - return create(path, path.getFileSize()); - } - - public static ParserInputSource create(Path path, long fileSize) throws IOException { - byte[] bytes = FileSystemUtils.readWithKnownFileSize(path, fileSize); - char[] content = FileSystemUtils.convertFromLatin1(bytes); - return create(content, path.asFragment()); + public static ParserInputSource create(byte[] bytes, PathFragment path) throws IOException { + char[] content = convertFromLatin1(bytes); + return create(content, path); } /** @@ -82,4 +68,12 @@ public abstract class ParserInputSource { } }; } + + private static char[] convertFromLatin1(byte[] content) { + char[] latin1 = new char[content.length]; + for (int i = 0; i < latin1.length; i++) { // yeah, latin1 is this easy! :-) + latin1[i] = (char) (0xff & content[i]); + } + return latin1; + } } |