Class StreamUtil
- java.lang.Object
-
- com.github.toolarium.system.command.impl.util.StreamUtil
-
public final class StreamUtil extends java.lang.Object
Stream util class
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description long
channelCopy(java.io.InputStream src, java.io.OutputStream dest)
This method copies data from the src and writes it to the dest until EOF on src.long
channelCopy(java.nio.channels.ReadableByteChannel src, java.nio.channels.WritableByteChannel dest)
This method copies data from the src channel and writes it to the dest channel until EOF on src.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.static StreamUtil
getInstance()
Get the instance
-
-
-
Method Detail
-
getInstance
public static StreamUtil getInstance()
Get the instance- Returns:
- the instance
-
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
-
channelCopy
public long channelCopy(java.io.InputStream src, java.io.OutputStream dest) throws java.io.IOException
This method copies data from the src and writes it to the dest until EOF on src.- Parameters:
src
- the source streamdest
- the destination stream- Returns:
- the copied bytes
- Throws:
java.io.IOException
- in case of error
-
channelCopy
public long channelCopy(java.nio.channels.ReadableByteChannel src, java.nio.channels.WritableByteChannel dest) throws java.io.IOException
This method copies data from the src channel and writes it to the dest channel until EOF on src. This implementation makes use of compact() on the temp buffer to pack down the data if the buffer wasn't fully drained. This may result in data copying, but minimizes system calls. It also requires a cleanup loop to make sure all the data gets sent.- Parameters:
src
- the source channeldest
- the destination channel- Returns:
- the copied bytes
- Throws:
java.io.IOException
- in case of error
-
close
public void close(java.io.Closeable closeable)
Close silent a stream- Parameters:
closeable
- close
-
-