Class BinaryFileBuffer

java.lang.Object
com.google.code.externalsorting.BinaryFileBuffer
All Implemented Interfaces:
IOStringStack

public final class BinaryFileBuffer extends Object implements IOStringStack
This is essentially a thin wrapper on top of a BufferedReader... which keeps the last line in memory.
  • Constructor Details

    • BinaryFileBuffer

      public BinaryFileBuffer(BufferedReader r) throws IOException
      Constructs a BinaryFileBuffer wrapping the given BufferedReader.
      Parameters:
      r - the BufferedReader to wrap
      Throws:
      IOException - if an I/O error occurs
  • Method Details

    • close

      public void close() throws IOException
      Closes the underlying BufferedReader.
      Specified by:
      close in interface IOStringStack
      Throws:
      IOException - if an I/O error occurs
    • empty

      public boolean empty()
      Checks if the buffer is empty.
      Specified by:
      empty in interface IOStringStack
      Returns:
      true if there are no more lines to read
    • peek

      public String peek()
      Returns the next line in the buffer without removing it.
      Specified by:
      peek in interface IOStringStack
      Returns:
      the next line as a String, or null if empty
    • pop

      public String pop() throws IOException
      Removes and returns the next line in the buffer.
      Specified by:
      pop in interface IOStringStack
      Returns:
      the next line as a String
      Throws:
      IOException - if an I/O error occurs