Class CharSink


  • @GwtIncompatible
    public abstract class CharSink
    extends 
    A destination to which characters can be written, such as a text file. Unlike a , a CharSink is not an open, stateful stream that can be written to and closed. Instead, it is an immutable supplier of Writer instances.

    CharSink provides two kinds of methods:

    • Methods that return a writer: These methods should return a new, independent instance each time they are called. The caller is responsible for ensuring that the returned writer is closed.
    • Convenience methods: These are implementations of common operations that are typically implemented by opening a writer using one of the methods in the first category, doing something and finally closing the writer that was opened.

    Any using ByteSink.asCharSink(Charset). Characters written to the resulting CharSink will written to the ByteSink as encoded bytes.

    Since:
    14.0
    Author:
    Colin Decker
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected CharSink()
      Constructor for use by subclasses.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      openBufferedStream()
      Opens a new buffered for writing to this sink.
      abstract openStream()
      Opens a new for writing to this sink.
      void  charSequence)
      Writes the given character sequence to this sink.
      long  readable)
      Writes all the text from the given (such as a ) to this sink.
      void <? extends > lines)
      Writes the given lines of text to this sink with each line (including the last) terminated with the operating system's default line separator.
      void <? extends > lines,  lineSeparator)
      Writes the given lines of text to this sink with each line (including the last) terminated with the given line separator.
      void <? extends > lines)
      Writes the given lines of text to this sink with each line (including the last) terminated with the operating system's default line separator.
      void <? extends > lines,  lineSeparator)
      Writes the given lines of text to this sink with each line (including the last) terminated with the given line separator.
      • Methods inherited from class java.lang.

        , , , , , , , , , ,
    • Constructor Detail

      • CharSink

        protected CharSink()
        Constructor for use by subclasses.
    • Method Detail

      • openStream

        public abstract  openStream()
                                   throws 
        Opens a new for writing to this sink. This method returns a new, independent writer each time it is called.

        The caller is responsible for ensuring that the returned writer is closed.

        Throws:
        - if an I/O error occurs while opening the writer
      • openBufferedStream

        public  openBufferedStream()
                                  throws 
        Opens a new buffered for writing to this sink. The returned stream is not required to be a in order to allow implementations to simply delegate to openStream() when the stream returned by that method does not benefit from additional buffering. This method returns a new, independent writer each time it is called.

        The caller is responsible for ensuring that the returned writer is closed.

        Throws:
        - if an I/O error occurs while opening the writer
        Since:
        15.0 (in 14.0 with return type )
      • write

        public void  charSequence)
                   throws 
        Writes the given character sequence to this sink.
        Throws:
        - if an I/O error while writing to this sink
      • writeLines

        public void <? extends > lines)
                        throws 
        Writes the given lines of text to this sink with each line (including the last) terminated with the operating system's default line separator. This method is equivalent to writeLines(lines, System.getProperty("line.separator")).
        Throws:
        - if an I/O error occurs while writing to this sink
      • writeLines

        public void <? extends > lines,
                                lineSeparator)
                        throws 
        Writes the given lines of text to this sink with each line (including the last) terminated with the given line separator.
        Throws:
        - if an I/O error occurs while writing to this sink
      • writeLines

        @Beta
        public void <? extends > lines)
                        throws 
        Writes the given lines of text to this sink with each line (including the last) terminated with the operating system's default line separator. This method is equivalent to writeLines(lines, System.getProperty("line.separator")).
        Throws:
        - if an I/O error occurs while writing to this sink
        Since:
        22.0
      • writeLines

        @Beta
        public void <? extends > lines,
                                lineSeparator)
                        throws 
        Writes the given lines of text to this sink with each line (including the last) terminated with the given line separator.
        Throws:
        - if an I/O error occurs while writing to this sink
        Since:
        22.0
      • writeFrom

        public long  readable)
                       throws 
        Writes all the text from the given (such as a ) to this sink. Does not close readable if it is Closeable.
        Returns:
        the number of characters written
        Throws:
        - if an I/O error occurs while reading from readable or writing to this sink