Class ProcessStreamUtil
- java.lang.Object
-
- com.github.toolarium.system.command.process.stream.util.ProcessStreamUtil
-
public final class ProcessStreamUtil extends java.lang.ObjectThe process stream util class
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose(java.io.Closeable closeable)Close silent a streamjava.io.ByteArrayOutputStreamconvertStreamTo(java.io.InputStream is)Convert the InputStream to String we use the Reader.read(char[] buffer) method.java.io.InputStreamconvertStreamToNewInputStream(java.io.InputStream is)Convert the InputStream to String we use the Reader.read(char[] buffer) method.java.lang.StringconvertStreamToStr(java.io.InputStream is)Convert the InputStream to String we use the Reader.read(char[] buffer) method.java.lang.StringconvertStreamToStr(java.io.InputStream is, java.lang.String charsetName)Convert the InputStream to String we use the Reader.read(char[] buffer) method.voiddeleteDirectory(java.nio.file.Path pathToBeDeleted)Delete a directoryjava.lang.StringgetId()Create a unique idstatic ProcessStreamUtilgetInstance()Get the instancebyte[]insertPrefix(byte[] data, int length, byte[] prefix)Insert a prefix by a newlineintpipeAvailableBytes(java.io.InputStream source, IProcessOutputStream target)Pipe the available bytes from the source stream to the target.intpipeAvailableBytes(java.io.InputStream source, java.io.OutputStream target, byte[] prefix, IProcessStreamExceptionHandler failureHandler)Pipe the available bytes from the source stream to the target.intpipeAvailableBytes(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.StringremoveCR(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.IOExceptionConvert 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.IOExceptionConvert 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.IOExceptionConvert 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.IOExceptionConvert 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
-
-