### Question:
FSDataInputStreamTail { public static long readTailForFileSize(String path, long paddedFileSize, FSDataInputStream inputStream) throws IOException { long position = max(paddedFileSize - MAX_SUPPORTED_PADDING_BYTES, 0); long maxEOFAt = paddedFileSize + 1; long startPos = inputStream.getPos(); try { inputStream.seek(position); int c; while (position < maxEOFAt) { c = inputStream.read(); if (c < 0) { return position; } position++; } throw rejectInvalidFileSize(path, paddedFileSize); } finally { inputStream.seek(startPos); } } private  FSDataInputStreamTail(long fileSize, Slice tailSlice); static FSDataInputStreamTail readTail(String path, long paddedFileSize, FSDataInputStream inputStream, int length); static long readTailForFileSize(String path, long paddedFileSize, FSDataInputStream inputStream); long getFileSize(); Slice getTailSlice(); static final int MAX_SUPPORTED_PADDING_BYTES; }### Answer:
@Test(dataProvider = "validFileSizeAndPaddedFileSize") public void testReadTailForFileSize(int fileSize, int paddedFileSize) throws Exception { fs.truncate(tempFile, 0); if (fileSize > 0) { try (FSDataOutputStream os = fs.append(tempFile)) { os.write(countingTestFileContentsWithLength(fileSize)); } } assertEquals(fs.getFileLinkStatus(tempFile).getLen(), fileSize); try (FSDataInputStream is = fs.open(tempFile)) { assertEquals(FSDataInputStreamTail.readTailForFileSize(tempFile.toString(), paddedFileSize, is), fileSize); } }
@Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = "Incorrect file size \\(.*\\) for file \\(end of stream not reached\\): file:.*") public void testReadTailForFileSizeNoEndOfFileFound() throws Exception { byte[] contents = countingTestFileContentsWithLength(256); try (FSDataOutputStream os = fs.append(tempFile)) { os.write(contents); } assertEquals(fs.getFileLinkStatus(tempFile).getLen(), contents.length); try (FSDataInputStream is = fs.open(tempFile)) { FSDataInputStreamTail.readTailForFileSize(tempFile.toString(), 128, is); fail("Expected failure to find end of stream"); } }