BAEL-1033 Introduction to StreamUtils (#2337)
* Evaluation article: Different Types of Bean Injection in Spring * added tests & changed configuration to Java-based config * removed xml config files * rename unit tests * BAEL-972 - Apache Commons Text * remove code from evaluation article * remove code from evaluation article * BAEL-972 - Apache Commons Text - added another example * BAEL-972 - Apache Commons Text - just indentation * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java - fix problems * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
dc037a4ce8
commit
36608b78cc
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.streamutils;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
public class CopyStream {
|
||||
public static String getStringFromInputStream(InputStream input) throws IOException {
|
||||
StringWriter writer = new StringWriter();
|
||||
IOUtils.copy(input, writer, "UTF-8");
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
public InputStream getNonClosingInputStream() throws IOException {
|
||||
InputStream in = new FileInputStream("src/test/resources/input.txt");
|
||||
return StreamUtils.nonClosing(in);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.streamutils;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
public class DrainStream {
|
||||
public InputStream getInputStream() {
|
||||
return StreamUtils.emptyInput();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user