Class StreamPlugThread

All Implemented Interfaces:
Closeable, AutoCloseable, Runnable

public final class StreamPlugThread extends ThreadService.ConfigurableRunnable implements Closeable
The Class StreamPlugThread.
  • Field Details

    • DEFAULT_BUFF_SIZE

      public static final int DEFAULT_BUFF_SIZE
      The Constant DEFAULT_BUFF_SIZE.
  • Constructor Details

    • StreamPlugThread

      public StreamPlugThread(InputStream in, OutputStream out)
      Instantiates a new stream plug thread.
      Parameters:
      in - the in
      out - the out
  • Method Details

    • setBuffSize

      public void setBuffSize(int buffSize)
      Sets the buff size.
      Parameters:
      buffSize - the new buff size
    • getBuffSize

      public int getBuffSize()
      Gets the buff size.
      Returns:
      the buff size
    • setFlush

      public void setFlush(boolean flush)
      Sets the flush.
      Parameters:
      flush - the new flush
    • getFlush

      public boolean getFlush()
      Gets the flush.
      Returns:
      the flush
    • setReadFully

      public void setReadFully(boolean readFully)
      Sets the read fully.
      Parameters:
      readFully - the new read fully
    • getReadFully

      public boolean getReadFully()
      Gets the read fully.
      Returns:
      the read fully
    • alive

      public boolean alive()
      Alive.
      Returns:
      true, if successful
    • close

      public void close()
      Close.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getMessage

      public String getMessage()
      Gets the message.
      Returns:
      the message
    • plugTogether

      public static void plugTogether(Socket source, Socket target, Closeable... toClose) throws IOException
      Plug together.
      Parameters:
      source - the source
      target - the target
      toClose - the to close
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • plugTogether

      public static void plugTogether(Socket source, InputStream in, OutputStream out, Closeable toClose) throws IOException
      Plug together.
      Parameters:
      source - the source
      in - the in
      out - the out
      toClose - the to close
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • readFully

      public static int readFully(InputStream in, byte[] b, int off, int len) throws IOException
      Read fully.
      Parameters:
      in - the in
      b - the b
      off - the off
      len - the len
      Returns:
      the int
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • copy

      public static long copy(OutputStream out, InputStream in, int bufferSize) throws IOException
      Copy.
      Parameters:
      out - the out
      in - the in
      bufferSize - the buffer size
      Returns:
      the long
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • copy

      public static long copy(OutputStream out, InputStream in, int bufferSize, long size) throws IOException
      Copy.
      Parameters:
      out - the out
      in - the in
      bufferSize - the buffer size
      size - the size
      Returns:
      the long
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • consume

      public static long consume(InputStream in, int bufferSize) throws IOException
      Just consume the input stream, but do nothing with it.
      Parameters:
      in - the in
      bufferSize - the buffer size
      Returns:
      the long
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • closeQuietly

      public static void closeQuietly(Process process)
      Close quietly.
      Parameters:
      process - the process
    • closeQuietly

      public static void closeQuietly(Scanner scanner)
      Close quietly.
      Parameters:
      scanner - the scanner
    • closeQuietly

      public static void closeQuietly(AutoCloseable closeable)
      Close quietly.
      Parameters:
      closeable - the closeable
    • closeQuietly

      public static void closeQuietly(Closeable closeable)
      Close quietly.
      Parameters:
      closeable - the closeable
    • closeQuietly

      public static void closeQuietly(Socket socket)
      Close quietly.
      Parameters:
      socket - the socket
    • closeQuietly

      public static void closeQuietly(ServerSocket serverSocket)
      Close quietly.
      Parameters:
      serverSocket - the server socket
    • flush

      public void flush() throws IOException
      Flush the underlying output stream.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • configurableRun

      public void configurableRun()
      Configurable run. Configurable run.
      Specified by:
      configurableRun in class ThreadService.ConfigurableRunnable
    • getExceptionMessage

      public static String getExceptionMessage(String input)
      Gets the exception message. Allow showing better message for sftp errors in the form '4: '.
      Parameters:
      input - the input
      Returns:
      the exception message
    • toClose

      public void toClose(Closeable... toClose)
      Specify which Closeable objects should be closed when the plug is closed.
      Parameters:
      toClose - the close
    • toClose

      public void toClose(Closeable toClose)
      Specify which Closeable object should be closed when the plug is closed.
      Parameters:
      toClose - the to close