Class BufferedWriter

  • Direct Known Subclasses:
    LineBufferedWriter

    public class BufferedWriter
    extends BufferedIOMixin
    Buffer for a writable sequential RawIO object.
    Author:
    Philip Jenvey
    • Constructor Summary

      Constructors 
      Constructor Description
      BufferedWriter​(RawIOBase rawIO, int bufferSize)
      Construct a BufferedWriter of bufferSize, wrapping the given RawIOBase.
    • Constructor Detail

      • BufferedWriter

        public BufferedWriter​(RawIOBase rawIO,
                              int bufferSize)
        Construct a BufferedWriter of bufferSize, wrapping the given RawIOBase.
        Parameters:
        rawIO -
        bufferSize -
    • Method Detail

      • write

        public int write​(java.nio.ByteBuffer bytes)
        Description copied from class: BufferedIOBase
        Write the given ByteBuffer to the IO stream. Returns the number of bytes written, which may be less than bytes.remaining().
        Overrides:
        write in class BufferedIOBase
        Parameters:
        bytes - a ByteBuffer value
        Returns:
        the number of bytes written as an int
      • flush

        public void flush()
        Description copied from class: IOBase
        Flushes write buffers, if applicable. This is a no-op for read-only and non-blocking streams.
        Overrides:
        flush in class BufferedIOMixin
      • tell

        public long tell()
        Description copied from class: IOBase
        Return the current stream position.
        Overrides:
        tell in class BufferedIOMixin
        Returns:
        a long position value
      • seek

        public long seek​(long pos,
                         int whence)
        Description copied from class: IOBase
        Seek to byte offset pos relative to position indicated by whence.
        Semantics
        whence Seek to pos
        0 Start of stream (the default).Should be ≥0.
        1 Current position + pos Either sign.
        2 End of stream + pos Usually ≤0.
        Returns the new absolute position.
        Overrides:
        seek in class BufferedIOMixin
        Parameters:
        pos - a long position value
        whence - an int whence value
        Returns:
        a long position value seeked to
      • buffered

        public boolean buffered()
        Description copied from class: BufferedIOBase
        Return true if this objects buffer contains any data.
        Overrides:
        buffered in class BufferedIOBase
        Returns:
        boolean whether or not any data is currently buffered
      • readall

        public java.nio.ByteBuffer readall()
        Description copied from class: BufferedIOBase
        Read until EOF.
        Overrides:
        readall in class BufferedIOBase
        Returns:
        a ByteBuffer containing the bytes read
      • readinto

        public int readinto​(java.nio.ByteBuffer bytes)
        Description copied from class: BufferedIOBase
        Read up to bytes.remaining() bytes into the given ByteBuffer. Returns number of bytes read (0 for EOF).
        Overrides:
        readinto in class BufferedIOBase
        Parameters:
        bytes - a ByteBuffer to read bytes into
        Returns:
        the amount of data read as an int
      • read1

        public int read1​(java.nio.ByteBuffer bytes)
        Description copied from class: BufferedIOBase
        Reads up to bytes.remaining() bytes. Returns up to bytes.remaining() bytes. If at least one byte is buffered, we only return buffered bytes. Otherwise, we do one raw read.
        Overrides:
        read1 in class BufferedIOBase
        Parameters:
        bytes - a ByteBuffer to read bytes into
        Returns:
        the amount of data read as an int
      • readable

        public boolean readable()
        Description copied from class: IOBase
        Return whether this file was opened for reading.
        Overrides:
        readable in class BufferedIOMixin
        Returns:
        true if the file was opened for reading