Class PrintOutput

java.lang.Object
java.io.OutputStream
org.basex.io.out.PrintOutput
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
Direct Known Subclasses:
ArrayOutput, EncoderOutput, NewlineOutput, NullOutput

public class PrintOutput extends OutputStream
This class is a stream-wrapper for textual data encoded in UTF8.
Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected long
    Maximum numbers of bytes to write.
    protected final OutputStream
    Output stream reference (can be null).
    protected long
    Number of bytes written.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor, given a filename.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
     
    boolean
    Checks if the output stream is exhausted.
    final void
     
    Returns a new instance for the given output stream.
    void
    print(byte[] token)
    Prints a token to the output stream.
    void
    print(int cp)
    Prints a single codepoint.
    void
    print(String string)
    Prints a string to the output stream.
    final void
    println(byte[] token)
    Prints a token to the output stream, followed by a system-specific newline.
    final void
    println(String string)
    Prints a string and newline to the output stream.
    final void
    setLimit(int limit)
    Sets the maximum number of bytes to be written.
    final long
    Returns the number of written bytes.
    void
    write(int b)
     

    Methods inherited from class java.io.OutputStream

    nullOutputStream, write, write

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • os

      protected final OutputStream os
      Output stream reference (can be null).
    • max

      protected long max
      Maximum numbers of bytes to write.
    • size

      protected long size
      Number of bytes written.
  • Constructor Details

    • PrintOutput

      public PrintOutput(IOFile file) throws IOException
      Constructor, given a filename.
      Parameters:
      file - file
      Throws:
      IOException - I/O exception
  • Method Details

    • get

      public static PrintOutput get(OutputStream out)
      Returns a new instance for the given output stream.
      Parameters:
      out - output stream reference
      Returns:
      print output
    • setLimit

      public final void setLimit(int limit)
      Sets the maximum number of bytes to be written. Note that the limit might break unicode characters.
      Parameters:
      limit - maximum
    • write

      public void write(int b) throws IOException
      Specified by:
      write in class OutputStream
      Throws:
      IOException
    • print

      public void print(int cp) throws IOException
      Prints a single codepoint.
      Parameters:
      cp - codepoint to be printed
      Throws:
      IOException - I/O exception
    • print

      public void print(byte[] token) throws IOException
      Prints a token to the output stream.
      Parameters:
      token - token to be written
      Throws:
      IOException - I/O exception
    • print

      public void print(String string) throws IOException
      Prints a string to the output stream.
      Parameters:
      string - string to be written
      Throws:
      IOException - I/O exception
    • println

      public final void println(String string) throws IOException
      Prints a string and newline to the output stream.
      Parameters:
      string - string to be written
      Throws:
      IOException - I/O exception
    • println

      public final void println(byte[] token) throws IOException
      Prints a token to the output stream, followed by a system-specific newline.
      Parameters:
      token - token to be written
      Throws:
      IOException - I/O exception
    • size

      public final long size()
      Returns the number of written bytes.
      Returns:
      number of written bytes
    • flush

      public final void flush() throws IOException
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException
    • close

      public final void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException
    • finished

      public boolean finished()
      Checks if the output stream is exhausted.
      Returns:
      true if stream is exhausted