@Override public String readLine() throws IOException { if (reader == null) { try { reader = new ReverseFileReader(blob); } catch (StorageException e) { throw new IOException(e); } } return reader.readLine(); }
public String readLine() throws IOException { if (bufferOffset == -1 && fileOffset == 0) { return null; } if (buffer == null) { readBlock(); } List<String> result = new ArrayList<>(1); while (true) { result.add(readUntilNewLine()); if (bufferOffset > -1) { // stopped on the '\n' break; } if (fileOffset == 0) { // reached the beginning of the file break; } readBlock(); } Collections.reverse(result); return String.join("", result); } }
@Test public void testEmptyFile() throws IOException, URISyntaxException, StorageException { List<String> entries = createFile( 0, 80); ReverseFileReader reader = new ReverseFileReader(getBlob(), 256); assertEquals(entries, reader); }
@Test public void testReverseReader() throws IOException, URISyntaxException, StorageException { List<String> entries = createFile( 1024, 80); ReverseFileReader reader = new ReverseFileReader(getBlob(), 256); assertEquals(entries, reader); }
@Override public String readLine() throws IOException { if (reader == null) { try { reader = new ReverseFileReader(blob); } catch (StorageException e) { throw new IOException(e); } } return reader.readLine(); }
@Test public void test1ByteBlock() throws IOException, URISyntaxException, StorageException { List<String> entries = createFile( 10, 16); ReverseFileReader reader = new ReverseFileReader(getBlob(), 1); assertEquals(entries, reader); }
public String readLine() throws IOException { if (bufferOffset == -1 && fileOffset == 0) { return null; } if (buffer == null) { readBlock(); } List<String> result = new ArrayList<>(1); while (true) { result.add(readUntilNewLine()); if (bufferOffset > -1) { // stopped on the '\n' break; } if (fileOffset == 0) { // reached the beginning of the file break; } readBlock(); } Collections.reverse(result); return String.join("", result); } }