HarFileSystem extends FileSystem { static BlockLocation[] fixBlockLocations(BlockLocation[] locations, long start, long len, long fileOffsetInHar) { long end = start + len; for (BlockLocation location : locations) { long harBlockStart = location.getOffset() - fileOffsetInHar; long harBlockEnd = harBlockStart + location.getLength(); if (start > harBlockStart) { location.setOffset(start); location.setLength(location.getLength() - (start - harBlockStart)); } else { location.setOffset(harBlockStart); } if (harBlockEnd > end) { location.setLength(location.getLength() - (harBlockEnd - end)); } } return locations; } HarFileSystem();  HarFileSystem(FileSystem fs); @Override String getScheme(); @Override void initialize(URI name, Configuration conf); @Override Configuration getConf(); int getHarVersion(); @Override Path getWorkingDirectory(); @Override Path getInitialWorkingDirectory(); @Override FsStatus getStatus(Path p); @Override URI getUri(); @Override Path resolvePath(Path p); @Override Path makeQualified(Path path); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start,
                                               long len); static int getHarHash(Path p); @Override FileStatus getFileStatus(Path f); @Override FileChecksum getFileChecksum(Path f, long length); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataInputStream open(PathHandle fd, int bufferSize); @Override FileSystem[] getChildFileSystems(); @Override FSDataOutputStream create(Path f, FsPermission permission,
      boolean overwrite, int bufferSize, short replication, long blockSize,
      Progressable progress); @Override FSDataOutputStream createNonRecursive(Path f, boolean overwrite,
      int bufferSize, short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override void close(); @Override boolean setReplication(Path src, short replication); @Override boolean rename(Path src, Path dst); @Override FSDataOutputStream append(Path f); @Override boolean truncate(Path f, long newLength); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override Path getHomeDirectory(); @Override void setWorkingDirectory(Path newDir); @Override boolean mkdirs(Path f, FsPermission permission); @Override void copyFromLocalFile(boolean delSrc, boolean overwrite,
      Path src, Path dst); @Override void copyFromLocalFile(boolean delSrc, boolean overwrite,
      Path[] srcs, Path dst); @Override void copyToLocalFile(boolean delSrc, Path src, Path dst); @Override Path startLocalOutput(Path fsOutputFile, Path tmpLocalFile); @Override void completeLocalOutput(Path fsOutputFile, Path tmpLocalFile); @Override void setOwner(Path p, String username, String groupname); @Override void setTimes(Path p, long mtime, long atime); @Override void setPermission(Path p, FsPermission permission); @Override boolean hasPathCapability(final Path path, final String capability); @SuppressWarnings("deprecation") @Override FsServerDefaults getServerDefaults(); @Override FsServerDefaults getServerDefaults(Path f); @Override long getUsed(); @Override long getUsed(Path path); @SuppressWarnings("deprecation") @Override long getDefaultBlockSize(); @SuppressWarnings("deprecation") @Override long getDefaultBlockSize(Path f); @SuppressWarnings("deprecation") @Override short getDefaultReplication(); @Override short getDefaultReplication(Path f); @Override FSDataOutputStreamBuilder createFile(Path path); @Override FSDataOutputStreamBuilder appendFile(Path path); static final String METADATA_CACHE_ENTRIES_KEY; static final int METADATA_CACHE_ENTRIES_DEFAULT; static final int VERSION; }
@Test public void testFixBlockLocations() { { BlockLocation[] b = { new BlockLocation(null, null, 10, 10) }; HarFileSystem.fixBlockLocations(b, 0, 20, 5); assertThat(b[0].getOffset()).isEqualTo(5); assertThat(b[0].getLength()).isEqualTo(10); } { BlockLocation[] b = { new BlockLocation(null, null, 10, 10) }; HarFileSystem.fixBlockLocations(b, 0, 20, 15); assertThat(b[0].getOffset()).isZero(); assertThat(b[0].getLength()).isEqualTo(5); } { BlockLocation[] b = { new BlockLocation(null, null, 10, 10) }; HarFileSystem.fixBlockLocations(b, 0, 10, 5); assertThat(b[0].getOffset()).isEqualTo(5); assertThat(b[0].getLength()).isEqualTo(5); } { BlockLocation[] b = { new BlockLocation(null, null, 10, 10) }; HarFileSystem.fixBlockLocations(b, 0, 6, 12); assertThat(b[0].getOffset()).isZero(); assertThat(b[0].getLength()).isEqualTo(6); } { BlockLocation[] b = { new BlockLocation(null, null, 10, 10) }; HarFileSystem.fixBlockLocations(b, 3, 20, 5); assertThat(b[0].getOffset()).isEqualTo(5); assertThat(b[0].getLength()).isEqualTo(10); } { BlockLocation[] b = { new BlockLocation(null, null, 10, 10) }; HarFileSystem.fixBlockLocations(b, 3, 20, 15); assertThat(b[0].getOffset()).isEqualTo(3); assertThat(b[0].getLength()).isEqualTo(2); } { BlockLocation[] b = { new BlockLocation(null, null, 10, 10) }; HarFileSystem.fixBlockLocations(b, 3, 7, 5); assertThat(b[0].getOffset()).isEqualTo(5); assertThat(b[0].getLength()).isEqualTo(5); } { BlockLocation[] b = { new BlockLocation(null, null, 10, 10) }; HarFileSystem.fixBlockLocations(b, 3, 3, 12); assertThat(b[0].getOffset()).isEqualTo(3); assertThat(b[0].getLength()).isEqualTo(3); } { BlockLocation[] b = { new BlockLocation(null, null, 512, 512), new BlockLocation(null, null, 1024, 512) }; HarFileSystem.fixBlockLocations(b, 0, 512, 896); assertThat(b[0].getOffset()).isZero(); assertThat(b[0].getLength()).isEqualTo(128); assertThat(b[1].getOffset()).isEqualTo(128); assertThat(b[1].getLength()).isEqualTo(384); } }