Class ProcessStreamUtil
- java.lang.Object
-
- com.github.toolarium.system.command.process.stream.util.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 streamjava.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 directoryjava.lang.String
getId()
Create a unique idstatic ProcessStreamUtil
getInstance()
Get the instancebyte[]
insertPrefix(byte[] data, int length, byte[] prefix)
Insert a prefix by a newlineint
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
-
-
-
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 streamtarget
- the output streamlinePrefix
- the prefix to add after every new line or nullfailureHandler
- 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 streamtarget
- the output streamprefix
- the prefix to add after every new line or nullfailureHandler
- 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 streamtarget
- 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 datalength
- the length of the dataprefix
- 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 streamcharsetName
- 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
-
-