public class StreamUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
AUTO_DETECT_CHARSET |
static int |
BUFFERSIZE |
static Charset |
DEFAULT_CHARSET |
static String |
DEFAULT_INPUT_STREAM_ENCODING |
protected static org.apache.logging.log4j.Logger |
log |
Constructor and Description |
---|
StreamUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
copyReaderToWriter(Reader reader,
Writer writer,
int chunkSize) |
static void |
copyStream(InputStream in,
OutputStream out,
int chunkSize) |
static InputStream |
dontClose(InputStream stream) |
static OutputStream |
dontClose(OutputStream stream) |
static Reader |
dontClose(Reader reader) |
static void |
fileToStream(String filename,
OutputStream output)
Copies the content of the specified file to an output stream.
|
static String |
fileToString(String fileName,
String endOfLineString)
Deprecated.
|
static String |
fileToString(String fileName,
String endOfLineString,
boolean xmlEncode)
Deprecated.
|
static Reader |
getCharsetDetectingInputStreamReader(InputStream inputStream)
Return a Reader that reads the InputStream in the character set specified by the BOM.
|
static Reader |
getCharsetDetectingInputStreamReader(InputStream inputStream,
String defaultCharset)
Return a Reader that reads the InputStream in the character set specified by the BOM.
|
static InputStream |
onClose(InputStream stream,
ThrowingRunnable<IOException> onClose) |
static Reader |
onClose(Reader reader,
ThrowingRunnable<IOException> onClose) |
static String |
readerToString(Reader reader,
String endOfLineString) |
static String |
readerToString(Reader reader,
String endOfLineString,
boolean xmlEncode)
Copies the content of a reader into a string, adds specified string to the end of the line, if specified.
|
static void |
readerToWriter(Reader reader,
Writer writer)
Copies the content of a reader to the buffer of a writer.
|
static String |
resourceToString(URL resource) |
static String |
resourceToString(URL resource,
String endOfLineString) |
static String |
resourceToString(URL resource,
String endOfLineString,
boolean xmlEncode) |
static byte[] |
streamToByteArray(InputStream inputStream,
boolean skipBOM) |
static byte[] |
streamToBytes(InputStream inputStream)
Writes the content of an input stream to a byte array.
|
static void |
streamToFile(InputStream inputStream,
File file)
Writes the content of an input stream to a specified file.
|
static void |
streamToStream(InputStream input,
OutputStream output) |
static void |
streamToStream(InputStream input,
OutputStream output,
byte[] eof)
Writes the content of an input stream to an output stream by copying the buffer of input stream to the buffer of the output stream.
|
static String |
streamToString(InputStream stream) |
static String |
streamToString(InputStream stream,
String streamEncoding) |
static String |
streamToString(InputStream stream,
String endOfLineString,
boolean xmlEncode) |
static String |
streamToString(InputStream stream,
String endOfLineString,
String streamEncoding) |
static String |
streamToString(InputStream stream,
String endOfLineString,
String streamEncoding,
boolean xmlEncode) |
static void |
stringToFile(String string,
String fileName)
Writes the string to a file.
|
public static final Charset DEFAULT_CHARSET
public static final String DEFAULT_INPUT_STREAM_ENCODING
public static final String AUTO_DETECT_CHARSET
public static final int BUFFERSIZE
protected static org.apache.logging.log4j.Logger log
public static InputStream dontClose(InputStream stream)
public static OutputStream dontClose(OutputStream stream)
public static String readerToString(Reader reader, String endOfLineString) throws IOException
IOException
public static String streamToString(InputStream stream, String endOfLineString, String streamEncoding) throws IOException
IOException
public static byte[] streamToByteArray(InputStream inputStream, boolean skipBOM) throws IOException
IOException
public static Reader getCharsetDetectingInputStreamReader(InputStream inputStream) throws IOException
IOException
public static Reader getCharsetDetectingInputStreamReader(InputStream inputStream, String defaultCharset) throws IOException
IOException
public static void copyStream(InputStream in, OutputStream out, int chunkSize) throws IOException
IOException
public static void copyReaderToWriter(Reader reader, Writer writer, int chunkSize) throws IOException
IOException
public static InputStream onClose(InputStream stream, ThrowingRunnable<IOException> onClose)
public static Reader onClose(Reader reader, ThrowingRunnable<IOException> onClose)
public static void fileToStream(String filename, OutputStream output) throws IOException
Example:
OutputStream os = new ByteArrayOutputStream Misc.fileToStream(someFileName, os); System.out.println(os.toString) // prints the content of the output stream // that's copied from the file.
IOException
- exception to be thrown if an I/O exception occurspublic static void streamToStream(InputStream input, OutputStream output) throws IOException
IOException
public static void streamToStream(InputStream input, OutputStream output, byte[] eof) throws IOException
Example:
String test = "test"; ByteArrayInputStream bais = new ByteArrayInputStream(test.getBytes()); OutputStream baos = new ByteArrayOutputStream(); Misc.streamToStream(bais, baos); System.out.println(baos.toString()); // prints "test"
IOException
- exception to be thrown if an I/O exception occurspublic static void streamToFile(InputStream inputStream, File file) throws IOException
Example:
String test = "test"; ByteArrayInputStream bais = new ByteArrayInputStream(test.getBytes()); Misc.streamToFile(bais, file); // "test" copied inside the file.
IOException
- exception to be thrown if an I/O exception occurspublic static byte[] streamToBytes(InputStream inputStream) throws IOException
Example:
String test = "test"; ByteArrayInputStream bais = new ByteArrayInputStream(test.getBytes()); byte[] arr = Misc.streamToBytes(bais); System.out.println(new String(arr, StandardCharsets.UTF_8)); // prints "test"
IOException
public static void readerToWriter(Reader reader, Writer writer) throws IOException
Example:
Reader reader = new StringReader("test"); Writer writer = new StringWriter(); Misc.readerToWriter(reader, writer, true); System.out.println(writer.toString)); // prints "test"
IOException
@Deprecated public static String fileToString(String fileName, String endOfLineString) throws IOException
IOException
@Deprecated public static String fileToString(String fileName, String endOfLineString, boolean xmlEncode) throws IOException
IOException
public static String readerToString(Reader reader, String endOfLineString, boolean xmlEncode) throws IOException
Example:
Reader r = new StringReader("WeAreFrank' \n"; String s = Misc.readerToString(r, "!!", true); System.out.println(s); // prints "<root> WeAreFrank!!</root>"
xmlEncode
- if set to true, applies XML encodings to the content of the readerIOException
public static String streamToString(InputStream stream) throws IOException
IOException
streamToString(InputStream, String, boolean)
public static String streamToString(InputStream stream, String streamEncoding) throws IOException
IOException
streamToString(InputStream, String, String, boolean)
public static String streamToString(InputStream stream, String endOfLineString, boolean xmlEncode) throws IOException
IOException
streamToString(InputStream, String, String, boolean)
public static String streamToString(InputStream stream, String endOfLineString, String streamEncoding, boolean xmlEncode) throws IOException
IOException
readerToString(Reader, String, boolean)
public static String resourceToString(URL resource, String endOfLineString, boolean xmlEncode) throws IOException
IOException
streamToString(InputStream, String, boolean)
public static String resourceToString(URL resource) throws IOException
IOException
streamToString(InputStream, String, boolean)
public static String resourceToString(URL resource, String endOfLineString) throws IOException
IOException
streamToString(InputStream, String, boolean)
public static void stringToFile(String string, String fileName) throws IOException
IOException
Copyright © 2023 Frank!Framework. All rights reserved.