Class ProcessStreamUtil


  • public final class ProcessStreamUtil
    extends java.lang.Object
    The process stream util class
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close​(java.io.Closeable closeable)
      Close silent a stream
      java.io.ByteArrayOutputStream convertStreamTo​(java.io.InputStream is)
      Convert the InputStream to String we use the Reader.read(char[] buffer) method.
      java.io.InputStream convertStreamToNewInputStream​(java.io.InputStream is)
      Convert the InputStream to String we use the Reader.read(char[] buffer) method.
      java.lang.String convertStreamToStr​(java.io.InputStream is)
      Convert the InputStream to String we use the Reader.read(char[] buffer) method.
      java.lang.String convertStreamToStr​(java.io.InputStream is, java.lang.String charsetName)
      Convert the InputStream to String we use the Reader.read(char[] buffer) method.
      void deleteDirectory​(java.nio.file.Path pathToBeDeleted)
      Delete a directory
      java.lang.String getId()
      Create a unique id
      static ProcessStreamUtil getInstance()
      Get the instance
      byte[] insertPrefix​(byte[] data, int length, byte[] prefix)
      Insert a prefix by a newline
      int pipeAvailableBytes​(java.io.InputStream source, IProcessOutputStream target)
      Pipe the available bytes from the source stream to the target.
      int pipeAvailableBytes​(java.io.InputStream source, java.io.OutputStream target, byte[] prefix, IProcessStreamExceptionHandler failureHandler)
      Pipe the available bytes from the source stream to the target.
      int pipeAvailableBytes​(java.io.InputStream source, java.io.OutputStream target, java.lang.String linePrefix, IProcessStreamExceptionHandler failureHandler)
      Pipe the available bytes from the source stream to the target.
      java.lang.String removeCR​(java.lang.String input)
      Remove CR
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getInstance

        public static ProcessStreamUtil getInstance()
        Get the instance
        Returns:
        the instance
      • getId

        public java.lang.String getId()
        Create a unique id
        Returns:
        the id
      • pipeAvailableBytes

        public int pipeAvailableBytes​(java.io.InputStream source,
                                      java.io.OutputStream target,
                                      java.lang.String linePrefix,
                                      IProcessStreamExceptionHandler failureHandler)
        Pipe the available bytes from the source stream to the target. In case a prefix is defined it will be inserted after a newline.
        Parameters:
        source - the input stream
        target - the output stream
        linePrefix - the prefix to add after every new line or null
        failureHandler - the failure handler
        Returns:
        the number of piped data; -1 in case of an error
      • pipeAvailableBytes

        public int pipeAvailableBytes​(java.io.InputStream source,
                                      java.io.OutputStream target,
                                      byte[] prefix,
                                      IProcessStreamExceptionHandler failureHandler)
        Pipe the available bytes from the source stream to the target. In case a prefix is defined it will be inserted after a newline.
        Parameters:
        source - the input stream
        target - the output stream
        prefix - the prefix to add after every new line or null
        failureHandler - the failure handler
        Returns:
        the number of piped data; -1 in case of an error
      • pipeAvailableBytes

        public int pipeAvailableBytes​(java.io.InputStream source,
                                      IProcessOutputStream target)
        Pipe the available bytes from the source stream to the target. In case a prefix is defined it will be inserted after a newline.
        Parameters:
        source - the input stream
        target - the output stream
        Returns:
        the number of piped data; -1 in case of an error
      • insertPrefix

        public byte[] insertPrefix​(byte[] data,
                                   int length,
                                   byte[] prefix)
        Insert a prefix by a newline
        Parameters:
        data - the data
        length - the length of the data
        prefix - the preifx to insert
        Returns:
        the prepared data
      • removeCR

        public java.lang.String removeCR​(java.lang.String input)
        Remove CR
        Parameters:
        input - the input
        Returns:
        the result
      • convertStreamTo

        public java.io.ByteArrayOutputStream convertStreamTo​(java.io.InputStream is)
                                                      throws java.io.IOException
        Convert the InputStream to String we use the Reader.read(char[] buffer) method. We iterate until the Reader return -1 which means there's no more data to read.
        Parameters:
        is - the input stream
        Returns:
        the result
        Throws:
        java.io.IOException - in case of error
      • convertStreamToStr

        public java.lang.String convertStreamToStr​(java.io.InputStream is)
                                            throws java.io.IOException
        Convert the InputStream to String we use the Reader.read(char[] buffer) method. We iterate until the Reader return -1 which means there's no more data to read.
        Parameters:
        is - the input stream
        Returns:
        the result
        Throws:
        java.io.IOException - in case of error
      • convertStreamToStr

        public java.lang.String convertStreamToStr​(java.io.InputStream is,
                                                   java.lang.String charsetName)
                                            throws java.io.IOException
        Convert the InputStream to String we use the Reader.read(char[] buffer) method. We iterate until the Reader return -1 which means there's no more data to read.
        Parameters:
        is - the input stream
        charsetName - the charset name
        Returns:
        the result
        Throws:
        java.io.IOException - in case of error
      • convertStreamToNewInputStream

        public java.io.InputStream convertStreamToNewInputStream​(java.io.InputStream is)
                                                          throws java.io.IOException
        Convert the InputStream to String we use the Reader.read(char[] buffer) method. We iterate until the Reader return -1 which means there's no more data to read.
        Parameters:
        is - the input stream
        Returns:
        the result
        Throws:
        java.io.IOException - in case of error
      • close

        public void close​(java.io.Closeable closeable)
        Close silent a stream
        Parameters:
        closeable - close
      • deleteDirectory

        public void deleteDirectory​(java.nio.file.Path pathToBeDeleted)
        Delete a directory
        Parameters:
        pathToBeDeleted - the directory