Package io.github.amanzat.util
Class IOUtils
java.lang.Object
io.github.amanzat.util.IOUtils
Miscellaneous I/O streams related utilities.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default buffer size (8192) to use in copy methods.static final intRepresents the end-of-file (or stream). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longcopy(InputStream inputStream, OutputStream outputStream) Copies bytes aInputStreamto anOutputStream.static longcopy(InputStream inputStream, OutputStream outputStream, byte[] buffer) Copies bytes from aInputStreamto anOutputStream.static longcopy(InputStream inputStream, OutputStream outputStream, int bufferSize) Copies bytes from anInputStreamto anOutputStreamusing an internal buffer of the given size.static InputStreamtoInputStream(String input, Charset charset) Converts the specified string to an input stream, encoded as bytes using the specified character encoding.
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEThe default buffer size (8192) to use in copy methods.- See Also:
-
EOF
public static final int EOFRepresents the end-of-file (or stream).- See Also:
-
-
Constructor Details
-
IOUtils
public IOUtils()
-
-
Method Details
-
copy
Copies bytes aInputStreamto anOutputStream.This method buffers the input internally, using the default buffer size:
DEFAULT_BUFFER_SIZE.- Parameters:
inputStream- TheInputStreamto read.outputStream- TheOutputStreamto write.- Returns:
- The number of bytes copied.
- Throws:
IOException- if an I/O error occurs.
-
copy
public static long copy(InputStream inputStream, OutputStream outputStream, int bufferSize) throws IOException Copies bytes from anInputStreamto anOutputStreamusing an internal buffer of the given size.- Parameters:
inputStream- TheInputStreamto read.outputStream- TheOutputStreamto write tobufferSize- The bufferSize used to copy from the input to the output- Returns:
- The number of bytes copied.
- Throws:
IOException- if an I/O error occurs.
-
copy
public static long copy(InputStream inputStream, OutputStream outputStream, byte[] buffer) throws IOException Copies bytes from aInputStreamto anOutputStream.This method uses the provided buffer, so there is no need to use a
BufferedInputStream.- Parameters:
inputStream- TheInputStreamto read.outputStream- TheOutputStreamto write.buffer- The buffer to use for the copy- Returns:
- The number of bytes copied.
- Throws:
IOException- if an I/O error occurs.
-
toInputStream
Converts the specified string to an input stream, encoded as bytes using the specified character encoding.- Parameters:
input- The string to convertcharset- The charset to use,nullallowed and transformed to default charset.- Returns:
- An input stream.
-