diff options
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java index e1ac9fb7ae..af3054766e 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java @@ -858,6 +858,24 @@ public class FileSystemUtils { } /** + * The type of {@link IOException} thrown by {@link #readWithKnownFileSize} when fewer bytes than + * expected are read. + */ + public static class ShortReadIOException extends IOException { + public final Path path; + public final int fileSize; + public final int numBytesRead; + + private ShortReadIOException(Path path, int fileSize, int numBytesRead) { + super("Unexpected short read from file '" + path + "' (expected " + fileSize + ", got " + + numBytesRead + " bytes)"); + this.path = path; + this.fileSize = fileSize; + this.numBytesRead = numBytesRead; + } + } + + /** * Reads the given file {@code path}, assumed to have size {@code fileSize}, and does a sanity * check on the number of bytes read. * @@ -873,8 +891,7 @@ public class FileSystemUtils { int fileSizeInt = (int) fileSize; byte[] bytes = readContentWithLimit(path, fileSizeInt); if (fileSizeInt > bytes.length) { - throw new IOException("Unexpected short read from file '" + path - + "' (expected " + fileSizeInt + ", got " + bytes.length + " bytes)"); + throw new ShortReadIOException(path, fileSizeInt, bytes.length); } return bytes; } |